libf 2 lat temu
commit
1787dcf549

+ 261 - 0
json_importer_gen/AlterClassByJson.js

@@ -0,0 +1,261 @@
+// 输入输出参数格式化
+input = INPUT;
+output = {};
+try {
+    input = decodeURIComponent(input);
+} catch(e) {}
+try {
+    input = base64.decode(input);
+} catch(e) {}
+try {
+    input = JSON.parse(input);
+    input = JSON.parse(input);
+} catch(e) {}
+output.info = {input:input};
+
+// 主执行阶段
+try {
+    if (!input.classname) { // like /cncc/itil/project
+        throw ("需要指定classname");
+    }
+    if (input.classname[0] != "/") { // like /cncc/itil/project
+        throw ("classname必须以 / 开头");
+    }
+    if (!input.data || typeof(input.data)!="object") {
+        throw ("data必须指定为一个对象");
+    }
+    // 检查父类是否存在,不存在就创建
+    cns = input.classname.split("/");
+    clsname = "";
+    for (var cni = 1; cni < cns.length - 1; cni++) {
+        clsname += "/" + cns[cni];
+        odb.mql("create class if not exists " + clsname + "()");
+    }
+    pclsname = clsname;
+    clsname += "/" + cns[cns.length - 1];
+
+    // 提取现有类的字段信息
+    clsexist = false;
+    clsfields = {};
+    try {
+        fieldslist = odb.classfields(clsname);
+        for (var fi = 0; fi < fieldslist.length; fi++) {
+            fld = fieldslist[fi];
+            fname = fld.name;
+            if (/^\w+\:.*/.test(fname)) {
+                fname = fname.replace(/^\w+\:/, ""); 
+            }
+            if (fname && fld.ftype) {
+                clsfields[fname] = {
+                    iskey: fld.iskey,
+                    ftype: fld.ftype,
+                };
+            }
+        }
+        clsexist = true;
+    } catch(e) {}
+    if (!clsexist) {
+        try {
+            fieldslist = odb.classfields(pclsname);
+            for (var fi = 0; fi < fieldslist.length; fi++) {
+                fld = fieldslist[fi];
+                fname = fld.name;
+                if (/^\w+\:.*/.test(fname)) {
+                    fname = fname.replace(/^\w+\:/, ""); 
+                }
+                if (fname && fld.ftype) {
+                    clsfields[fname] = {
+                        iskey: fld.iskey,
+                        ftype: fld.ftype,
+                    };
+                }
+            }
+        } catch(e) {}
+    }
+    output.info.clsfields = clsfields;
+
+    // 通过参数确定的字段类型信息
+    fields = input.fields;
+    if (!fields) {
+        fields = {};
+    }
+    // 字段名映射,参数中指定的字段名均为JSON对象中的属性名,默认将 camelStyle 转换为 snake_style
+    fieldmap = input.fieldmap;
+    if (!fieldmap) {
+        fieldmap = {};
+    }
+    // 反向字段名映射,类中的字段名映射为JSON对象中的属性名
+    xfieldmap = {};
+    // 类中的字段名列表,用于排序
+    xfieldslist = [];
+    // 类字段类型信息
+    xfields = {};
+    xpks = [];
+    for (var jk in input.data) {
+        xk = fieldmap[jk];
+        // 通过参数确定的字段类型信息
+        if (!xk) {
+            // 默认将 camelStyle 转换为 snake_style
+            xk = "j_"; // 区别于其它字段,自动创建的字段以 j_ 开头
+            for (var i = 0; i < jk.length; i++) {
+                if (jk[i] >= 'A' && jk[i] <= 'Z') {
+                    xk += "_" + jk[i].toLowerCase();
+                } else {
+                    xk += jk[i];
+                }
+            }
+            fieldmap[jk] = xk;
+        }
+        xfieldslist.push(xk);
+        xfieldmap[xk] = jk;
+        dt = fields[jk];
+        if (dt && dt.indexOf(",key") > 0) {
+            dt = dt.replace(",key", "");
+            xpks.push(xk);
+        }
+        switch (dt) {
+        case "date":
+        case "time":
+        case "datetime":
+            dt = "timestamp";
+            break;
+        case "int":
+        case "integer":
+            dt = "bigint";
+            break;
+        case "number":
+        case "float":
+            dt = "double";
+            break;
+        case "text":
+            dt = "text";
+            break;
+        case "string":
+            dt = "varchar";
+            break;
+        case "boolean":
+            dt = "boolean";
+            break;
+        }
+        if (!dt) {
+            // 没有明确定义的字段类型
+            // 根据数据判断类型
+            dt = "varchar";
+            d = input.data[jk];
+            if (d || d == "" || d == 0 || d == false) { 
+                switch (typeof(d)) {
+                case 'object':
+                    // 转为text
+                    dt = "text"; 
+                    break;
+                case 'number':
+                    // 是否为整数
+                    if ((""+d).indexOf(".")<0) {
+                        dt = "bigint";
+                    } else {
+                        dt = "double";
+                    }
+                    break;
+                case 'boolean':
+                    dt = "boolean";
+                    break;
+                case 'string':
+                default:
+                    // 是否为日期时间
+                    if (/_time/.test(xk) || /_date/.test(xk)) {
+                        dt = "timestamp";
+                    } else {
+                        dt = "varchar";
+                    }
+                    break;
+                }
+            } else {
+                if (/_time/.test(xk) || /_date/.test(xk)) {
+                    dt = "timestamp";
+                } else {
+                    dt = "varchar";
+                }
+            }
+        }
+        xfields[xk] = dt;
+    }
+    output.info.xfields = xfields;
+    
+    if (!clsexist) {
+        // 类不存在,自动创建类
+        mql = "create class if not exists " + clsname + "(";
+        indexes = "indexes(";
+        for (var fi = 0; fi < xfieldslist.length; fi++) {
+            xk = xfieldslist[fi];
+            if (xk in {"id":"", "class":"", "name":"", "day":"", "tags":"", "vtime":""}) {
+                throw("内部使用字段名 " + xk + ",需要映射成其它名称");
+            }
+            if (clsfields[xk] && clsfields[xk].ftype != xfields[xk]) {
+                throw ("类继承字段 "+ xk +" 信息不一致,"+clsfields[xk].ftype + "!=" + xfields[xk]+",需手动干预");
+            }
+            mql += fi==0 ? "\n": ",\n";
+            mql += xk + " " + xfields[xk];
+            if (fi > 0) {
+                indexes += ",";
+            }
+            indexes += xk;
+        }
+        indexes += ")";
+        mql += ",\n" + indexes;
+        if (xpks.length > 0) {
+            mql += ",\n";
+            mql += "keys(";
+            for (var pki = 0; pki < xpks.length; pki++) {
+                if (pki > 0) {
+                    mql += ",";
+                }
+                mql += xpks[pki];
+            }
+            mql += ")";
+        }
+        mql += "\n";
+        mql += ")";
+        if (input.clsoption) {
+            mql += input.clsoption;
+        }
+        odb.mql(mql);
+        output.info = {mql:mql};
+    } else {
+        // 类已存在,检查主键信息是否存在
+        for (var pki = 0; pki < xpks.length; pki++) {
+            xk = xpks[pki];
+            if (!clsfields[xk] || !clsfields[xk].iskey) {
+                throw ("已经存在同名类主键 "+ xk +" 信息不一致,需手动干预");
+            }
+        }
+        // 追加字段
+        mql = "alter class " + clsname + " add index column";
+        addn = 0;
+        for (var fi = 0; fi < xfieldslist.length; fi++) {
+            xk = xfieldslist[fi];
+            if (!clsfields[xk]) {
+                mql += (addn == 0)?" ":", ";
+                mql += xk + " " + xfields[xk];
+                addn++;
+            } else if (clsfields[xk].ftype != xfields[xk]) {
+                throw ("已经存在同名类字段 "+ xk +" 信息不一致,需手动干预");
+            }
+        }
+        if (addn > 0) {
+            odb.mql(mql);
+            output.info = {mql:mql};
+        }
+    }
+} catch(e) {
+    if (typeof(e) == "object") {
+        output.error = e;
+    } else if (typeof(e) == "string") {
+        output.error = "错误:" + e;
+    } else {
+        output.error = JSON.stringify(e);
+    }
+}
+
+// 返回输出信息
+OUTPUT = output;
+

