var ini = require("ini"); var fs = require("fs"); const Cryptr = require("cryptr"); const cryptr = new Cryptr("TBS"); var log = require("../util/log.js"); const notifier = require("node-notifier"); var moment = require("moment"); module.exports.encryptData = function encryptData(data) { var result = cryptr.encrypt(data); return result; }; module.exports.decryptData = function decryptData(data) { var result = cryptr.decrypt(data); return result; }; module.exports.throwNotif = function throwNotif(message) { notifier.notify( { title: "Check log for information", message: message, wait: true, sound: true, }, function (err, data) { //process.exit(); } ); }; module.exports.infoNotif = function infoNotif(title, message) { notifier.notify( { title: title, message: message, wait: true, sound: true, }, function (err, data) { //process.exit(); } ); }; module.exports.getConfig = function getConfig() { var configjs = ini.parse(fs.readFileSync("./config/config.ini", "utf-8")); if (configjs.database_dpack.user != "") { configjs.database_dpack.user = cryptr.decrypt(configjs.database_dpack.user); } if (configjs.database_dpack.password != "") { configjs.database_dpack.password = cryptr.decrypt( configjs.database_dpack.password ); } if (configjs.database_collection.user != "") { configjs.database_collection.user = cryptr.decrypt( configjs.database_collection.user ); } if (configjs.database_collection.password != "") { configjs.database_collection.password = cryptr.decrypt( configjs.database_collection.password ); } if (configjs.database_owner.user != "") { configjs.database_owner.user = cryptr.decrypt(configjs.database_owner.user); } if (configjs.database_owner.password != "") { configjs.database_owner.password = cryptr.decrypt( configjs.database_owner.password ); } if (configjs.database_sendcol.user != "") { configjs.database_sendcol.user = cryptr.decrypt( configjs.database_sendcol.user ); } if (configjs.database_sendcol.password != "") { configjs.database_sendcol.password = cryptr.decrypt( configjs.database_sendcol.password ); } return configjs; }; module.exports.saveConfig = function saveConfig(config) { config.database_dpack.user = cryptr.encrypt(config.database_dpack.user); config.database_dpack.password = cryptr.encrypt( config.database_dpack.password ); config.database_collection.user = cryptr.encrypt( config.database_collection.user ); config.database_collection.password = cryptr.encrypt( config.database_collection.password ); config.database_owner.user = cryptr.encrypt(config.database_owner.user); config.database_owner.password = cryptr.encrypt( config.database_owner.password ); config.database_sendcol.user = cryptr.encrypt(config.database_sendcol.user); config.database_sendcol.password = cryptr.encrypt( config.database_sendcol.password ); if ( config != null || config != undefined || config.owner != null || config.owner != "" || config.owner != undefined ) { try { fs.writeFileSync("./config/config.ini", ini.stringify(config)); } catch (e) { log.createLog(0, e.message); } } }; module.exports.getProcess = function getProcess() { try { var configjs = ini.parse(fs.readFileSync("./config/process.ini", "utf-8")); console.log(configjs); return configjs; } catch (e) { log.createLog(0, e.message); throw e.message; } }; module.exports.saveProcess = function saveProcess(process) { try { fs.writeFileSync("./config/process.ini", ini.stringify(process)); } catch (e) { log.createLog(0, e.message); throw e.message; } }; module.exports.regexQuery = async function regexQuery(query, last_date) { if (last_date == null) { last_date = moment().format("YYYY-MM-DD HH:mm:ss.SSS"); } else { last_date = moment.utc(last_date).format("YYYY-MM-DD HH:mm:ss.SSS"); } var dataRegex = ["[COMPANY]", "[LAST_DATE]"]; var configjs = this.getConfig(); regex = configjs.config_regex; RegExp.quote = function (str) { return str.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1"); }; dataRegex.forEach((word) => { var regExp = new RegExp(RegExp.quote(word), "g"); if (word == "[COMPANY]") { query = query.replace(regExp, `'${regex.owner}'`); } else if (word == "[LAST_DATE]") { query = query.replace(regExp, `'${last_date}'`); } }); return query; }; module.exports.changeColumnOracle = function changeColumnOracle(string) { var numberIndicate = parseInt(string.substr(1)); numberIndicate = 1000 + numberIndicate; numberIndicate = numberIndicate.toString().substr(1); var result = string[0] + numberIndicate; return result; };