Dpack get data Node : V10
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 

187 satır
4.8 KiB

  1. var ini = require("ini");
  2. var fs = require("fs");
  3. const Cryptr = require("cryptr");
  4. const cryptr = new Cryptr("TBS");
  5. var log = require("../util/log.js");
  6. const notifier = require("node-notifier");
  7. var moment = require("moment");
  8. module.exports.encryptData = function encryptData(data) {
  9. var result = cryptr.encrypt(data);
  10. return result;
  11. };
  12. module.exports.decryptData = function decryptData(data) {
  13. var result = cryptr.decrypt(data);
  14. return result;
  15. };
  16. module.exports.throwNotif = function throwNotif(message) {
  17. notifier.notify(
  18. {
  19. title: "Check log for information",
  20. message: message,
  21. wait: true,
  22. sound: true,
  23. },
  24. function (err, data) {
  25. //process.exit();
  26. }
  27. );
  28. };
  29. module.exports.infoNotif = function infoNotif(title, message) {
  30. notifier.notify(
  31. {
  32. title: title,
  33. message: message,
  34. wait: true,
  35. sound: true,
  36. },
  37. function (err, data) {
  38. //process.exit();
  39. }
  40. );
  41. };
  42. module.exports.getConfig = function getConfig() {
  43. var configjs = ini.parse(fs.readFileSync("./config/config.ini", "utf-8"));
  44. if (configjs.database_dpack.user != "") {
  45. configjs.database_dpack.user = cryptr.decrypt(configjs.database_dpack.user);
  46. }
  47. if (configjs.database_dpack.password != "") {
  48. configjs.database_dpack.password = cryptr.decrypt(
  49. configjs.database_dpack.password
  50. );
  51. }
  52. if (configjs.database_collection.user != "") {
  53. configjs.database_collection.user = cryptr.decrypt(
  54. configjs.database_collection.user
  55. );
  56. }
  57. if (configjs.database_collection.password != "") {
  58. configjs.database_collection.password = cryptr.decrypt(
  59. configjs.database_collection.password
  60. );
  61. }
  62. if (configjs.database_owner.user != "") {
  63. configjs.database_owner.user = cryptr.decrypt(configjs.database_owner.user);
  64. }
  65. if (configjs.database_owner.password != "") {
  66. configjs.database_owner.password = cryptr.decrypt(
  67. configjs.database_owner.password
  68. );
  69. }
  70. if (configjs.database_sendcol.user != "") {
  71. configjs.database_sendcol.user = cryptr.decrypt(
  72. configjs.database_sendcol.user
  73. );
  74. }
  75. if (configjs.database_sendcol.password != "") {
  76. configjs.database_sendcol.password = cryptr.decrypt(
  77. configjs.database_sendcol.password
  78. );
  79. }
  80. return configjs;
  81. };
  82. module.exports.saveConfig = function saveConfig(config) {
  83. config.database_dpack.user = cryptr.encrypt(config.database_dpack.user);
  84. config.database_dpack.password = cryptr.encrypt(
  85. config.database_dpack.password
  86. );
  87. config.database_collection.user = cryptr.encrypt(
  88. config.database_collection.user
  89. );
  90. config.database_collection.password = cryptr.encrypt(
  91. config.database_collection.password
  92. );
  93. config.database_owner.user = cryptr.encrypt(config.database_owner.user);
  94. config.database_owner.password = cryptr.encrypt(
  95. config.database_owner.password
  96. );
  97. config.database_sendcol.user = cryptr.encrypt(config.database_sendcol.user);
  98. config.database_sendcol.password = cryptr.encrypt(
  99. config.database_sendcol.password
  100. );
  101. if (
  102. config != null ||
  103. config != undefined ||
  104. config.owner != null ||
  105. config.owner != "" ||
  106. config.owner != undefined
  107. ) {
  108. try {
  109. fs.writeFileSync("./config/config.ini", ini.stringify(config));
  110. } catch (e) {
  111. log.createLog(0, e.message);
  112. }
  113. }
  114. };
  115. module.exports.getProcess = function getProcess() {
  116. try {
  117. var configjs = ini.parse(fs.readFileSync("./config/process.ini", "utf-8"));
  118. console.log(configjs);
  119. return configjs;
  120. } catch (e) {
  121. log.createLog(0, e.message);
  122. throw e.message;
  123. }
  124. };
  125. module.exports.saveProcess = function saveProcess(process) {
  126. try {
  127. fs.writeFileSync("./config/process.ini", ini.stringify(process));
  128. } catch (e) {
  129. log.createLog(0, e.message);
  130. throw e.message;
  131. }
  132. };
  133. module.exports.regexQuery = async function regexQuery(query, last_date) {
  134. if (last_date == null) {
  135. last_date = moment().format("YYYY-MM-DD HH:mm:ss.SSS");
  136. } else {
  137. last_date = moment.utc(last_date).format("YYYY-MM-DD HH:mm:ss.SSS");
  138. }
  139. var dataRegex = ["[COMPANY]", "[LAST_DATE]"];
  140. var configjs = this.getConfig();
  141. regex = configjs.config_regex;
  142. RegExp.quote = function (str) {
  143. return str.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
  144. };
  145. dataRegex.forEach((word) => {
  146. var regExp = new RegExp(RegExp.quote(word), "g");
  147. if (word == "[COMPANY]") {
  148. query = query.replace(regExp, `'${regex.owner}'`);
  149. } else if (word == "[LAST_DATE]") {
  150. query = query.replace(regExp, `'${last_date}'`);
  151. }
  152. });
  153. return query;
  154. };
  155. module.exports.changeColumnOracle = function changeColumnOracle(string) {
  156. var numberIndicate = parseInt(string.substr(1));
  157. numberIndicate = 1000 + numberIndicate;
  158. numberIndicate = numberIndicate.toString().substr(1);
  159. var result = string[0] + numberIndicate;
  160. return result;
  161. };