+ 326 - 0
json_importer_gen/InitByJsonData.js

@@ -0,0 +1,326 @@
+
+//默认值设置
+defaultinput = {
+    server: "http://172.23.12.228:8080",
+    author: base64.encode("meta.admin:admin"),
+    istesting: true,
+    classname: "/cncc/action/test",
+    data: null,
+    datafiledir: "/opt/cncc/ITIL/change_main",
+    datafilename: "",
+    jsfilename: "/script/cncc/ITIL/测试.js",
+    clsoption: "with ttl=10 day, version=true, nickname='test'",
+    fieldmap: {id: "jid"},
+    fields: {idUnique: "string,key"},
+    mustfield: "id,idUnique",
+};
+inputmapping = {
+    "change": {
+        classname: "/cncc/action/change_main",
+        datafiledir: "/opt/cncc/ITIL/change_main",
+        jsfilename: "/script/cncc/ITIL/变更单.js",
+        clsoption: "with ttl=10 day, version=true, nickname='change_main'",
+    },
+    "event": {
+        classname: "/cncc/action/event",
+        datafiledir: "/opt/cncc/ITIL/event",
+        jsfilename: "/script/cncc/ITIL/事件单.js",
+        clsoption: "with ttl=10 day, version=true, nickname='event'",
+    },
+    "problem": {
+        classname: "/cncc/action/problem",
+        datafiledir: "/opt/cncc/ITIL/problem",
+        jsfilename: "/script/cncc/ITIL/问题单.js",
+        clsoption: "with ttl=10 day, version=true, nickname='problem'",
+    },
+    "baobei": {
+        classname: "/cncc/action/baobei",
+        datafiledir: "/opt/cncc/ITIL/baobei",
+        jsfilename: "/script/cncc/ITIL/报备.js",
+        clsoption: "with ttl=10 day, version=true, nickname='baobei'",
+    },
+    "shebeishangxiadian": {
+        classname: "/cncc/action/shebeishangxiadian",
+        datafiledir: "/opt/cncc/ITIL/shebeishangxiadian",
+        jsfilename: "/script/cncc/ITIL/设备上下电.js",
+        clsoption: "with ttl=10 day, version=true, nickname='shebeishangxiadian'",
+    },
+    "shujuhuoqu": {
+        classname: "/cncc/action/shujuhuoqu",
+        datafiledir: "/opt/cncc/ITIL/shujuhuoqu",
+        jsfilename: "/script/cncc/ITIL/数据获取.js",
+        clsoption: "with ttl=10 day, version=true, nickname='shujuhuoqu'",
+    },
+    "yanlian": {
+        classname: "/cncc/action/yanlian",
+        datafiledir: "/opt/cncc/ITIL/yanlian",
+        jsfilename: "/script/cncc/ITIL/应急演练.js",
+        clsoption: "with ttl=10 day, version=true, nickname='yanlian'",
+    },
+    "project": {
+        classname: "/cncc/action/project",
+        datafiledir: "/opt/cncc/ITIL/project",
+        jsfilename: "/script/cncc/ITIL/项目实施或巡检.js",
+        clsoption: "with ttl=10 day, version=true, nickname='project'",
+    }
+};
+
+// 输入输出参数格式化
+input = INPUT;
+output = {};
+try {
+    input = decodeURIComponent(input);
+} catch(e) {}
+try {
+    input = base64.decode(input);
+} catch(e) {}
+try {
+    input = JSON.parse(input);
+    input = JSON.parse(input);
+} catch(e) {}
+
+// 通用函数
+function isempty(o) {
+    if (o) {
+        for (var k in o){
+            return false;
+        }
+    } 
+    return true;
+}
+
+// 主执行阶段
+function main() {
+    output.info = {};
+    output.info.p0 = {name: "确认参数"};
+    p = inputmapping[input.name];
+    if (p) {
+        for (var k in p) {
+            defaultinput[k] = p[k];
+        }
+    }
+    server = input.server;
+    if (!server) {
+        server = defaultinput.server;
+    }
+    author = input.author;
+    if (!author) {
+        author = defaultinput.author;
+    }
+    istesting = input.istesting;
+    if (!istesting) {
+        istesting = defaultinput.istesting;
+    }
+    classname = input.classname;
+    if (!classname) {
+        classname = defaultinput.classname;
+    }
+    if (classname[0] != "/") {
+        throw ("classname必须以 / 开头");
+    }
+    if (classname.substring(0,8) == "/matrix/") {
+        throw ("classname不能以 /matrix/ 开头");
+    }
+    data = input.data;
+    if (isempty(data)) {
+        data = defaultinput.data;
+        if (isempty(data)) {
+            datafilename = input.datafilename;
+            if (!datafilename) {
+                datafilename = defaultinput.datafilename;
+            }
+            if (datafilename) {
+                try {
+                    data = dfs.read(datafilename);
+                    data = JSON.parse(data);
+                } catch(e) {}
+            }
+        }
+        if (isempty(data)) {
+            datafiledir = input.datafiledir;
+            if (!datafiledir) {
+                if (classname == defaultinput.classname) {
+                    datafiledir = defaultinput.datafiledir;
+                } else {
+                    datafiledir = "/opt" + classname;
+                }
+            }
+            // 读取所有文件,综合数据
+            data = {};
+            files = dfs.readdir(datafiledir);
+            for (i = 0; i < files.length; i++) { 
+                try {
+                    adat = dfs.read(files[i].fullname);
+                    adat = JSON.parse(adat);
+                    if (typeof(adat) != "object") {
+                        throw("只接收JSON对象数据");
+                    }
+                    for (var k in adat) {
+                        if (!data[k]) {
+                            data[k] = adat[k];
+                        } else if (adat[k]) {
+                            if (typeof(adat[k]) == "object") {
+                                if (JSON.stringify(adat[k]).length > JSON.stringify(data[k]).length) {
+                                    data[k] = adat[k];
+                                }
+                            } else if (typeof(adat[k]) == "string") {
+                                if (typeof(data[k]) != "string") {
+                                    data[k] = adat[k];
+                                } else if (adat[k].length > data[k].length) {
+                                    data[k] = adat[k];
+                                }
+                            } else if (typeof(adat[k]) == "number") {
+                                if (typeof(data[k]) == "number") {
+                                    if ((""+adat[k]).indexOf(".")>=0) {
+                                        data[k] = adat[k];
+                                    }
+                                }
+                            } else if (typeof(adat[k]) == "boolean") {
+                                if (typeof(data[k]) != "boolean") {
+                                    data[k] = ""+adat[k];
+                                }
+                            }
+                        }
+                    }
+                } catch(e) {}
+            }
+        }
+    }
+    jsfilename = input.jsfilename;
+    if (!jsfilename) {
+        jsfilename = defaultinput.jsfilename;
+    }
+    clsoption = input.clsoption;
+    if (!clsoption) {
+        clsoption = defaultinput.clsoption;
+    }
+    fieldmap = input.fieldmap;
+    if (!fieldmap) {
+        fieldmap = defaultinput.fieldmap;
+    }
+    mustfield = input.mustfield;
+    if (!mustfield) {
+        mustfield = defaultinput.mustfield;
+    }
+    fields = input.fields;
+    if (!fields) {
+        fields = defaultinput.fields;
+    }
+    reqinput = {
+        istesting: istesting,
+        classname: classname, 
+        jsfilename: jsfilename,
+        clsoption: clsoption, 
+        fieldmap: fieldmap,
+        fields: fields,
+        mustfield: mustfield,
+        data: data,
+    };
+    reqinput = encodeURIComponent(JSON.stringify(reqinput));
+    output.info.p1 = {name:"生成类"};
+    http.do("POST", 
+        server+"/script/exec/js?filepath=/matrix/utils/AlterClassByJson.js",
+        {
+            "Authorization": "Basic "+author,
+            "Content-Type": "application/x-www-form-urlencoded",
+            "Data-Type": "json"
+        },
+        'input='+reqinput,
+        function(response){
+            // success func
+            ret = response.data;
+            if (ret.message) {
+                output.info.p1.result = ret.message;
+            } else {
+                output.info.p1.result = ret;
+            }
+        },
+        function(response){
+            // error func
+            output.error = response.data;
+        });
+    if (output.error || output.info.p1.result.error) {
+        return;
+    }
+    output.info.p2 = {name:"生成脚本"};
+    http.do("POST", 
+        server+"/script/exec/js?filepath=/matrix/utils/JsonImporterGen.js&input="+reqinput,
+        {"Authorization": "Basic "+author},
+        '',
+        function(response){
+            // success func
+            ret = response.data;
+            if (ret.message) {
+                output.info.p2.result = ret.message;
+            } else {
+                output.info.p2.result = ret;
+            }
+        },
+        function(response){
+            // error func
+            output.error = response.data;
+        });
+    if (output.error || output.info.p2.result.error) {
+        return;
+    }
+    output.info.p2x = {name:"激活脚本"};
+    calljsfp = encodeURIComponent(jsfilename.replace(/\/script/, ""));
+    http.do("POST", 
+        server+"/fs/tolocal/script"+calljsfp+"?issys=true",
+        {"Authorization": "Basic "+author},
+        '',
+        function(response){
+            // success func
+            ret = response.data;
+            if (ret.message) {
+                output.info.p2x.result = ret.message;
+            } else {
+                output.info.p2x.result = ret;
+            }
+        },
+        function(response){
+            // error func
+            output.error = response.data;
+        });
+    if (output.error || output.info.p2x.result.error) {
+        return;
+    }
+    output.info.p3 = {name:"插入数据"};
+    reqinput = encodeURIComponent(base64.encode(JSON.stringify(data)));
+    calljsfp = encodeURIComponent(jsfilename.replace(/\/script/, ""));
+    http.do("POST", 
+        server+"/script/exec/js?filepath="+calljsfp+"&input="+reqinput,
+        {"Authorization": "Basic "+author},
+        '',
+        function(response){
+            // success func
+            ret = response.data;
+            if (ret.message) {
+                output.info.p3.result = ret.message;
+            } else {
+                output.info.p3.result = ret;
+            }
+        },
+        function(response){
+            // error func
+            output.error = response.data;
+        });
+    if (output.error || output.info.p3.result.error) {
+        return;
+    }
+    output.info.p4 = {name:"完成"};
+}
+try {
+    main();
+} catch(e) {
+    if (typeof(e) == "object") {
+        output.error = e;
+    } else if (typeof(e) == "string") {
+        output.error = "错误:" + e;
+    } else {
+        output.error = JSON.stringify(e);
+    }
+}
+
+// 返回输出信息
+OUTPUT = output;

