From 2682df395090d3a33d54f2353907758089a77a65 Mon Sep 17 00:00:00 2001 From: sp Date: Mon, 13 Mar 2023 13:42:16 +0530 Subject: [PATCH 1/4] added the jar while authenticating the request --- package-lock.json | 576 +++++++++++++++++++++++++++++++++++++++-- package.json | 6 +- server.js | 25 +- utils/getCookie.js | 105 ++++---- utils/pull_from_mii.js | 18 +- utils/push_to_mii.js | 85 +++--- 6 files changed, 679 insertions(+), 136 deletions(-) diff --git a/package-lock.json b/package-lock.json index 37ab7f3..e90da42 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,9 +5,21 @@ "packages": { "": { "dependencies": { + "cheerio": "^1.0.0-rc.12", "express": "^4.18.2", + "jquery": "^3.6.4", + "prompt": "^1.3.0", "request": "^2.88.2", - "xml2js": "^0.4.23" + "xml2js": "^0.4.23", + "xmldom": "^0.6.0" + } + }, + "node_modules/@colors/colors": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.5.0.tgz", + "integrity": "sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==", + "engines": { + "node": ">=0.1.90" } }, "node_modules/accepts": { @@ -58,6 +70,11 @@ "node": ">=0.8" } }, + "node_modules/async": { + "version": "3.2.3", + "resolved": "https://registry.npmjs.org/async/-/async-3.2.3.tgz", + "integrity": "sha512-spZRyzKL5l5BZQrr/6m/SqFdBN0q3OCI0f9rjfBzCMBIP4p75P620rR3gTmaksNOhmzgdxcaxdNfMy6anrbM0g==" + }, "node_modules/asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", @@ -107,6 +124,11 @@ "npm": "1.2.8000 || >= 1.4.16" } }, + "node_modules/boolbase": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz", + "integrity": "sha512-JZOSA7Mo9sNGB8+UjSgzdLtokWAky1zbztM3WRLCbZ70/3cTANmQmOdR7y2g+J0e2WXywy1yS468tY+IruqEww==" + }, "node_modules/bytes": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", @@ -132,6 +154,50 @@ "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", "integrity": "sha512-4tYFyifaFfGacoiObjJegolkwSU4xQNGbVgUiNYVUxbQ2x2lUsFvY4hVgVzGiIe6WLOPqycWXA40l+PWsxthUw==" }, + "node_modules/cheerio": { + "version": "1.0.0-rc.12", + "resolved": "https://registry.npmjs.org/cheerio/-/cheerio-1.0.0-rc.12.tgz", + "integrity": "sha512-VqR8m68vM46BNnuZ5NtnGBKIE/DfN0cRIzg9n40EIq9NOv90ayxLBXA8fXC5gquFRGJSTRqBq25Jt2ECLR431Q==", + "dependencies": { + "cheerio-select": "^2.1.0", + "dom-serializer": "^2.0.0", + "domhandler": "^5.0.3", + "domutils": "^3.0.1", + "htmlparser2": "^8.0.1", + "parse5": "^7.0.0", + "parse5-htmlparser2-tree-adapter": "^7.0.0" + }, + "engines": { + "node": ">= 6" + }, + "funding": { + "url": "https://github.com/cheeriojs/cheerio?sponsor=1" + } + }, + "node_modules/cheerio-select": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/cheerio-select/-/cheerio-select-2.1.0.tgz", + "integrity": "sha512-9v9kG0LvzrlcungtnJtpGNxY+fzECQKhK4EGJX2vByejiMX84MFNQw4UxPJl3bFbTMw+Dfs37XaIkCwTZfLh4g==", + "dependencies": { + "boolbase": "^1.0.0", + "css-select": "^5.1.0", + "css-what": "^6.1.0", + "domelementtype": "^2.3.0", + "domhandler": "^5.0.3", + "domutils": "^3.0.1" + }, + "funding": { + "url": "https://github.com/sponsors/fb55" + } + }, + "node_modules/colors": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/colors/-/colors-1.0.3.tgz", + "integrity": "sha512-pFGrxThWcWQ2MsAz6RtgeWe4NK2kUE1WfsrvvlctdII745EW9I0yflqhe7++M5LEc7bV2c/9/5zc8sFcpL0Drw==", + "engines": { + "node": ">=0.1.90" + } + }, "node_modules/combined-stream": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", @@ -180,6 +246,40 @@ "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", "integrity": "sha512-3lqz5YjWTYnW6dlDa5TLaTCcShfar1e40rmcJVwCBJC6mWlFuj0eCHIElmG1g5kyuJ/GD+8Wn4FFCcz4gJPfaQ==" }, + "node_modules/css-select": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/css-select/-/css-select-5.1.0.tgz", + "integrity": "sha512-nwoRF1rvRRnnCqqY7updORDsuqKzqYJ28+oSMaJMMgOauh3fvwHqMS7EZpIPqK8GL+g9mKxF1vP/ZjSeNjEVHg==", + "dependencies": { + "boolbase": "^1.0.0", + "css-what": "^6.1.0", + "domhandler": "^5.0.2", + "domutils": "^3.0.1", + "nth-check": "^2.0.1" + }, + "funding": { + "url": "https://github.com/sponsors/fb55" + } + }, + "node_modules/css-what": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/css-what/-/css-what-6.1.0.tgz", + "integrity": "sha512-HTUrgRJ7r4dsZKU6GjmpfRK1O76h97Z8MfS1G0FozR+oF2kG6Vfe8JE6zwrkbxigziPHinCJ+gCPjA9EaBDtRw==", + "engines": { + "node": ">= 6" + }, + "funding": { + "url": "https://github.com/sponsors/fb55" + } + }, + "node_modules/cycle": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/cycle/-/cycle-1.0.3.tgz", + "integrity": "sha512-TVF6svNzeQCOpjCqsy0/CSy8VgObG3wXusJ73xW2GbG5rGx7lC8zxDSURicsXI2UsGdi2L0QNRCi745/wUDvsA==", + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/dashdash": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", @@ -224,6 +324,57 @@ "npm": "1.2.8000 || >= 1.4.16" } }, + "node_modules/dom-serializer": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-2.0.0.tgz", + "integrity": "sha512-wIkAryiqt/nV5EQKqQpo3SToSOV9J0DnbJqwK7Wv/Trc92zIAYZ4FlMu+JPFW1DfGFt81ZTCGgDEabffXeLyJg==", + "dependencies": { + "domelementtype": "^2.3.0", + "domhandler": "^5.0.2", + "entities": "^4.2.0" + }, + "funding": { + "url": "https://github.com/cheeriojs/dom-serializer?sponsor=1" + } + }, + "node_modules/domelementtype": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-2.3.0.tgz", + "integrity": "sha512-OLETBj6w0OsagBwdXnPdN0cnMfF9opN69co+7ZrbfPGrdpPVNBUj02spi6B1N7wChLQiPn4CSH/zJvXw56gmHw==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fb55" + } + ] + }, + "node_modules/domhandler": { + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-5.0.3.tgz", + "integrity": "sha512-cgwlv/1iFQiFnU96XXgROh8xTeetsnJiDsTc7TYCLFd9+/WNkIqPTxiM/8pSd8VIrhXGTf1Ny1q1hquVqDJB5w==", + "dependencies": { + "domelementtype": "^2.3.0" + }, + "engines": { + "node": ">= 4" + }, + "funding": { + "url": "https://github.com/fb55/domhandler?sponsor=1" + } + }, + "node_modules/domutils": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/domutils/-/domutils-3.0.1.tgz", + "integrity": "sha512-z08c1l761iKhDFtfXO04C7kTdPBLi41zwOZl00WS8b5eiaebNpY00HKbztwBq+e3vyqWNwWF3mP9YLUeqIrF+Q==", + "dependencies": { + "dom-serializer": "^2.0.0", + "domelementtype": "^2.3.0", + "domhandler": "^5.0.1" + }, + "funding": { + "url": "https://github.com/fb55/domutils?sponsor=1" + } + }, "node_modules/ecc-jsbn": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", @@ -246,6 +397,17 @@ "node": ">= 0.8" } }, + "node_modules/entities": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/entities/-/entities-4.4.0.tgz", + "integrity": "sha512-oYp7156SP8LkeGD0GF85ad1X9Ai79WtRsZ2gxJqtBuzH+98YUV6jkHEKlZkMbcrjJjIVJNIDP/3WL9wQkoPbWA==", + "engines": { + "node": ">=0.12" + }, + "funding": { + "url": "https://github.com/fb55/entities?sponsor=1" + } + }, "node_modules/escape-html": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", @@ -313,6 +475,14 @@ "node >=0.6.0" ] }, + "node_modules/eyes": { + "version": "0.1.8", + "resolved": "https://registry.npmjs.org/eyes/-/eyes-0.1.8.tgz", + "integrity": "sha512-GipyPsXO1anza0AOZdy69Im7hGFCNB7Y/NGjDlZGJ3GJJLtwNSb2vrzYrTYJRrRloVx7pl+bhUaTB8yiccPvFQ==", + "engines": { + "node": "> 0.1.90" + } + }, "node_modules/fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", @@ -446,6 +616,24 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/htmlparser2": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-8.0.1.tgz", + "integrity": "sha512-4lVbmc1diZC7GUJQtRQ5yBAeUCL1exyMwmForWkRLnwyzWBFxN633SALPMGYaWZvKe9j1pRZJpauvmxENSp/EA==", + "funding": [ + "https://github.com/fb55/htmlparser2?sponsor=1", + { + "type": "github", + "url": "https://github.com/sponsors/fb55" + } + ], + "dependencies": { + "domelementtype": "^2.3.0", + "domhandler": "^5.0.2", + "domutils": "^3.0.1", + "entities": "^4.3.0" + } + }, "node_modules/http-errors": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz", @@ -509,6 +697,11 @@ "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", "integrity": "sha512-Yljz7ffyPbrLpLngrMtZ7NduUgVvi6wG9RJ9IUcyCd59YQ911PBJphODUcbOVbqYfxe1wuYf/LJ8PauMRwsM/g==" }, + "node_modules/jquery": { + "version": "3.6.4", + "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.6.4.tgz", + "integrity": "sha512-v28EW9DWDFpzcD9O5iyJXg3R3+q+mET5JhnjJzQUZMHOv67bpSIHq81GEYpPNZHG+XXHsfSme3nxp/hndKEcsQ==" + }, "node_modules/jsbn": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", @@ -543,6 +736,11 @@ "node": ">=0.6.0" } }, + "node_modules/lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" + }, "node_modules/media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", @@ -599,6 +797,11 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" }, + "node_modules/mute-stream": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.8.tgz", + "integrity": "sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==" + }, "node_modules/negotiator": { "version": "0.6.3", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", @@ -607,6 +810,17 @@ "node": ">= 0.6" } }, + "node_modules/nth-check": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/nth-check/-/nth-check-2.1.1.tgz", + "integrity": "sha512-lqjrjmaOoAnWfMmBPL+XNnynZh2+swxiX3WUE0s4yEHI6m+AwrK2UZOimIRl3X/4QctVqS8AiZjFqyOGrMXb/w==", + "dependencies": { + "boolbase": "^1.0.0" + }, + "funding": { + "url": "https://github.com/fb55/nth-check?sponsor=1" + } + }, "node_modules/oauth-sign": { "version": "0.9.0", "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz", @@ -634,6 +848,29 @@ "node": ">= 0.8" } }, + "node_modules/parse5": { + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/parse5/-/parse5-7.1.2.tgz", + "integrity": "sha512-Czj1WaSVpaoj0wbhMzLmWD69anp2WH7FXMB9n1Sy8/ZFF9jolSQVMu1Ij5WIyGmcBmhk7EOndpO4mIpihVqAXw==", + "dependencies": { + "entities": "^4.4.0" + }, + "funding": { + "url": "https://github.com/inikulin/parse5?sponsor=1" + } + }, + "node_modules/parse5-htmlparser2-tree-adapter": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/parse5-htmlparser2-tree-adapter/-/parse5-htmlparser2-tree-adapter-7.0.0.tgz", + "integrity": "sha512-B77tOZrqqfUfnVcOrUvfdLbz4pu4RopLD/4vmu3HUPswwTA8OH0EMW9BlWR2B0RCoiZRAHEUu7IxeP1Pd1UU+g==", + "dependencies": { + "domhandler": "^5.0.2", + "parse5": "^7.0.0" + }, + "funding": { + "url": "https://github.com/inikulin/parse5?sponsor=1" + } + }, "node_modules/parseurl": { "version": "1.3.3", "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", @@ -652,6 +889,21 @@ "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", "integrity": "sha512-7EAHlyLHI56VEIdK57uwHdHKIaAGbnXPiw0yWbarQZOKaKpvUIgW0jWRVLiatnM+XXlSwsanIBH/hzGMJulMow==" }, + "node_modules/prompt": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/prompt/-/prompt-1.3.0.tgz", + "integrity": "sha512-ZkaRWtaLBZl7KKAKndKYUL8WqNT+cQHKRZnT4RYYms48jQkFw3rrBL+/N5K/KtdEveHkxs982MX2BkDKub2ZMg==", + "dependencies": { + "@colors/colors": "1.5.0", + "async": "3.2.3", + "read": "1.0.x", + "revalidator": "0.1.x", + "winston": "2.x" + }, + "engines": { + "node": ">= 6.0.0" + } + }, "node_modules/proxy-addr": { "version": "2.0.7", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", @@ -713,6 +965,17 @@ "node": ">= 0.8" } }, + "node_modules/read": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/read/-/read-1.0.7.tgz", + "integrity": "sha512-rSOKNYUmaxy0om1BNjMN4ezNT6VKK+2xF4GBhc81mkH7L60i6dp8qPYrkndNLT3QPphoII3maL9PVC9XmhHwVQ==", + "dependencies": { + "mute-stream": "~0.0.4" + }, + "engines": { + "node": ">=0.8" + } + }, "node_modules/request": { "version": "2.88.2", "resolved": "https://registry.npmjs.org/request/-/request-2.88.2.tgz", @@ -752,6 +1015,26 @@ "node": ">=0.6" } }, + "node_modules/request/node_modules/tough-cookie": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz", + "integrity": "sha512-nlLsUzgm1kfLXSXfRZMc1KLAugd4hqJHDTvc2hDIwS3mZAfMEuMbc03SujMF+GEcpaX/qboeycw6iO8JwVv2+g==", + "dependencies": { + "psl": "^1.1.28", + "punycode": "^2.1.1" + }, + "engines": { + "node": ">=0.8" + } + }, + "node_modules/revalidator": { + "version": "0.1.8", + "resolved": "https://registry.npmjs.org/revalidator/-/revalidator-0.1.8.tgz", + "integrity": "sha512-xcBILK2pA9oh4SiinPEZfhP8HfrB/ha+a2fTMyl7Om2WjlDVrOQy99N2MXXlUHqGJz4qEu2duXxHJjDWuK/0xg==", + "engines": { + "node": ">= 0.4.0" + } + }, "node_modules/safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", @@ -865,6 +1148,14 @@ "node": ">=0.10.0" } }, + "node_modules/stack-trace": { + "version": "0.0.10", + "resolved": "https://registry.npmjs.org/stack-trace/-/stack-trace-0.0.10.tgz", + "integrity": "sha512-KGzahc7puUKkzyMt+IqAep+TVNbKP+k2Lmwhub39m1AsTSkaDutx56aDCo+HLDzf/D26BIHTJWNiTG1KAJiQCg==", + "engines": { + "node": "*" + } + }, "node_modules/statuses": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", @@ -881,18 +1172,6 @@ "node": ">=0.6" } }, - "node_modules/tough-cookie": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz", - "integrity": "sha512-nlLsUzgm1kfLXSXfRZMc1KLAugd4hqJHDTvc2hDIwS3mZAfMEuMbc03SujMF+GEcpaX/qboeycw6iO8JwVv2+g==", - "dependencies": { - "psl": "^1.1.28", - "punycode": "^2.1.1" - }, - "engines": { - "node": ">=0.8" - } - }, "node_modules/tunnel-agent": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", @@ -975,6 +1254,30 @@ "extsprintf": "^1.2.0" } }, + "node_modules/winston": { + "version": "2.4.7", + "resolved": "https://registry.npmjs.org/winston/-/winston-2.4.7.tgz", + "integrity": "sha512-vLB4BqzCKDnnZH9PHGoS2ycawueX4HLqENXQitvFHczhgW2vFpSOn31LZtVr1KU8YTw7DS4tM+cqyovxo8taVg==", + "dependencies": { + "async": "^2.6.4", + "colors": "1.0.x", + "cycle": "1.0.x", + "eyes": "0.1.x", + "isstream": "0.1.x", + "stack-trace": "0.0.x" + }, + "engines": { + "node": ">= 0.10.0" + } + }, + "node_modules/winston/node_modules/async": { + "version": "2.6.4", + "resolved": "https://registry.npmjs.org/async/-/async-2.6.4.tgz", + "integrity": "sha512-mzo5dfJYwAn29PeiJ0zvwTo04zj8HDJj0Mn8TD7sno7q12prdbnasKJHhkm2c1LgrhlJ0teaea8860oxi51mGA==", + "dependencies": { + "lodash": "^4.17.14" + } + }, "node_modules/xml2js": { "version": "0.4.23", "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.23.tgz", @@ -994,9 +1297,22 @@ "engines": { "node": ">=4.0" } + }, + "node_modules/xmldom": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/xmldom/-/xmldom-0.6.0.tgz", + "integrity": "sha512-iAcin401y58LckRZ0TkI4k0VSM1Qg0KGSc3i8rU+xrxe19A/BN1zHyVSJY7uoutVlaTSzYyk/v5AmkewAP7jtg==", + "engines": { + "node": ">=10.0.0" + } } }, "dependencies": { + "@colors/colors": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.5.0.tgz", + "integrity": "sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==" + }, "accepts": { "version": "1.3.8", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", @@ -1035,6 +1351,11 @@ "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", "integrity": "sha512-NfJ4UzBCcQGLDlQq7nHxH+tv3kyZ0hHQqF5BO6J7tNJeP5do1llPr8dZ8zHonfhAu0PHAdMkSo+8o0wxg9lZWw==" }, + "async": { + "version": "3.2.3", + "resolved": "https://registry.npmjs.org/async/-/async-3.2.3.tgz", + "integrity": "sha512-spZRyzKL5l5BZQrr/6m/SqFdBN0q3OCI0f9rjfBzCMBIP4p75P620rR3gTmaksNOhmzgdxcaxdNfMy6anrbM0g==" + }, "asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", @@ -1077,6 +1398,11 @@ "unpipe": "1.0.0" } }, + "boolbase": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz", + "integrity": "sha512-JZOSA7Mo9sNGB8+UjSgzdLtokWAky1zbztM3WRLCbZ70/3cTANmQmOdR7y2g+J0e2WXywy1yS468tY+IruqEww==" + }, "bytes": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", @@ -1096,6 +1422,38 @@ "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", "integrity": "sha512-4tYFyifaFfGacoiObjJegolkwSU4xQNGbVgUiNYVUxbQ2x2lUsFvY4hVgVzGiIe6WLOPqycWXA40l+PWsxthUw==" }, + "cheerio": { + "version": "1.0.0-rc.12", + "resolved": "https://registry.npmjs.org/cheerio/-/cheerio-1.0.0-rc.12.tgz", + "integrity": "sha512-VqR8m68vM46BNnuZ5NtnGBKIE/DfN0cRIzg9n40EIq9NOv90ayxLBXA8fXC5gquFRGJSTRqBq25Jt2ECLR431Q==", + "requires": { + "cheerio-select": "^2.1.0", + "dom-serializer": "^2.0.0", + "domhandler": "^5.0.3", + "domutils": "^3.0.1", + "htmlparser2": "^8.0.1", + "parse5": "^7.0.0", + "parse5-htmlparser2-tree-adapter": "^7.0.0" + } + }, + "cheerio-select": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/cheerio-select/-/cheerio-select-2.1.0.tgz", + "integrity": "sha512-9v9kG0LvzrlcungtnJtpGNxY+fzECQKhK4EGJX2vByejiMX84MFNQw4UxPJl3bFbTMw+Dfs37XaIkCwTZfLh4g==", + "requires": { + "boolbase": "^1.0.0", + "css-select": "^5.1.0", + "css-what": "^6.1.0", + "domelementtype": "^2.3.0", + "domhandler": "^5.0.3", + "domutils": "^3.0.1" + } + }, + "colors": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/colors/-/colors-1.0.3.tgz", + "integrity": "sha512-pFGrxThWcWQ2MsAz6RtgeWe4NK2kUE1WfsrvvlctdII745EW9I0yflqhe7++M5LEc7bV2c/9/5zc8sFcpL0Drw==" + }, "combined-stream": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", @@ -1132,6 +1490,28 @@ "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", "integrity": "sha512-3lqz5YjWTYnW6dlDa5TLaTCcShfar1e40rmcJVwCBJC6mWlFuj0eCHIElmG1g5kyuJ/GD+8Wn4FFCcz4gJPfaQ==" }, + "css-select": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/css-select/-/css-select-5.1.0.tgz", + "integrity": "sha512-nwoRF1rvRRnnCqqY7updORDsuqKzqYJ28+oSMaJMMgOauh3fvwHqMS7EZpIPqK8GL+g9mKxF1vP/ZjSeNjEVHg==", + "requires": { + "boolbase": "^1.0.0", + "css-what": "^6.1.0", + "domhandler": "^5.0.2", + "domutils": "^3.0.1", + "nth-check": "^2.0.1" + } + }, + "css-what": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/css-what/-/css-what-6.1.0.tgz", + "integrity": "sha512-HTUrgRJ7r4dsZKU6GjmpfRK1O76h97Z8MfS1G0FozR+oF2kG6Vfe8JE6zwrkbxigziPHinCJ+gCPjA9EaBDtRw==" + }, + "cycle": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/cycle/-/cycle-1.0.3.tgz", + "integrity": "sha512-TVF6svNzeQCOpjCqsy0/CSy8VgObG3wXusJ73xW2GbG5rGx7lC8zxDSURicsXI2UsGdi2L0QNRCi745/wUDvsA==" + }, "dashdash": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", @@ -1163,6 +1543,39 @@ "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz", "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==" }, + "dom-serializer": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-2.0.0.tgz", + "integrity": "sha512-wIkAryiqt/nV5EQKqQpo3SToSOV9J0DnbJqwK7Wv/Trc92zIAYZ4FlMu+JPFW1DfGFt81ZTCGgDEabffXeLyJg==", + "requires": { + "domelementtype": "^2.3.0", + "domhandler": "^5.0.2", + "entities": "^4.2.0" + } + }, + "domelementtype": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-2.3.0.tgz", + "integrity": "sha512-OLETBj6w0OsagBwdXnPdN0cnMfF9opN69co+7ZrbfPGrdpPVNBUj02spi6B1N7wChLQiPn4CSH/zJvXw56gmHw==" + }, + "domhandler": { + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-5.0.3.tgz", + "integrity": "sha512-cgwlv/1iFQiFnU96XXgROh8xTeetsnJiDsTc7TYCLFd9+/WNkIqPTxiM/8pSd8VIrhXGTf1Ny1q1hquVqDJB5w==", + "requires": { + "domelementtype": "^2.3.0" + } + }, + "domutils": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/domutils/-/domutils-3.0.1.tgz", + "integrity": "sha512-z08c1l761iKhDFtfXO04C7kTdPBLi41zwOZl00WS8b5eiaebNpY00HKbztwBq+e3vyqWNwWF3mP9YLUeqIrF+Q==", + "requires": { + "dom-serializer": "^2.0.0", + "domelementtype": "^2.3.0", + "domhandler": "^5.0.1" + } + }, "ecc-jsbn": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", @@ -1182,6 +1595,11 @@ "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", "integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==" }, + "entities": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/entities/-/entities-4.4.0.tgz", + "integrity": "sha512-oYp7156SP8LkeGD0GF85ad1X9Ai79WtRsZ2gxJqtBuzH+98YUV6jkHEKlZkMbcrjJjIVJNIDP/3WL9wQkoPbWA==" + }, "escape-html": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", @@ -1240,6 +1658,11 @@ "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", "integrity": "sha512-11Ndz7Nv+mvAC1j0ktTa7fAb0vLyGGX+rMHNBYQviQDGU0Hw7lhctJANqbPhu9nV9/izT/IntTgZ7Im/9LJs9g==" }, + "eyes": { + "version": "0.1.8", + "resolved": "https://registry.npmjs.org/eyes/-/eyes-0.1.8.tgz", + "integrity": "sha512-GipyPsXO1anza0AOZdy69Im7hGFCNB7Y/NGjDlZGJ3GJJLtwNSb2vrzYrTYJRrRloVx7pl+bhUaTB8yiccPvFQ==" + }, "fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", @@ -1339,6 +1762,17 @@ "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==" }, + "htmlparser2": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-8.0.1.tgz", + "integrity": "sha512-4lVbmc1diZC7GUJQtRQ5yBAeUCL1exyMwmForWkRLnwyzWBFxN633SALPMGYaWZvKe9j1pRZJpauvmxENSp/EA==", + "requires": { + "domelementtype": "^2.3.0", + "domhandler": "^5.0.2", + "domutils": "^3.0.1", + "entities": "^4.3.0" + } + }, "http-errors": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz", @@ -1389,6 +1823,11 @@ "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", "integrity": "sha512-Yljz7ffyPbrLpLngrMtZ7NduUgVvi6wG9RJ9IUcyCd59YQ911PBJphODUcbOVbqYfxe1wuYf/LJ8PauMRwsM/g==" }, + "jquery": { + "version": "3.6.4", + "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.6.4.tgz", + "integrity": "sha512-v28EW9DWDFpzcD9O5iyJXg3R3+q+mET5JhnjJzQUZMHOv67bpSIHq81GEYpPNZHG+XXHsfSme3nxp/hndKEcsQ==" + }, "jsbn": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", @@ -1420,6 +1859,11 @@ "verror": "1.10.0" } }, + "lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" + }, "media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", @@ -1458,11 +1902,24 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" }, + "mute-stream": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.8.tgz", + "integrity": "sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==" + }, "negotiator": { "version": "0.6.3", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==" }, + "nth-check": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/nth-check/-/nth-check-2.1.1.tgz", + "integrity": "sha512-lqjrjmaOoAnWfMmBPL+XNnynZh2+swxiX3WUE0s4yEHI6m+AwrK2UZOimIRl3X/4QctVqS8AiZjFqyOGrMXb/w==", + "requires": { + "boolbase": "^1.0.0" + } + }, "oauth-sign": { "version": "0.9.0", "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz", @@ -1481,6 +1938,23 @@ "ee-first": "1.1.1" } }, + "parse5": { + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/parse5/-/parse5-7.1.2.tgz", + "integrity": "sha512-Czj1WaSVpaoj0wbhMzLmWD69anp2WH7FXMB9n1Sy8/ZFF9jolSQVMu1Ij5WIyGmcBmhk7EOndpO4mIpihVqAXw==", + "requires": { + "entities": "^4.4.0" + } + }, + "parse5-htmlparser2-tree-adapter": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/parse5-htmlparser2-tree-adapter/-/parse5-htmlparser2-tree-adapter-7.0.0.tgz", + "integrity": "sha512-B77tOZrqqfUfnVcOrUvfdLbz4pu4RopLD/4vmu3HUPswwTA8OH0EMW9BlWR2B0RCoiZRAHEUu7IxeP1Pd1UU+g==", + "requires": { + "domhandler": "^5.0.2", + "parse5": "^7.0.0" + } + }, "parseurl": { "version": "1.3.3", "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", @@ -1496,6 +1970,18 @@ "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", "integrity": "sha512-7EAHlyLHI56VEIdK57uwHdHKIaAGbnXPiw0yWbarQZOKaKpvUIgW0jWRVLiatnM+XXlSwsanIBH/hzGMJulMow==" }, + "prompt": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/prompt/-/prompt-1.3.0.tgz", + "integrity": "sha512-ZkaRWtaLBZl7KKAKndKYUL8WqNT+cQHKRZnT4RYYms48jQkFw3rrBL+/N5K/KtdEveHkxs982MX2BkDKub2ZMg==", + "requires": { + "@colors/colors": "1.5.0", + "async": "3.2.3", + "read": "1.0.x", + "revalidator": "0.1.x", + "winston": "2.x" + } + }, "proxy-addr": { "version": "2.0.7", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", @@ -1539,6 +2025,14 @@ "unpipe": "1.0.0" } }, + "read": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/read/-/read-1.0.7.tgz", + "integrity": "sha512-rSOKNYUmaxy0om1BNjMN4ezNT6VKK+2xF4GBhc81mkH7L60i6dp8qPYrkndNLT3QPphoII3maL9PVC9XmhHwVQ==", + "requires": { + "mute-stream": "~0.0.4" + } + }, "request": { "version": "2.88.2", "resolved": "https://registry.npmjs.org/request/-/request-2.88.2.tgz", @@ -1570,9 +2064,23 @@ "version": "6.5.3", "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.3.tgz", "integrity": "sha512-qxXIEh4pCGfHICj1mAJQ2/2XVZkjCDTcEgfoSQxc/fYivUZxTkk7L3bDBJSoNrEzXI17oUO5Dp07ktqE5KzczA==" + }, + "tough-cookie": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz", + "integrity": "sha512-nlLsUzgm1kfLXSXfRZMc1KLAugd4hqJHDTvc2hDIwS3mZAfMEuMbc03SujMF+GEcpaX/qboeycw6iO8JwVv2+g==", + "requires": { + "psl": "^1.1.28", + "punycode": "^2.1.1" + } } } }, + "revalidator": { + "version": "0.1.8", + "resolved": "https://registry.npmjs.org/revalidator/-/revalidator-0.1.8.tgz", + "integrity": "sha512-xcBILK2pA9oh4SiinPEZfhP8HfrB/ha+a2fTMyl7Om2WjlDVrOQy99N2MXXlUHqGJz4qEu2duXxHJjDWuK/0xg==" + }, "safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", @@ -1657,6 +2165,11 @@ "tweetnacl": "~0.14.0" } }, + "stack-trace": { + "version": "0.0.10", + "resolved": "https://registry.npmjs.org/stack-trace/-/stack-trace-0.0.10.tgz", + "integrity": "sha512-KGzahc7puUKkzyMt+IqAep+TVNbKP+k2Lmwhub39m1AsTSkaDutx56aDCo+HLDzf/D26BIHTJWNiTG1KAJiQCg==" + }, "statuses": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", @@ -1667,15 +2180,6 @@ "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==" }, - "tough-cookie": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz", - "integrity": "sha512-nlLsUzgm1kfLXSXfRZMc1KLAugd4hqJHDTvc2hDIwS3mZAfMEuMbc03SujMF+GEcpaX/qboeycw6iO8JwVv2+g==", - "requires": { - "psl": "^1.1.28", - "punycode": "^2.1.1" - } - }, "tunnel-agent": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", @@ -1736,6 +2240,29 @@ "extsprintf": "^1.2.0" } }, + "winston": { + "version": "2.4.7", + "resolved": "https://registry.npmjs.org/winston/-/winston-2.4.7.tgz", + "integrity": "sha512-vLB4BqzCKDnnZH9PHGoS2ycawueX4HLqENXQitvFHczhgW2vFpSOn31LZtVr1KU8YTw7DS4tM+cqyovxo8taVg==", + "requires": { + "async": "^2.6.4", + "colors": "1.0.x", + "cycle": "1.0.x", + "eyes": "0.1.x", + "isstream": "0.1.x", + "stack-trace": "0.0.x" + }, + "dependencies": { + "async": { + "version": "2.6.4", + "resolved": "https://registry.npmjs.org/async/-/async-2.6.4.tgz", + "integrity": "sha512-mzo5dfJYwAn29PeiJ0zvwTo04zj8HDJj0Mn8TD7sno7q12prdbnasKJHhkm2c1LgrhlJ0teaea8860oxi51mGA==", + "requires": { + "lodash": "^4.17.14" + } + } + } + }, "xml2js": { "version": "0.4.23", "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.23.tgz", @@ -1749,6 +2276,11 @@ "version": "11.0.1", "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz", "integrity": "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==" + }, + "xmldom": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/xmldom/-/xmldom-0.6.0.tgz", + "integrity": "sha512-iAcin401y58LckRZ0TkI4k0VSM1Qg0KGSc3i8rU+xrxe19A/BN1zHyVSJY7uoutVlaTSzYyk/v5AmkewAP7jtg==" } } } diff --git a/package.json b/package.json index 1a3376e..eae2cf9 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,12 @@ { "dependencies": { + "cheerio": "^1.0.0-rc.12", "express": "^4.18.2", + "jquery": "^3.6.4", + "prompt": "^1.3.0", "request": "^2.88.2", - "xml2js": "^0.4.23" + "xml2js": "^0.4.23", + "xmldom": "^0.6.0" }, "scripts": { "push": "node ./utils/push_to_mii.js", diff --git a/server.js b/server.js index 849fc42..3f34ab0 100644 --- a/server.js +++ b/server.js @@ -2,11 +2,12 @@ const express = require('express'); const request = require('request') const bodyParser = require('body-parser'); const fs = require('fs'); + const updateModified = require('./utils/updateModified') const app = express(); -let cookie; const configs = JSON.parse(fs.readFileSync('./configs.json')) -const { getCookie } = require('./utils/getCookie') +const { getCookie,getJar } = require('./utils/getCookie') +let jar; app.use(bodyParser.urlencoded({ extended: true @@ -18,9 +19,11 @@ configureEndPoints(configs.endPoints) app.listen(configs.LocalPort, () => { console.log('listening at port ' + configs.LocalPort) - getCookie().then(_cookie => { - cookie = _cookie + getJar().then(_jar=>{ + jar = _jar console.log("go to this url see the ui5 app", "http://localhost:" + configs.LocalPort + "/index.html") + }).catch((err)=>{ + console.log(err) }) }) @@ -57,11 +60,12 @@ function get_data(query, service) { url: `${configs.server}${service}`, method: 'get', headers: { - 'Cookie': cookie, - 'Content-Type':(query['Content-Type'] === 'text/json')?'application/json':'application/xml' + // 'Cookie': cookie, + 'Content-Type': (query['Content-Type'] === 'text/json') ? 'application/json' : 'application/xml' }, 'json': (query['Content-Type'] === 'text/json') ? true : false, - qs: query + qs: query, + jar:jar }, (error, response, body) => { if (error) { reject(response) @@ -78,11 +82,12 @@ function post_data(query, service) { url: `${configs.server}${service}`, method: 'post', headers: { - 'Cookie': cookie, - 'Content-Type':(query['Content-Type'] === 'text/json')?'application/json':'application/xml' + // 'Cookie': cookie, + 'Content-Type': (query['Content-Type'] === 'text/json') ? 'application/json' : 'application/xml' }, 'json': (query['Content-Type'] === 'text/json') ? true : false, - qs:query + qs: query, + jar:jar }, (error, response, body) => { if (error) { reject(response) diff --git a/utils/getCookie.js b/utils/getCookie.js index e701a93..add877e 100644 --- a/utils/getCookie.js +++ b/utils/getCookie.js @@ -1,82 +1,75 @@ var request = require('request'); const fs = require('fs') -const readline = require('readline'); +const prompt = require('prompt') +const cheerio = require('cheerio'); const configs = JSON.parse(fs.readFileSync('./configs.json')) -const cookiesFilePath = './data/cookies.txt'; -const cookie = fs.readFileSync(cookiesFilePath).toString(); +const jar = request.jar() -const rl = readline.createInterface({ - input: process.stdin, - output: process.stdout, - hideEchoBack: true -}); +async function promptPassword() { + prompt.start() + prompt.message = '' + prompt.delimiter = ':' + const { password } = await prompt.get({ + properties: { + password: { + message: 'Password', + hidden: true, + replace: '*' + } + } + }) + + return password +} // target URL -var options = { +const options = { url: configs.server + '/XMII/Illuminator', method: 'GET', + headers: { + 'Content-Type': 'application/xml' + }, auth: { user: configs.userName, pass: '' - } + }, + jar }; -function isCookieExpired(cookieStr) { - if (cookieStr === "") - return true - - const jar = request.jar(); - const url = new URL(configs.server + '/XMII/Illuminator'); - jar.setCookie(cookieStr, url); - const cookies = jar.getCookies(url); - const curCookie = cookies[0]; - return curCookie && curCookie.expires && new Date(curCookie.expires).getTime() <= Date.now(); -} - -async function getCookie() { - - try { - // Check if current cookie is expired - if (isCookieExpired(cookie)) throw new Error('Expired cookie') - return cookie - } catch (error) { - console.log("Your session to MII server is expired. Please relogin!") +function getJar() { + return new Promise(async (resolve, reject) => { + console.log("Please Login to MII Server") console.log(`MII server: ${configs.server}`); console.log(`User name: ${configs.userName}`); - - const userInput = await new Promise((res, rej) => { - rl.question('Please Enter your password: ', res); - }); - - try { - options.auth.pass = userInput; - const _cookie = await requestCookie(); - fs.writeFileSync(cookiesFilePath, _cookie); - return _cookie; - - } catch (error) { - console.error('Unable to retrieve new cookie:', error); - throw error; // Rethrow error for higher-level error handling + const password = await promptPassword() + if (password) { + options.auth.pass = password + } else { + console.log("Please Enter a valid password") + getJar() } - } -} -function requestCookie() { - return new Promise((resolve, reject) => { - request(options, - (error, response, body) => { - if (!error && (response.statusCode === 200 || response.statusCode === 201)) { - resolve(response.headers['set-cookie'][0]) + request(options, (error, response, body) => { + try { + if (!error && response.statusCode === 200) { + const $ = cheerio.load(body); + if($('.urLogonTable').html() === null){ + resolve(jar) + }else{ + reject("Invalid Credentials. Please relogin") + } + } else { - console.log("error=>", error) reject(error) } - }) + } catch (err) { + reject(err) + } + }) }) } - module.exports = { - getCookie + getJar } diff --git a/utils/pull_from_mii.js b/utils/pull_from_mii.js index 71c4d29..b4afac4 100644 --- a/utils/pull_from_mii.js +++ b/utils/pull_from_mii.js @@ -1,11 +1,11 @@ const fs = require('fs') const request = require('request') const xml2js = require('xml2js'); -const { getCookie } = require('./getCookie') +const { getJar } = require('./getCookie') const configs = JSON.parse(fs.readFileSync('./configs.json')) const parser = new xml2js.Parser({ explicitArray: false }); -let cookie; +let jar; function getFilesList(folderPath, type) { return new Promise((resolve, reject) => { @@ -13,7 +13,7 @@ function getFilesList(folderPath, type) { url: `${configs.server}/XMII/Catalog`, method: 'post', headers: { - cookie: cookie + // cookie: cookie }, qs: { 'Mode': (type === 'folder' ? 'ListFolders' : 'List'), @@ -21,7 +21,8 @@ function getFilesList(folderPath, type) { 'DoStateCheck': true, 'Content-Type': 'text/xml', 'Folder': folderPath - } + }, + jar: jar }, (error, res, body) => { if (error) { console.log("Error while getting the filesList.function:getFilesList, error: " + error) @@ -88,7 +89,7 @@ function readMIIFile(path) { url: `${configs.server}/XMII/Catalog`, method: 'get', headers: { - cookie: cookie + // cookie: cookie }, qs: { Mode: 'LoadBinary', @@ -97,7 +98,8 @@ function readMIIFile(path) { 'Content-Type': 'text/json', ObjectName: path }, - json: true + json: true, + jar: jar }, (err, res, body) => { if (!err && (res.statusCode === 200 || res.statusCode === 201)) { try { @@ -114,8 +116,8 @@ function readMIIFile(path) { }) } -getCookie().then((_cookie) => { - cookie = _cookie +getJar().then((_jar) => { + jar = _jar dfs(configs.miiRootFolder).then(() => { console.log("code pulled from mii and placed all the resources in webapp folder") diff --git a/utils/push_to_mii.js b/utils/push_to_mii.js index d158670..6758541 100644 --- a/utils/push_to_mii.js +++ b/utils/push_to_mii.js @@ -1,17 +1,16 @@ const fs = require('fs'); const request = require('request'); -const { parse_param_str, isFile } = require('./util') const xml2js = require('xml2js'); + const configs = JSON.parse(fs.readFileSync('./configs.json')) const modifiedFiles = JSON.parse(fs.readFileSync('./data/modifiedFiles.json')) -let cookie; -const { getCookie } = require('./getCookie') +const { getJar } = require('./getCookie'); +let jar; async function pushFilestoMII() { - cookie = await getCookie() let failed_files = [] let promiseArray = [] - if(Object.keys(modifiedFiles).length===0){ + if (Object.keys(modifiedFiles).length === 0) { console.log("No new Modifications found!") return } @@ -19,17 +18,17 @@ async function pushFilestoMII() { for (let file of Object.keys(modifiedFiles)) { const promise = new Promise((resolve, reject) => { saveFile(modifiedFiles[file].path, fs.readFileSync(`./webapp/${file}`)).then((res) => { + console.log(res) if (res && !res.FatalError) { - console.log(file) + console.log(modifiedFiles[file].path) delete modifiedFiles[file] - resolve() + resolve("File saved Successfully") } else { failed_files.push(file) - reject() + reject(res.FatalError) } }).catch((err) => { - console.log(err) - reject() + reject(err) }) }) promiseArray.push(promise) @@ -41,51 +40,59 @@ async function pushFilestoMII() { console.log(failed_files) } fs.writeFileSync('./data/modifiedFiles.json', JSON.stringify(modifiedFiles)) - }) + }).catch(err => console.log(err)) } function saveFile(filePath, content) { + return new Promise((resolve, reject) => { const bufferObj = Buffer.from(content, 'utf-8'); - const base64String = bufferObj.toString('base64'); + const base64String = bufferObj.toString('base64') const params = { - 'Mode': 'SaveBinary', - 'Class': 'Content', - 'ObjectName': filePath, - 'Content': encodeURIComponent(base64String) + 'Mode': 'SaveBinary', + 'Class': 'Content', + 'ObjectName': filePath, + 'Content': base64String } const options = { - url: `${configs.server}/XMII/Catalog?${parse_param_str(params)}`, - method: 'POST', - headers: { - 'Cookie': cookie, - 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', - } + url: `${configs.server}/XMII/Catalog`, + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', + }, + qs: params, + jar:jar }; - return new Promise((resolve, reject) => { - request(options, (error, response, body) => { - if (!error && response.statusCode === 200) { + request(options, (error, response, body) => { + if (!error && response.statusCode === 200) { + xml2js.parseString(body, function (err, result) { + if (err) { + reject(err); + } else { + resolve(result) + } + }); - xml2js.parseString(body, function (err, result) { - if (err) { - reject(err); - } else { - resolve(result) - } + } else { + reject(error) + } + }); + }) - }); +} - } else { - reject(response) - } - }); - }) -} +getJar().then(_jar => { + jar = _jar + pushFilestoMII().catch(err => console.log(err)) + +}).catch(err => { + console.log(err) +}) + -pushFilestoMII() From 535ee8cb96e3d1cc45bff2a0beb4039e19e4edb4 Mon Sep 17 00:00:00 2001 From: sp Date: Mon, 13 Mar 2023 18:06:59 +0530 Subject: [PATCH 2/4] fixed the issue with deleted file from local directory --- utils/push_to_mii.js | 8 ++++++-- utils/updateModified.js | 38 ++++++++++++++++++++++++-------------- utils/util.js | 1 - 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/utils/push_to_mii.js b/utils/push_to_mii.js index 6758541..2046996 100644 --- a/utils/push_to_mii.js +++ b/utils/push_to_mii.js @@ -16,6 +16,11 @@ async function pushFilestoMII() { } console.log('Below files are pushed to MII') for (let file of Object.keys(modifiedFiles)) { + if (modifiedFiles[file].status === 'deleted') { + console.log(modifiedFiles[file].path, ", can't push this deleted file in your local directory to mii wb") + delete modifiedFiles[file] + continue; + } const promise = new Promise((resolve, reject) => { saveFile(modifiedFiles[file].path, fs.readFileSync(`./webapp/${file}`)).then((res) => { console.log(res) @@ -43,7 +48,6 @@ async function pushFilestoMII() { }).catch(err => console.log(err)) } - function saveFile(filePath, content) { return new Promise((resolve, reject) => { const bufferObj = Buffer.from(content, 'utf-8'); @@ -62,7 +66,7 @@ function saveFile(filePath, content) { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', }, qs: params, - jar:jar + jar: jar }; request(options, (error, response, body) => { diff --git a/utils/updateModified.js b/utils/updateModified.js index 6ed588f..ce1b9cf 100644 --- a/utils/updateModified.js +++ b/utils/updateModified.js @@ -1,24 +1,34 @@ const fs = require('fs') const mii_root_folder_path = JSON.parse(fs.readFileSync('./configs.json')).miiRootFolder -const {parse_param_str,isFile} = require('./util') +const {isFile } = require('./util') -module.exports = function updateModified(){ +module.exports = function updateModified() { + try { fs.watch('./webapp', { recursive: true }, (eventType, filename) => { - let modifiedFiles = JSON.parse(fs.readFileSync('./data/modifiedFiles.json')) - filename = filename.replaceAll('\\','/') - if (isFile('./webapp/'+filename)) { - if(!modifiedFiles[filename]){ - modifiedFiles[filename] = { - "path":`${mii_root_folder_path}/webapp/${filename}`, - "status":"changed", - "type":"file" - } - }else{ - modifiedFiles[filename].status = "changed" + let modifiedFiles = JSON.parse(fs.readFileSync('./data/modifiedFiles.json')) + filename = filename.replaceAll('\\', '/') + let filePath = './webapp/' + filename + + //checking for file deletion + if (eventType === 'rename' && !fs.existsSync(filePath)) { + modifiedFiles[filename].status = "deleted" + } else if(isFile(filePath)) { + if (!modifiedFiles[filename]) { + modifiedFiles[filename] = { + "path": `${mii_root_folder_path}/webapp/${filename}`, + "status": "changed", + "type": "file" } + } else if(modifiedFiles[filename].status!=="deleted"){ + modifiedFiles[filename].status = "changed" } - fs.writeFileSync('./data/modifiedFiles.json', JSON.stringify(modifiedFiles)) + } + fs.writeFileSync('./data/modifiedFiles.json', JSON.stringify(modifiedFiles)) }); + } catch (err) { + + } + } diff --git a/utils/util.js b/utils/util.js index bdccdc8..eea4ec5 100644 --- a/utils/util.js +++ b/utils/util.js @@ -14,7 +14,6 @@ function isFile(path) { const stats = fs.lstatSync(path) return stats.isDirectory() ? false : true } catch (error) { - console.error(error) return false } } From c75a1d7c8468286669af9368b7bcd733a481526f Mon Sep 17 00:00:00 2001 From: sp Date: Mon, 13 Mar 2023 23:59:46 +0530 Subject: [PATCH 3/4] encryption of cookies code added, but didn't used in the code --- utils/cookiejar.js | 127 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 utils/cookiejar.js diff --git a/utils/cookiejar.js b/utils/cookiejar.js new file mode 100644 index 0000000..4d1ccf1 --- /dev/null +++ b/utils/cookiejar.js @@ -0,0 +1,127 @@ +const request = require('request'); +const {CookieJar } = require('tough-cookie'); +const fs = require('fs'); +const prompt = require('prompt'); +const cheerio = require('cheerio'); +const crypto = require('crypto'); + +const configs = JSON.parse(fs.readFileSync('./configs.json')); + +// Load cookie jar from file if it exists +let jar; + +if (fs.existsSync('./data/cookies.txt')) { + const rawCookies = decryptcookie(fs.readFileSync('./data/cookies.txt', 'utf8'), 'xxxxxx') + jar = CookieJar.fromJSON(rawCookies); +} else { + jar = new CookieJar() +} + +async function promptPassword() { + prompt.start() + prompt.message = '' + prompt.delimiter = ':' + const { password } = await prompt.get({ + properties: { + password: { + message: 'Password', + hidden: true, + replace: '*' + } + } + }) + + return password +} + +// target URL +const options = { + url: configs.server + '/XMII/Illuminator', + method: 'GET', + headers: { + 'Content-Type': 'application/xml' + }, + auth: { + user: configs.userName, + pass: '' + }, + jar +}; + +function getJar() { + return new Promise(async (resolve, reject) => { + let cookies = await jar.getCookies(options.url) + if (!cookies.length) { + console.log("Please Login to MII Server") + console.log(`MII server: ${configs.server}`); + console.log(`User name: ${configs.userName}`); + const password = await promptPassword() + if (password) { + options.auth.pass = password + request(options, (error, response, body) => { + try { + if (!error && response.statusCode === 200) { + const $ = cheerio.load(body); + if ($('.urLogonTable').html() === null) { + // Save cookie jar to file + const serializedCookies = JSON.stringify(jar.toJSON()) + fs.writeFileSync('./data/cookies.txt', encryptcookie(serializedCookies, password)); + resolve(jar); + } else { + // Session expired or invalid credentials + reject("Invalid Credentials or Session Expired. Please relogin") + } + + } else { + reject(error); + } + } catch (err) { + reject(err); + } + }); + } else { + console.log("Please Enter a valid password") + getJar() + } + } else { + console.log(jar) + resolve(jar) + } + }); +} + +function encryptcookie(data, key) { + const algorithm = 'aes-256-cbc'; + if (key.length < 32) { + key += 'abcdefghijklmnopqrstuvwxyz0123456789'.slice(0, 32 - key.length) + } + const iv = key.slice(0, 16) + const cipher = crypto.createCipheriv(algorithm, key, iv); + let encrypted = cipher.update(data, 'utf-8', 'hex'); + encrypted += cipher.final('hex'); + return encrypted + +} + +function decryptcookie(encryptedContent, key) { + if (key.length < 32) { + key += 'abcdefghijklmnopqrstuvwxyz0123456789'.slice(0, 32 - key.length) + } + const algorithm = 'aes-256-cbc' + const iv = key.slice(0, 16) + const decipher = crypto.createDecipheriv(algorithm, key, iv); + + let decryptedText = decipher.update(encryptedContent, 'hex', 'utf8'); + decryptedText += decipher.final(); + //decryptedText = JSON.parse(decryptedText) + return decryptedText; +} + +module.exports = { + getJar +} + + + + + From 2af67c830186d30b2fda590b462b97bdf79b501f Mon Sep 17 00:00:00 2001 From: sp Date: Tue, 14 Mar 2023 00:05:05 +0530 Subject: [PATCH 4/4] cleaned the code --- .gitignore | 2 -- configs.json | 17 +++++++++++++++++ data/modifiedFiles.json | 1 + 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 configs.json create mode 100644 data/modifiedFiles.json diff --git a/.gitignore b/.gitignore index 127ad4b..a347da3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,3 @@ /node_modules /webapp *.log -/configs.json -/data \ No newline at end of file diff --git a/configs.json b/configs.json new file mode 100644 index 0000000..a675c49 --- /dev/null +++ b/configs.json @@ -0,0 +1,17 @@ +{ + "userName":"", + "server":"", + "miiRootFolder":"", + "LocalPort":3000, + "endPoints":{ + "get":[ + "/XMII/Illuminator", + "/XMII/Runner", + "/XMII/PropertyAccessServlet" + ], + "post":[ + "/XMII/Illuminator", + "/XMII/Runner" + ] + } +} diff --git a/data/modifiedFiles.json b/data/modifiedFiles.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/data/modifiedFiles.json @@ -0,0 +1 @@ +{} \ No newline at end of file