+ 326 - 0
json_importer_gen/InitJsonImporter.js

@@ -0,0 +1,326 @@
+
+//默认值设置
+defaultinput = {
+    server: "http://172.23.12.228:8080",
+    author: base64.encode("meta.admin:admin"),
+    istesting: true,
+    classname: "/cncc/action/test",
+    data: null,
+    datafiledir: "/opt/cncc/ITIL/change_main",
+    datafilename: "",
+    jsfilename: "/script/cncc/ITIL/测试.js",
+    clsoption: "with ttl=10 day, version=true, nickname='test'",
+    fieldmap: {id: "jid"},
+    fields: {idUnique: "string,key"},
+    mustfield: "id,idUnique",
+};
+inputmapping = {
+    "change": {
+        classname: "/cncc/action/change_main",
+        datafiledir: "/opt/cncc/ITIL/change_main",
+        jsfilename: "/script/cncc/ITIL/变更单.js",
+        clsoption: "with ttl=10 day, version=true, nickname='change_main'",
+    },
+    "event": {
+        classname: "/cncc/action/event",
+        datafiledir: "/opt/cncc/ITIL/event",
+        jsfilename: "/script/cncc/ITIL/事件单.js",
+        clsoption: "with ttl=10 day, version=true, nickname='event'",
+    },
+    "problem": {
+        classname: "/cncc/action/problem",
+        datafiledir: "/opt/cncc/ITIL/problem",
+        jsfilename: "/script/cncc/ITIL/问题单.js",
+        clsoption: "with ttl=10 day, version=true, nickname='problem'",
+    },
+    "baobei": {
+        classname: "/cncc/action/baobei",
+        datafiledir: "/opt/cncc/ITIL/baobei",
+        jsfilename: "/script/cncc/ITIL/报备.js",
+        clsoption: "with ttl=10 day, version=true, nickname='baobei'",
+    },
+    "shebeishangxiadian": {
+        classname: "/cncc/action/shebeishangxiadian",
+        datafiledir: "/opt/cncc/ITIL/shebeishangxiadian",
+        jsfilename: "/script/cncc/ITIL/设备上下电.js",
+        clsoption: "with ttl=10 day, version=true, nickname='shebeishangxiadian'",
+    },
+    "shujuhuoqu": {
+        classname: "/cncc/action/shujuhuoqu",
+        datafiledir: "/opt/cncc/ITIL/shujuhuoqu",
+        jsfilename: "/script/cncc/ITIL/数据获取.js",
+        clsoption: "with ttl=10 day, version=true, nickname='shujuhuoqu'",
+    },
+    "yanlian": {
+        classname: "/cncc/action/yanlian",
+        datafiledir: "/opt/cncc/ITIL/yanlian",
+        jsfilename: "/script/cncc/ITIL/应急演练.js",
+        clsoption: "with ttl=10 day, version=true, nickname='yanlian'",
+    },
+    "project": {
+        classname: "/cncc/action/project",
+        datafiledir: "/opt/cncc/ITIL/project",
+        jsfilename: "/script/cncc/ITIL/项目实施或巡检.js",
+        clsoption: "with ttl=10 day, version=true, nickname='project'",
+    }
+};
+
+// 输入输出参数格式化
+input = INPUT;
+output = {};
+try {
+    input = decodeURIComponent(input);
+} catch(e) {}
+try {
+    input = base64.decode(input);
+} catch(e) {}
+try {
+    input = JSON.parse(input);
+    input = JSON.parse(input);
+} catch(e) {}
+
+// 通用函数
+function isempty(o) {
+    if (o) {
+        for (var k in o){
+            return false;
+        }
+    } 
+    return true;
+}
+
+// 主执行阶段
+function main() {
+    output.info = {};
+    output.info.p0 = {name: "确认参数"};
+    p = inputmapping[input.name];
+    if (p) {
+        for (var k in p) {
+            defaultinput[k] = p[k];
+        }
+    }
+    server = input.server;
+    if (!server) {
+        server = defaultinput.server;
+    }
+    author = input.author;
+    if (!author) {
+        author = defaultinput.author;
+    }
+    istesting = input.istesting;
+    if (!istesting) {
+        istesting = defaultinput.istesting;
+    }
+    classname = input.classname;
+    if (!classname) {
+        classname = defaultinput.classname;
+    }
+    if (classname[0] != "/") {
+        throw ("classname必须以 / 开头");
+    }
+    if (classname.substring(0,8) == "/matrix/") {
+        throw ("classname不能以 /matrix/ 开头");
+    }
+    data = input.data;
+    if (isempty(data)) {
+        data = defaultinput.data;
+        if (isempty(data)) {
+            datafilename = input.datafilename;
+            if (!datafilename) {
+                datafilename = defaultinput.datafilename;
+            }
+            if (datafilename) {
+                try {
+                    data = dfs.read(datafilename);
+                    data = JSON.parse(data);
+                } catch(e) {}
+            }
+        }
+        if (isempty(data)) {
+            datafiledir = input.datafiledir;
+            if (!datafiledir) {
+                if (classname == defaultinput.classname) {
+                    datafiledir = defaultinput.datafiledir;
+                } else {
+                    datafiledir = "/opt" + classname;
+                }
+            }
+            // 读取所有文件,综合数据
+            data = {};
+            files = dfs.readdir(datafiledir);
+            for (i = 0; i < files.length; i++) { 
+                try {
+                    adat = dfs.read(files[i].fullname);
+                    adat = JSON.parse(adat);
+                    if (typeof(adat) != "object") {
+                        throw("只接收JSON对象数据");
+                    }
+                    for (var k in adat) {
+                        if (!data[k]) {
+                            data[k] = adat[k];
+                        } else if (adat[k]) {
+                            if (typeof(adat[k]) == "object") {
+                                if (JSON.stringify(adat[k]).length > JSON.stringify(data[k]).length) {
+                                    data[k] = adat[k];
+                                }
+                            } else if (typeof(adat[k]) == "string") {
+                                if (typeof(data[k]) != "string") {
+                                    data[k] = adat[k];
+                                } else if (adat[k].length > data[k].length) {
+                                    data[k] = adat[k];
+                                }
+                            } else if (typeof(adat[k]) == "number") {
+                                if (typeof(data[k]) == "number") {
+                                    if ((""+adat[k]).indexOf(".")>=0) {
+                                        data[k] = adat[k];
+                                    }
+                                }
+                            } else if (typeof(adat[k]) == "boolean") {
+                                if (typeof(data[k]) != "boolean") {
+                                    data[k] = ""+adat[k];
+                                }
+                            }
+                        }
+                    }
+                } catch(e) {}
+            }
+        }
+    }
+    jsfilename = input.jsfilename;
+    if (!jsfilename) {
+        jsfilename = defaultinput.jsfilename;
+    }
+    clsoption = input.clsoption;
+    if (!clsoption) {
+        clsoption = defaultinput.clsoption;
+    }
+    fieldmap = input.fieldmap;
+    if (!fieldmap) {
+        fieldmap = defaultinput.fieldmap;
+    }
+    mustfield = input.mustfield;
+    if (!mustfield) {
+        mustfield = defaultinput.mustfield;
+    }
+    fields = input.fields;
+    if (!fields) {
+        fields = defaultinput.fields;
+    }
+    reqinput = {
+        istesting: istesting,
+        classname: classname, 
+        jsfilename: jsfilename,
+        clsoption: clsoption, 
+        fieldmap: fieldmap,
+        fields: fields,
+        mustfield: mustfield,
+        data: data,
+    };
+    reqinput = encodeURIComponent(JSON.stringify(reqinput));
+    output.info.p1 = {name:"生成类"};
+    http.do("POST", 
+        server+"/script/exec/js?filepath=/matrix/utils/AlterClassByJson.js",
+        {
+            "Authorization": "Basic "+author,
+            "Content-Type": "application/x-www-form-urlencoded",
+            "Data-Type": "json"
+        },
+        'input='+reqinput,
+        function(response){
+            // success func
+            ret = response.data;
+            if (ret.message) {
+                output.info.p1.result = ret.message;
+            } else {
+                output.info.p1.result = ret;
+            }
+        },
+        function(response){
+            // error func
+            output.error = response.data;
+        });
+    if (output.error || output.info.p1.result.error) {
+        return;
+    }
+    output.info.p2 = {name:"生成脚本"};
+    http.do("POST", 
+        server+"/script/exec/js?filepath=/matrix/utils/JsonImporterGen.js&input="+reqinput,
+        {"Authorization": "Basic "+author},
+        '',
+        function(response){
+            // success func
+            ret = response.data;
+            if (ret.message) {
+                output.info.p2.result = ret.message;
+            } else {
+                output.info.p2.result = ret;
+            }
+        },
+        function(response){
+            // error func
+            output.error = response.data;
+        });
+    if (output.error || output.info.p2.result.error) {
+        return;
+    }
+    output.info.p2x = {name:"激活脚本"};
+    calljsfp = encodeURIComponent(jsfilename.replace(/\/script/, ""));
+    http.do("POST", 
+        server+"/fs/tolocal/script"+calljsfp+"?issys=true",
+        {"Authorization": "Basic "+author},
+        '',
+        function(response){
+            // success func
+            ret = response.data;
+            if (ret.message) {
+                output.info.p2x.result = ret.message;
+            } else {
+                output.info.p2x.result = ret;
+            }
+        },
+        function(response){
+            // error func
+            output.error = response.data;
+        });
+    if (output.error || output.info.p2x.result.error) {
+        return;
+    }
+    output.info.p3 = {name:"插入数据"};
+    reqinput = encodeURIComponent(base64.encode(JSON.stringify(data)));
+    calljsfp = encodeURIComponent(jsfilename.replace(/\/script/, ""));
+    http.do("POST", 
+        server+"/script/exec/js?filepath="+calljsfp+"&input="+reqinput,
+        {"Authorization": "Basic "+author},
+        '',
+        function(response){
+            // success func
+            ret = response.data;
+            if (ret.message) {
+                output.info.p3.result = ret.message;
+            } else {
+                output.info.p3.result = ret;
+            }
+        },
+        function(response){
+            // error func
+            output.error = response.data;
+        });
+    if (output.error || output.info.p3.result.error) {
+        return;
+    }
+    output.info.p4 = {name:"完成"};
+}
+try {
+    main();
+} catch(e) {
+    if (typeof(e) == "object") {
+        output.error = e;
+    } else if (typeof(e) == "string") {
+        output.error = "错误:" + e;
+    } else {
+        output.error = JSON.stringify(e);
+    }
+}
+
+// 返回输出信息
+OUTPUT = output;

+ 72 - 0
json_importer_gen/JsonImporter.template.js

@@ -0,0 +1,72 @@
+// ___classname___ JSON数据导入程序
+// ___datetime_now___ 由 JsonImportGen.js 自动生成,请勿手动修改
+    
+// 输入输出参数格式化
+input = INPUT;
+try {
+    input = decodeURIComponent(input);
+} catch(e) {}
+try {
+    input = base64.decode(input);
+} catch(e) {}
+try {
+    input = JSON.parse(input);
+    input = JSON.parse(input);
+} catch(e) {}
+output = {};
+
+istesting = ___istesting___;
+function teststore() {
+    // 输入JSON临时存入DFS
+    dir = "/opt___classname___";
+    dtm = new Date().toJSON().replace(/[\-\:\.TZ ]/mg, "");
+    fn = dir + "/" + dtm;
+    if (input.id) {
+        fn += "." + input.id;
+    } else {
+        fn += "_" + _.random(0, 1000000);
+    }
+    fn += ".json";
+    dfs.write(fn, JSON.stringify(input, " ", 4));
+    output.filename = fn;
+    // 刪除旧交件
+    files = dfs.readdir(dir);
+    dt = Date.now() - 1000 * 3600 * 24 * 10;
+    for (i = 0; i < files.length; i++) {
+        if (files[i].mtime < dt) {
+            dfs.remove(files[i].fullname);
+        }
+    }
+    // 留最后10个
+    files.sort(function(a,b){ return a.mtime-b.mtime; });
+    for (i = 0; i < files.length-10; i++) {
+        dfs.remove(files[i].fullname);
+    }
+}
+// 主执行阶段
+try {
+    if (istesting) {
+        teststore();
+    }
+    // 数据合法性检查
+    if (___datacheck___) {}
+    // mql定义
+    mql = `___mql___`;
+    // 执行mql
+    ret = odb.mql(mql, ___values___);
+    // 打印完成信息
+    output.info=___datainfo___;
+    log.info(output.info);
+} catch(e) {
+    if (typeof(e) == "object") {
+        output.error = e;
+    } else if (typeof(e) == "string") {
+        output.error = "插库错误:" + e;
+    } else {
+        output.error = JSON.stringify(e);
+    }
+    log.error(output.error);
+}
+
+// 返回输出信息
+OUTPUT = output;

+ 160 - 0
json_importer_gen/JsonImporterGen.js

@@ -0,0 +1,160 @@
+// 输入输出参数格式化
+input = INPUT;
+try {
+    input = decodeURIComponent(input);
+} catch(e) {}
+try {
+    input = base64.decode(input);
+} catch(e) {}
+try {
+    input = JSON.parse(input);
+    input = JSON.parse(input);
+} catch(e) {}
+output = {};
+
+// 主执行阶段
+try {
+    if (!input.classname) { // like /cncc/itil/project
+        throw ("需要指定classname");
+    }
+    if (input.classname[0] != "/") { // like /cncc/itil/project
+        throw ("classname必须以 / 开头");
+    }
+    sjsfn = input.jsfilename;
+    if (!sjsfn) {
+        sjsfn = "/script" + input.classname; // like /script/cncc/itil/project
+    }
+    if (sjsfn.substring(0, 8) != "/script/") {
+        throw ("jsfilename必须以 /script/ 开头");
+    }
+    sjsfn = sjsfn.replace(/\.js$/, "");
+    output.file = sjsfn;
+
+    dtm = new Date().toJSON();
+    mql = "insert into " + input.classname + " (\n";
+    mql_values = ") values (\n";
+    mql_end = ")";
+    values = "";
+    fieldmap = input.fieldmap;
+    if (!fieldmap) {
+        fieldmap = {};
+    }
+    xfieldmap = {};
+    xfields = [];
+    clsfields = {};
+    try {
+        fieldslist = odb.classfields(input.classname);
+        for (var fi = 0; fi < fieldslist.length; fi++) {
+            fld = fieldslist[fi];
+            fname = fld.name;
+            if (/^\w+\:.*/.test(fname)) {
+                fname = fname.replace(/^\w+\:/, ""); 
+            }
+            if (fname && fld.ftype) {
+                clsfields[fname] = {
+                    iskey: fld.iskey,
+                    ftype: fld.ftype,
+                };
+            }
+        }
+    } catch(e) {}
+    for (var k in input.data) {
+        xk = fieldmap[k];
+        if (!xk) {
+            xk = "j_"; // 区别于其它字段,自动创建的字段以 j_ 开头
+            for (var i = 0; i < k.length; i++) {
+                if (k[i] >= 'A' && k[i] <= 'Z') {
+                    xk += "_" + k[i].toLowerCase();
+                } else {
+                    xk += k[i];
+                }
+            }
+            fieldmap[k] = xk;
+        }
+        xfields.push(xk);
+        xfieldmap[xk] = k;
+    }
+    xfields.sort();
+    fsep = ",";
+    for (var i = 0; i < xfields.length; i++) {
+        if (i == xfields.length - 1) {
+            fsep = "";
+        }
+        xk = xfields[i];
+        k = xfieldmap[xk];
+        mql += xk + fsep + "\n";
+        mql_values += "?" + fsep + "\n";
+        values += "    ";
+        v = input.data[k];
+        if (!clsfields[xk]) {
+            throw("字段不存在", xk)
+        }
+        switch (clsfields[xk].ftype) {
+        case "text":
+        case "varchar":
+            if (typeof(v) == "object") {
+                values += "JSON.stringify(";
+                values += "input." + k + ", \" \", 4)" + fsep;
+                values += JSON.stringify(v, " ", 4).replace(/^/mg, "            // ").replace(/            /, " ");
+            } else {
+                values += "\"\"+";
+                values += "input." + k + fsep;
+                values += (""+v).replace(/^/mg, "            // ").replace(/            /, " ");
+            }
+            break;
+        default:
+            values += "input." + k + fsep;
+            values += (""+v).replace(/^/mg, "            // ").replace(/            /, " ");
+        }
+        values += "\n    ";
+    }
+    mql += mql_values + mql_end;
+    values = "\n    " + values;
+
+    datainfo = "{";
+    datacheck = "";
+    if (input.mustfield) {
+        ids = input.mustfield.split(",");
+        for (var i = 0; i < ids.length; i++) {
+            id = ids[i];
+            if (i > 0) {
+                datacheck += "\n    ";
+            }
+            datacheck += "if (!input." + id + ") {\n    ";
+            datacheck += "    throw (\"输入参数必须为对象,且指定属性" + id + "\");\n    ";
+            datacheck += "}";
+            if (i == 0) {
+                datainfo += "\n    ";
+            } else {
+                datainfo += ",\n    ";
+            }
+            datainfo += "    " + id + ": input." + id;
+        }
+    }
+    datainfo += "\n    ";
+    datainfo += "}";
+
+    importjs = dfs.read("/script/matrix/utils/JsonImporter.template.js");
+    importjs = importjs.replace(/___istesting___/mg, input.istesting);
+    importjs = importjs.replace(/___classname___/mg, input.classname);
+    importjs = importjs.replace(/___datetime_now___/mg, dtm);
+    importjs = importjs.replace(/if\s*\(\s*___datacheck___\s*\)\s*\{.*\}/mg, datacheck);
+    importjs = importjs.replace(/___mql___/mg, mql);
+    importjs = importjs.replace(/___values___/mg, values);
+    importjs = importjs.replace(/___datainfo___/mg, datainfo);
+
+    output.content = importjs;
+
+    dfs.write(sjsfn + ".js", importjs);
+} catch(e) {
+    if (typeof(e) == "object") {
+        output.error = e;
+    } else if (typeof(e) == "string") {
+        output.error = "错误:" + e;
+    } else {
+        output.error = JSON.stringify(e);
+    }
+}
+
+// 返回输出信息
+OUTPUT = output;

+ 17 - 0
json_importer_gen/test.sh

@@ -0,0 +1,17 @@
+
+URL='http://47.92.151.165:8080/script/exec/js?filepath=/matrix/utils/InitClassByJson.js'
+FORM='input={"classname":"/bofengtest/aaaa", "datafilename":"/opt/bofengtest/aaa/test.json"}'
+curl --location --request POST "${URL}" --header 'Authorization: Basic d2VjaXNlLmFkbWluOmFkbWlu' --form "${FORM}" ;echo
+
+exit
+
+URL='http://47.92.151.165:8080/script/exec/js?filepath=/matrix/utils/AlterClassByJson.js'
+FORM='input={"classname":"/bofengtest/aaaa", "options":"with ttl=10 day", "fieldmap": {"ID":"id"}, "fields":{"idUnique": "string,key"}, "mustfield": "idUnique", "data":{"ID":'`date +%Y%m%d%H%M%S`', "idUnique":"test'`date +%Y%m%d%H%M%S`'","changeSummary":{"info":"test for itil 变更单"}}}'
+curl --location --request POST "${URL}" --header 'Authorization: Basic d2VjaXNlLmFkbWluOmFkbWlu' --form "${FORM}" ;echo
+
+exit
+
+URL='http://47.92.151.165:8080/script/exec/js?filepath=/matrix/utils/JsonImporterGen.js'
+FORM='input={"classname":"/bofengtest/aaaa", "fieldmap": {"ID":"id"}, "mustfield": "idUnique", "data":{"ID":'`date +%Y%m%d%H%M%S`', "idUnique":"test'`date +%Y%m%d%H%M%S`'","changeSummary":{"info":"test for itil 变更单"}}}'
+curl --location --request POST "${URL}" --header 'Authorization: Basic d2VjaXNlLmFkbWluOmFkbWlu' --form "${FORM}" ;echo
+

Plik diff jest za duży
+ 25 - 0
remotecmd/3.txt


BIN
remotecmd/__pycache__/json.cpython-38.pyc


BIN
remotecmd/remote/packDFS.zip


+ 70 - 0
remotecmd/remote/packDfs.sh

@@ -0,0 +1,70 @@
+#! /bin/sh
+
+###   ### ###                  ##     
+##   ##  #  #                  #     
+###  ##     #                  #     
+# # # #   ##  ### #  ##  ###   ####  
+# # # #     #  #  ## #  #   #  #   # 
+#  #  #     #  ### # #  #####  #   # 
+#  #  #  #  #   ## ##   #      #   # 
+###   ### ###    #   #    ####  #### 
+
+clear
+
+host="47.92.151.165"
+port="8080"
+company="wecise"
+auth="wecise.admin:admin1234)(*&"
+ctime=`date +%Y%m%d`_`date +%H%M%S`
+target="./m3web/${host}_${company}/${ctime}"
+dfs=("/app/assets" "/app/matrix/m3appstore" "/app/matrix/m3auditlog" "/app/matrix/m3config" "/assets/images" "/etc" "/home/admin" "/opt" "/script/matrix")
+
+echo
+echo 'M³web 应用打包**********************************************************************'
+echo
+echo '打包服务器:'${host}':'${port} 
+echo
+echo '打包租户:'${company}
+echo
+mkdir -p ${target}
+echo '存放目录:'$target
+echo
+
+echo "Web前端打包开始。。。"
+echo
+#ssh  matrix@"${host}" "cd /opt/matrix/web;tar czvf - --exclude=/opt/matrix/web/public/web/vendor-20200726 --exclude=.DS_Store --exclude=/opt/matrix/web/templates/matrix/test public/ templates/ " > "${target}/web.tar.gz"
+s/ro action=remote host="${host}" username="matrix" password="MndzWDFxYVo=" cmds='"cd /opt/matrix/web;tar czvf - --exclude=/opt/matrix/web/public/web/vendor-20200726 --exclude=.DS_Store --exclude=/opt/matrix/web/templates/matrix/test public/ templates/ " > "'${target}'/web.tar.gz"'
+
+echo
+echo "文件系统打包开始。。。"
+echo
+for v in ${dfs[@]}
+
+do
+    name="dfs${v//\//_}"
+    echo "${v}"
+    echo
+    curl -u "${auth}" --location --request POST "http://${host}:${port}/fs/export?issys=true&srcpath=${v}"   >> "${target}/${name}.zip"
+    echo
+    echo
+done
+
+echo "合并文件系统"
+echo
+
+cd  $target
+for x in dfs_*.zip
+do 
+    unzip -d dfs -o -u $x
+done
+zip -r dfs.zip dfs
+
+echo "删除中件文件"
+echo
+rm -rf ./dfs_*.zip
+rm -rf dfs
+
+
+echo
+ls -rtl 
+echo '应用打包完成**********************************************************************'

+ 71 - 0
remotecmd/remote/s/ro

@@ -0,0 +1,71 @@
+
+export LANG=zh_CN.utf8
+export LC_ALL=zh_CN.utf8
+
+#改变工作目录到当前脚本所在路径
+if [[ "$0" =~ / ]]; then cd "${0%/*}"; fi
+
+mkdir -p "/opt/matrix/logs"
+
+if [[ "$#" == "0" ]]; then
+
+echo "
+usage:
+
+#执行本地命令
+ro action=local  cmds=<命令>
+
+#执行远程命令
+ro action=remote host=<IP或可解析的hostname> username=<用户> password=<密码> cmds=<命令>
+
+#从远程下载文件
+ro action=fget   host=<IP或可解析的hostname> username=<用户> password=<密码> local=<本地文件路径> remote=<远程文件路径>
+
+#上传文件到远程
+ro action=fput   host=<IP或可解析的hostname> username=<用户> password=<密码> local=<本地文件路径> remote=<远程文件路径>
+
+#Base64编码
+ro b64
+
+注意事项:
+命令:命令尽量使用单引号包括
+密码:需要BASE64编码,如果使用明文密码,那么需要在密码前增加一个等于号并使用单引号包括,例如:
+  ro action=remote host=127.0.0.1 username=root password='=123456' cmds='pwd;ls'
+Base64编码可以通过执行 ro b64 命令,输入明文,转换后得到
+"
+export ret=1
+
+elif [[ "$1" = "b64" ]]; then
+
+echo -n 输入:
+python -c "
+import base64;
+import sys;
+
+s = sys.stdin.readline().strip()
+try:
+	if s[0] == '=':
+		print(s[1:])
+	else:
+		if sys.version_info.major == 3:
+			s = bytes(s, encoding='utf8')
+		s = base64.b64encode(s)
+		if sys.version_info.major == 3:
+			s = str(s, encoding='utf8')
+		print(s)
+except TypeError as e:
+	#print(e)
+	print(s)
+"
+export ret=$?
+
+else
+
+python ro.py TRACE=SIPR logdir="/opt/matrix/logs" "$@"
+export ret=$?
+
+fi
+
+exit $ret
+
+#见见之时 见非是见 见犹离见 见不能及

Plik diff jest za duży
+ 1569 - 0
remotecmd/remote/s/ro.py


+ 4 - 0
remotecmd/run.sh

@@ -0,0 +1,4 @@
+
+echo bash -c "${@//\"/\\\"}"
+bash -c "${@//\"/\\\"}"
+

+ 62 - 0
remotecmd/s.py

@@ -0,0 +1,62 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+import requests
+import json
+import sys
+import time
+reload(sys)
+sys.setdefaultencoding( "utf-8" )
+date_time=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
+tmp_date_time=time.strftime('%Y%m%d%H%M%S',time.localtime(time.time()))
+tmp_date=time.strftime('%Y-%m-%d',time.localtime(time.time()))
+tmp_time=time.strftime('%H:%M:%S',time.localtime(time.time()))
+f=open("/opt/matrix/agent/bin/alert_cmd/send_sms.log", "a+")
+data1=sys.argv[1]
+data2=sys.argv[2]
+#hjson1= json.loads(data1.decode('utf-8'))
+hjson1= json.loads(data1)
+ipaddress=hjson1['netgate']['address']
+port=hjson1['netgate']['port']
+protocol=hjson1['netgate']['protocol']
+brNo=hjson1['netgate']['brNo']
+chanNo=hjson1['netgate']['chanNo']
+srvId=hjson1['netgate']['srvId']
+svcId=hjson1['netgate']['svcId']
+print(hjson1['jdbc']['driver'])
+#hjson2= json.loads(data2.decode('utf-8'))
+hjson2= json.loads(data2)
+#f.write(date_time+" "+hjson1+" "+hjson2+"\n")
+for msg in hjson2:
+  message=msg['msg']
+  for names in msg['to']:
+       touser=names['mobile']
+       #url=protocol+'://'+ipaddress+':'+port+'/'
+       url=protocol+'://'+str(ipaddress)+':'+str(port)+'/'
+       body='<?xml version="1.0" encoding="UTF-8"?>' \
+      '<reqt>' \
+      '<appHdr>' \
+      '<reqDt>'+tmp_date+'</reqDt>' \
+      '<reqTm>'+tmp_time+'</reqTm>' \
+      '<svcId>'+svcId+'</svcId>' \
+    '</appHdr>' \
+    '<appBody>' \
+      '<srvId>'+srvId+'</srvId>' \
+      '<chanNo>'+chanNo+'</chanNo>' \
+      '<brNo>'+brNo+'</brNo>' \
+      '<objAddr>'+touser+'</objAddr>' \
+      '<msgCont>'+message+'</msgCont>' \
+      '<ordTm>'+tmp_date_time+'</ordTm>' \
+      '<accNo>null</accNo>' \
+      '<custNo>null</custNo>' \
+    '</appBody>' \
+    '</reqt>'
+       #r = requests.post(url,data=body.decode("gbk").encode("utf-8"))
+       r = requests.post(url,data=body.encode("utf-8"))
+       #f.write(date_time+" "+url+" "+body+"\n")
+       f.write(date_time+" "+touser+" "+message+r.text+"\n")
+       #f.write(date_time+" "+touser+" "+message+"\n")
+f.close()
+#print(hjson1)
+
+
+

+ 94 - 0
remotecmd/send_sms.py

@@ -0,0 +1,94 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+import urllib2
+import json
+import os
+import sys
+import time
+
+reload(sys)
+sys.setdefaultencoding('utf8')
+
+#准备日志文件
+if not os.path.exists("/opt/matrix/agent/bin/alert_cmd"):
+    os.makedirs("/opt/matrix/agent/bin/alert_cmd")
+f = open("/opt/matrix/agent/bin/alert_cmd/send_sms.log", "a+")
+
+#日志输出
+def log(s):
+    dt=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
+    print(dt+" "+s+"\n")
+    f.write(dt+" "+s+"\n")
+
+try:
+    #
+    date_time=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
+    tmp_date_time=time.strftime('%Y%m%d%H%M%S',time.localtime(time.time()))
+    tmp_date=time.strftime('%Y-%m-%d',time.localtime(time.time()))
+    tmp_time=time.strftime('%H:%M:%S',time.localtime(time.time()))
+
+    #接收参数
+    log("=============================================================================")
+    data1 = sys.argv[1]
+    log("data1=" + data1)
+    data2 = sys.argv[2]
+    log("data2=" + data2)
+
+    #参数解析
+    #hjson1= json.loads(data1.decode('utf-8'))
+    hjson1= json.loads(data1)
+    ipaddress=hjson1['netgate']['address']
+    port=hjson1['netgate']['port']
+    protocol=hjson1['netgate']['protocol']
+    brNo=hjson1['netgate']['brNo']
+    chanNo=hjson1['netgate']['chanNo']
+    srvId=hjson1['netgate']['srvId']
+    svcId=hjson1['netgate']['svcId']
+    #log(hjson1['jdbc']['driver'])
+    #hjson2= json.loads(data2.decode('utf-8'))
+    hjson2= json.loads(data2)
+    #f.write(date_time+" "+hjson1+" "+hjson2+"\n")
+
+    #处理
+    for msg in hjson2:
+        message=msg['msg']
+        for names in msg['to']:
+            touser=names['mobile']
+            #url=protocol+'://'+ipaddress+':'+port+'/'
+            url=protocol+'://'+str(ipaddress)+':'+str(port)+'/'
+            body='<?xml version="1.0" encoding="UTF-8"?>' \
+                '<reqt>' \
+                '<appHdr>' \
+                '<reqDt>'+tmp_date+'</reqDt>' \
+                '<reqTm>'+tmp_time+'</reqTm>' \
+                '<svcId>'+svcId+'</svcId>' \
+                '</appHdr>' \
+                '<appBody>' \
+                '<srvId>'+srvId+'</srvId>' \
+                '<chanNo>'+chanNo+'</chanNo>' \
+                '<brNo>'+brNo+'</brNo>' \
+                '<objAddr>'+touser+'</objAddr>' \
+                '<msgCont>'+message+'</msgCont>' \
+                '<ordTm>'+tmp_date_time+'</ordTm>' \
+                '<accNo>null</accNo>' \
+                '<custNo>null</custNo>' \
+                '</appBody>' \
+                '</reqt>'
+            #data = urllib.urlencode(body)
+            log("发送请求:"+date_time+" "+url+" "+body)
+            response = urllib2.urlopen(urllib2.Request(url, body), timeout=3).read()
+            log("请求返回:"+date_time+" "+response)
+            #r = requests.post(url,data=body.decode("gbk").encode("utf-8"))
+            #r = requests.post(url,data=body.encode("utf-8"))
+            #f.write(date_time+" "+url+" "+body+"\n")
+            #f.write(date_time+" "+touser+" "+message+r.text+"\n")
+            #f.write(date_time+" "+touser+" "+message+"\n")
+    #print(hjson1)
+    #print(hjson2)
+    #send wechart
+except Exception as e:
+    log("{}".format(e))
+
+#关闭日志文件
+f.close()
+

+ 23 - 0
remotecmd/t.py

@@ -0,0 +1,23 @@
+#encoding=UTF8
+
+import os
+import sys
+import json
+
+
+def run(args):
+    o = json.loads(args)
+    print(json.dumps(o))
+
+def main():
+    cur_file_dir = os.path.split(os.path.abspath(__file__))[0];
+    envs_work_dir = os.path.split(cur_file_dir)[0];
+    os.chdir(envs_work_dir);
+    run(sys.argv[1] if len(sys.argv)>1 else "")
+
+if __name__ == '__main__':
+    try:
+        exit(main())
+    except KeyboardInterrupt as ki:
+        print("")
+        exit(130)