diff --git a/.gitignore b/.gitignore index 25d66ac..ea28854 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ node_modules/ dist/ .env -data/ +data/*.json +data/xray-backups/ +!data/.gitkeep diff --git a/data/.gitkeep b/data/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/docker-compose.yml b/docker-compose.yml index 53d5bfc..c9f4b13 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,6 +19,8 @@ services: - XRAY_USERNAME2= - XRAY_PASSWORD2= + ports: + - "3000:3000" networks: - applications extra_hosts: diff --git a/entrypoint.sh b/entrypoint.sh index e991142..208861d 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,13 +1,5 @@ #!/bin/sh set -e -INTERVAL="${PARSE_INTERVAL:-3600}" - -echo "[entrypoint] PARSE_INTERVAL=${INTERVAL}s" - -while true; do - echo "[entrypoint] Запуск парсера..." - npx ts-node src/index.ts - echo "[entrypoint] Следующий запуск через ${INTERVAL} секунд" - sleep "${INTERVAL}" -done +echo "[entrypoint] Starting web server..." +exec npx ts-node src/server.ts diff --git a/package-lock.json b/package-lock.json index 5774f79..ea9fbac 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,10 +8,14 @@ "name": "vpn-parser", "version": "1.0.0", "dependencies": { + "cookie-parser": "^1.4.7", "dotenv": "^16.4.7", + "express": "^5.2.1", "playwright": "^1.51.0" }, "devDependencies": { + "@types/cookie-parser": "^1.4.10", + "@types/express": "^5.0.6", "@types/node": "^22.13.0", "ts-node": "^10.9.2", "typescript": "^5.7.3" @@ -86,6 +90,69 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/body-parser": { + "version": "1.19.6", + "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.6.tgz", + "integrity": "sha512-HLFeCYgz89uk22N5Qg3dvGvsv46B8GLvKKo1zKG4NybA8U2DiEO3w9lqGg29t/tfLRJpJ6iQxnVw4OnB7MoM9g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/connect": "*", + "@types/node": "*" + } + }, + "node_modules/@types/connect": { + "version": "3.4.38", + "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.38.tgz", + "integrity": "sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, + "node_modules/@types/cookie-parser": { + "version": "1.4.10", + "resolved": "https://registry.npmjs.org/@types/cookie-parser/-/cookie-parser-1.4.10.tgz", + "integrity": "sha512-B4xqkqfZ8Wek+rCOeRxsjMS9OgvzebEzzLYw7NHYuvzb7IdxOkI0ZHGgeEBX4PUM7QGVvNSK60T3OvWj3YfBRg==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "@types/express": "*" + } + }, + "node_modules/@types/express": { + "version": "5.0.6", + "resolved": "https://registry.npmjs.org/@types/express/-/express-5.0.6.tgz", + "integrity": "sha512-sKYVuV7Sv9fbPIt/442koC7+IIwK5olP1KWeD88e/idgoJqDm3JV/YUiPwkoKK92ylff2MGxSz1CSjsXelx0YA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/body-parser": "*", + "@types/express-serve-static-core": "^5.0.0", + "@types/serve-static": "^2" + } + }, + "node_modules/@types/express-serve-static-core": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-5.1.1.tgz", + "integrity": "sha512-v4zIMr/cX7/d2BpAEX3KNKL/JrT1s43s96lLvvdTmza1oEvDudCqK9aF/djc/SWgy8Yh0h30TZx5VpzqFCxk5A==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*", + "@types/qs": "*", + "@types/range-parser": "*", + "@types/send": "*" + } + }, + "node_modules/@types/http-errors": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/@types/http-errors/-/http-errors-2.0.5.tgz", + "integrity": "sha512-r8Tayk8HJnX0FztbZN7oVqGccWgw98T/0neJphO91KkmOzug1KkofZURD4UaD5uH8AqcFLfdPErnBod0u71/qg==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/node": { "version": "22.19.19", "resolved": "https://registry.npmjs.org/@types/node/-/node-22.19.19.tgz", @@ -96,6 +163,54 @@ "undici-types": "~6.21.0" } }, + "node_modules/@types/qs": { + "version": "6.15.1", + "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.15.1.tgz", + "integrity": "sha512-GZHUBZR9hckSUhrxmp1nG6NwdpM9fCunJwyThLW1X3AyHgd9IlHb6VANpQQqDr2o/qQp6McZ3y/IA2rVzKzSbw==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/range-parser": { + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.7.tgz", + "integrity": "sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/send": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@types/send/-/send-1.2.1.tgz", + "integrity": "sha512-arsCikDvlU99zl1g69TcAB3mzZPpxgw0UQnaHeC1Nwb015xp8bknZv5rIfri9xTOcMuaVgvabfIRA7PSZVuZIQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, + "node_modules/@types/serve-static": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-2.2.0.tgz", + "integrity": "sha512-8mam4H1NHLtu7nmtalF7eyBH14QyOASmcxHhSfEoRyr0nP/YdoesEtU+uSRvMe96TW/HPTtkoKqQLl53N7UXMQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/http-errors": "*", + "@types/node": "*" + } + }, + "node_modules/accepts": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-2.0.0.tgz", + "integrity": "sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng==", + "license": "MIT", + "dependencies": { + "mime-types": "^3.0.0", + "negotiator": "^1.0.0" + }, + "engines": { + "node": ">= 0.6" + } + }, "node_modules/acorn": { "version": "8.16.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.16.0.tgz", @@ -129,6 +244,118 @@ "dev": true, "license": "MIT" }, + "node_modules/body-parser": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.2.2.tgz", + "integrity": "sha512-oP5VkATKlNwcgvxi0vM0p/D3n2C3EReYVX+DNYs5TjZFn/oQt2j+4sVJtSMr18pdRr8wjTcBl6LoV+FUwzPmNA==", + "license": "MIT", + "dependencies": { + "bytes": "^3.1.2", + "content-type": "^1.0.5", + "debug": "^4.4.3", + "http-errors": "^2.0.0", + "iconv-lite": "^0.7.0", + "on-finished": "^2.4.1", + "qs": "^6.14.1", + "raw-body": "^3.0.1", + "type-is": "^2.0.1" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/bytes": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", + "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/call-bind-apply-helpers": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", + "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/call-bound": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz", + "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "get-intrinsic": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/content-disposition": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-1.1.0.tgz", + "integrity": "sha512-5jRCH9Z/+DRP7rkvY83B+yGIGX96OYdJmzngqnw2SBSxqCFPd0w2km3s5iawpGX8krnwSGmF0FW5Nhr0Hfai3g==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/content-type": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", + "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz", + "integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie-parser": { + "version": "1.4.7", + "resolved": "https://registry.npmjs.org/cookie-parser/-/cookie-parser-1.4.7.tgz", + "integrity": "sha512-nGUvgXnotP3BsjiLX2ypbQnWoGUPIIfHQNZkkC668ntrzGWEZVW70HDEB1qnNGMicPje6EttlIgzo51YSwNQGw==", + "license": "MIT", + "dependencies": { + "cookie": "0.7.2", + "cookie-signature": "1.0.6" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/cookie-signature": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", + "integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==", + "license": "MIT" + }, "node_modules/create-require": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", @@ -136,6 +363,32 @@ "dev": true, "license": "MIT" }, + "node_modules/debug": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", + "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/depd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, "node_modules/diff": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.4.tgz", @@ -158,6 +411,171 @@ "url": "https://dotenvx.com" } }, + "node_modules/dunder-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", + "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.1", + "es-errors": "^1.3.0", + "gopd": "^1.2.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==", + "license": "MIT" + }, + "node_modules/encodeurl": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz", + "integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/es-define-property": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-object-atoms": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz", + "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==", + "license": "MIT" + }, + "node_modules/etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/express": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/express/-/express-5.2.1.tgz", + "integrity": "sha512-hIS4idWWai69NezIdRt2xFVofaF4j+6INOpJlVOLDO8zXGpUVEVzIYk12UUi2JzjEzWL3IOAxcTubgz9Po0yXw==", + "license": "MIT", + "dependencies": { + "accepts": "^2.0.0", + "body-parser": "^2.2.1", + "content-disposition": "^1.0.0", + "content-type": "^1.0.5", + "cookie": "^0.7.1", + "cookie-signature": "^1.2.1", + "debug": "^4.4.0", + "depd": "^2.0.0", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "etag": "^1.8.1", + "finalhandler": "^2.1.0", + "fresh": "^2.0.0", + "http-errors": "^2.0.0", + "merge-descriptors": "^2.0.0", + "mime-types": "^3.0.0", + "on-finished": "^2.4.1", + "once": "^1.4.0", + "parseurl": "^1.3.3", + "proxy-addr": "^2.0.7", + "qs": "^6.14.0", + "range-parser": "^1.2.1", + "router": "^2.2.0", + "send": "^1.1.0", + "serve-static": "^2.2.0", + "statuses": "^2.0.1", + "type-is": "^2.0.1", + "vary": "^1.1.2" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/express/node_modules/cookie-signature": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.2.2.tgz", + "integrity": "sha512-D76uU73ulSXrD1UXF4KE2TMxVVwhsnCgfAyTg9k8P6KGZjlXKrOLe4dJQKI3Bxi5wjesZoFXJWElNWBjPZMbhg==", + "license": "MIT", + "engines": { + "node": ">=6.6.0" + } + }, + "node_modules/finalhandler": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-2.1.1.tgz", + "integrity": "sha512-S8KoZgRZN+a5rNwqTxlZZePjT/4cnm0ROV70LedRHZ0p8u9fRID0hJUZQpkKLzro8LfmC8sx23bY6tVNxv8pQA==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.0", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "on-finished": "^2.4.1", + "parseurl": "^1.3.3", + "statuses": "^2.0.1" + }, + "engines": { + "node": ">= 18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/forwarded": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", + "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/fresh": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-2.0.0.tgz", + "integrity": "sha512-Rx/WycZ60HOaqLKAi6cHRKKI7zxWbJ31MhntmtwMoaTeF7XFH9hhBp8vITaMidfljRQ6eYWCKkaTK+ykVJHP2A==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, "node_modules/fsevents": { "version": "2.3.2", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", @@ -172,6 +590,145 @@ "node": "^8.16.0 || ^10.6.0 || >=11.0.0" } }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-intrinsic": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", + "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "es-define-property": "^1.0.1", + "es-errors": "^1.3.0", + "es-object-atoms": "^1.1.1", + "function-bind": "^1.1.2", + "get-proto": "^1.0.1", + "gopd": "^1.2.0", + "has-symbols": "^1.1.0", + "hasown": "^2.0.2", + "math-intrinsics": "^1.1.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", + "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", + "license": "MIT", + "dependencies": { + "dunder-proto": "^1.0.1", + "es-object-atoms": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/gopd": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-symbols": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", + "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hasown": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.3.tgz", + "integrity": "sha512-ej4AhfhfL2Q2zpMmLo7U1Uv9+PyhIZpgQLGT1F9miIGmiCJIoCgSmczFdrc97mWT4kVY72KA+WnnhJ5pghSvSg==", + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/http-errors": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz", + "integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==", + "license": "MIT", + "dependencies": { + "depd": "~2.0.0", + "inherits": "~2.0.4", + "setprototypeof": "~1.2.0", + "statuses": "~2.0.2", + "toidentifier": "~1.0.1" + }, + "engines": { + "node": ">= 0.8" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/iconv-lite": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.7.2.tgz", + "integrity": "sha512-im9DjEDQ55s9fL4EYzOAv0yMqmMBSZp6G0VvFyTMPKWxiSBHUj9NW/qqLmXUwXrrM7AvqSlTCfvqRb0cM8yYqw==", + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "license": "ISC" + }, + "node_modules/ipaddr.js": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", + "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", + "license": "MIT", + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/is-promise": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-4.0.0.tgz", + "integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==", + "license": "MIT" + }, "node_modules/make-error": { "version": "1.3.6", "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", @@ -179,6 +736,128 @@ "dev": true, "license": "ISC" }, + "node_modules/math-intrinsics": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", + "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/media-typer": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-1.1.0.tgz", + "integrity": "sha512-aisnrDP4GNe06UcKFnV5bfMNPBUw4jsLGaWwWfnH3v02GnBuXX2MCVn5RbrWo0j3pczUilYblq7fQ7Nw2t5XKw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/merge-descriptors": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-2.0.0.tgz", + "integrity": "sha512-Snk314V5ayFLhp3fkUREub6WtjBfPdCPY1Ln8/8munuLuiYhsABgBVWsozAG+MWMbVEvcdcpbi9R7ww22l9Q3g==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/mime-db": { + "version": "1.54.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.54.0.tgz", + "integrity": "sha512-aU5EJuIN2WDemCcAp2vFBfp/m4EAhWJnUNSSw0ixs7/kXbd6Pg64EmwJkNdFhB8aWt1sH2CTXrLxo/iAGV3oPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-3.0.2.tgz", + "integrity": "sha512-Lbgzdk0h4juoQ9fCKXW4by0UJqj+nOOrI9MJ1sSj4nI8aI2eo1qmvQEie4VD1glsS250n15LsWsYtCugiStS5A==", + "license": "MIT", + "dependencies": { + "mime-db": "^1.54.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/negotiator": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.0.0.tgz", + "integrity": "sha512-8Ofs/AUQh8MaEcrlq5xOX0CQ9ypTF5dl78mjlMNfOK08fzpgTHQRQPBxcPlEtIw0yRpws+Zo/3r+5WRby7u3Gg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/object-inspect": { + "version": "1.13.4", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", + "integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/on-finished": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", + "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", + "license": "MIT", + "dependencies": { + "ee-first": "1.1.1" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "license": "ISC", + "dependencies": { + "wrappy": "1" + } + }, + "node_modules/parseurl": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/path-to-regexp": { + "version": "8.4.2", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.4.2.tgz", + "integrity": "sha512-qRcuIdP69NPm4qbACK+aDogI5CBDMi1jKe0ry5rSQJz8JVLsC7jV8XpiJjGRLLol3N+R5ihGYcrPLTno6pAdBA==", + "license": "MIT", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, "node_modules/playwright": { "version": "1.60.0", "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.60.0.tgz", @@ -209,6 +888,221 @@ "node": ">=18" } }, + "node_modules/proxy-addr": { + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", + "integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==", + "license": "MIT", + "dependencies": { + "forwarded": "0.2.0", + "ipaddr.js": "1.9.1" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/qs": { + "version": "6.15.2", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.15.2.tgz", + "integrity": "sha512-Rzq0KEyX/w/tEybncDgdkZrJgVUsUMk3xjh3t5bv3S1HTAtg+uOYt72+ZfwiQwKdysThkTBdL/rTi6HDmX9Ddw==", + "license": "BSD-3-Clause", + "dependencies": { + "side-channel": "^1.1.0" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/range-parser": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", + "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/raw-body": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-3.0.2.tgz", + "integrity": "sha512-K5zQjDllxWkf7Z5xJdV0/B0WTNqx6vxG70zJE4N0kBs4LovmEYWJzQGxC9bS9RAKu3bgM40lrd5zoLJ12MQ5BA==", + "license": "MIT", + "dependencies": { + "bytes": "~3.1.2", + "http-errors": "~2.0.1", + "iconv-lite": "~0.7.0", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/router": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/router/-/router-2.2.0.tgz", + "integrity": "sha512-nLTrUKm2UyiL7rlhapu/Zl45FwNgkZGaCpZbIHajDYgwlJCOzLSk+cIPAnsEqV955GjILJnKbdQC1nVPz+gAYQ==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.0", + "depd": "^2.0.0", + "is-promise": "^4.0.0", + "parseurl": "^1.3.3", + "path-to-regexp": "^8.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "license": "MIT" + }, + "node_modules/send": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/send/-/send-1.2.1.tgz", + "integrity": "sha512-1gnZf7DFcoIcajTjTwjwuDjzuz4PPcY2StKPlsGAQ1+YH20IRVrBaXSWmdjowTJ6u8Rc01PoYOGHXfP1mYcZNQ==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.3", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "etag": "^1.8.1", + "fresh": "^2.0.0", + "http-errors": "^2.0.1", + "mime-types": "^3.0.2", + "ms": "^2.1.3", + "on-finished": "^2.4.1", + "range-parser": "^1.2.1", + "statuses": "^2.0.2" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/serve-static": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-2.2.1.tgz", + "integrity": "sha512-xRXBn0pPqQTVQiC8wyQrKs2MOlX24zQ0POGaj0kultvoOCstBQM5yvOhAVSUwOMjQtTvsPWoNCHfPGwaaQJhTw==", + "license": "MIT", + "dependencies": { + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "parseurl": "^1.3.3", + "send": "^1.2.0" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/setprototypeof": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", + "license": "ISC" + }, + "node_modules/side-channel": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz", + "integrity": "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.3", + "side-channel-list": "^1.0.0", + "side-channel-map": "^1.0.1", + "side-channel-weakmap": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-list": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.1.tgz", + "integrity": "sha512-mjn/0bi/oUURjc5Xl7IaWi/OJJJumuoJFQJfDDyO46+hBWsfaVM65TBHq2eoZBhzl9EchxOijpkbRC8SVBQU0w==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.4" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-map": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz", + "integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-weakmap": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz", + "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3", + "side-channel-map": "^1.0.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/statuses": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz", + "integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/toidentifier": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", + "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", + "license": "MIT", + "engines": { + "node": ">=0.6" + } + }, "node_modules/ts-node": { "version": "10.9.2", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz", @@ -253,6 +1147,37 @@ } } }, + "node_modules/type-is": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-2.1.0.tgz", + "integrity": "sha512-faYHw0anBbc/kWF3zFTEnxSFOAGUX9GFbOBthvDdLsIlEoWOFOtS0zgCiQYwIskL9iGXZL3kAXD8OoZ4GmMATA==", + "license": "MIT", + "dependencies": { + "content-type": "^2.0.0", + "media-typer": "^1.1.0", + "mime-types": "^3.0.0" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/type-is/node_modules/content-type": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-2.0.0.tgz", + "integrity": "sha512-j/O/d7GcZCyNl7/hwZAb606rzqkyvaDctLmckbxLzHvFBzTJHuGEdodATcP3yIRoDrLHkIATJuvzbFlp/ki2cQ==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, "node_modules/typescript": { "version": "5.9.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", @@ -274,6 +1199,15 @@ "dev": true, "license": "MIT" }, + "node_modules/unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, "node_modules/v8-compile-cache-lib": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", @@ -281,6 +1215,21 @@ "dev": true, "license": "MIT" }, + "node_modules/vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "license": "ISC" + }, "node_modules/yn": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", diff --git a/package.json b/package.json index 0e07c2f..fccc033 100644 --- a/package.json +++ b/package.json @@ -3,15 +3,20 @@ "version": "1.0.0", "private": true, "scripts": { - "start": "ts-node src/index.ts", + "start": "ts-node src/server.ts", + "start:cli": "ts-node src/index.ts", "build": "tsc", "typecheck": "tsc --noEmit" }, "dependencies": { + "cookie-parser": "^1.4.7", "dotenv": "^16.4.7", + "express": "^5.2.1", "playwright": "^1.51.0" }, "devDependencies": { + "@types/cookie-parser": "^1.4.10", + "@types/express": "^5.0.6", "@types/node": "^22.13.0", "ts-node": "^10.9.2", "typescript": "^5.7.3" diff --git a/public/app.js b/public/app.js new file mode 100644 index 0000000..0057200 --- /dev/null +++ b/public/app.js @@ -0,0 +1,206 @@ +const $ = (sel) => document.querySelector(sel); + +const loginScreen = $("#login-screen"); +const dashboardScreen = $("#dashboard-screen"); +const loginForm = $("#login-form"); +const loginError = $("#login-error"); +const logoutBtn = $("#logout-btn"); +const novavpsUrlInput = $("#novavps-url"); +const saveConfigBtn = $("#save-config-btn"); +const configMsg = $("#config-msg"); +const runBtn = $("#run-btn"); +const runMsg = $("#run-msg"); +const runningIndicator = $("#running-indicator"); +const currentStep = $("#current-step"); +const lastRunEl = $("#last-run"); + +const POLL_INTERVAL = 10000; + +let pollTimer = null; + +function showScreen(screen) { + loginScreen.classList.add("hidden"); + dashboardScreen.classList.add("hidden"); + screen.classList.remove("hidden"); +} + +function formatTime(iso) { + if (!iso) return ""; + const d = new Date(iso); + return d.toLocaleString(); +} + +function updatePanelStatus(prefix, data) { + const badge = $(`#${prefix}-status`); + const detail = $(`#${prefix}-detail`); + const time = $(`#${prefix}-time`); + + badge.textContent = data.status; + badge.className = "status-badge " + data.status; + + let detailText = ""; + if (prefix === "novavps" && data.count != null) { + detailText = `${data.count} connections`; + } else if (data.outboundsCount != null) { + detailText = `${data.outboundsCount} outbounds`; + if (data.synced) detailText += " (synced)"; + } + if (data.error) detailText += (detailText ? " | " : "") + data.error; + detail.textContent = detailText; + time.textContent = formatTime(data.timestamp); +} + +async function fetchStatus() { + try { + const res = await fetch("/api/status"); + if (res.status === 401) { + showScreen(loginScreen); + stopPolling(); + return; + } + const data = await res.json(); + + const isRunning = data.status === "running"; + runBtn.disabled = isRunning; + runningIndicator.classList.toggle("hidden", !isRunning); + + const stepLabels = { + initializing: "Initializing...", + novavps_fetching: "Fetching Novavps data...", + xray1_parsing: "Parsing Xray 1...", + xray1_syncing: "Syncing Xray 1...", + xray2_parsing: "Parsing Xray 2...", + xray2_syncing: "Syncing Xray 2...", + done: "Completed", + novavps_url_missing: "Error: NOVAVPS URL not set", + no_xray_panels: "Error: No Xray panels configured", + fatal: "Fatal error", + }; + currentStep.textContent = stepLabels[data.currentStep] || data.currentStep; + + updatePanelStatus("novavps", data.novavps); + updatePanelStatus("xray1", data.xray1); + updatePanelStatus("xray2", data.xray2); + + lastRunEl.textContent = data.lastRun ? formatTime(data.lastRun) : "Never"; + } catch (err) { + console.error("Status fetch error:", err); + } +} + +async function fetchConfig() { + try { + const res = await fetch("/api/config"); + if (res.status === 401) { + showScreen(loginScreen); + stopPolling(); + return; + } + const data = await res.json(); + novavpsUrlInput.value = data.novavpsUrl || ""; + } catch (err) { + console.error("Config fetch error:", err); + } +} + +function startPolling() { + fetchStatus(); + fetchConfig(); + if (pollTimer) clearInterval(pollTimer); + pollTimer = setInterval(fetchStatus, POLL_INTERVAL); +} + +function stopPolling() { + if (pollTimer) { + clearInterval(pollTimer); + pollTimer = null; + } +} + +function showMsg(el, text, type) { + el.textContent = text; + el.className = "msg " + type; + el.classList.remove("hidden"); + setTimeout(() => el.classList.add("hidden"), 5000); +} + +loginForm.addEventListener("submit", async (e) => { + e.preventDefault(); + loginError.classList.add("hidden"); + + const username = $("#username").value; + const password = $("#password").value; + + try { + const res = await fetch("/api/login", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ username, password }), + }); + const data = await res.json(); + if (!res.ok) { + loginError.textContent = data.error || "Login failed"; + loginError.classList.remove("hidden"); + return; + } + showScreen(dashboardScreen); + startPolling(); + } catch (err) { + loginError.textContent = "Network error"; + loginError.classList.remove("hidden"); + } +}); + +logoutBtn.addEventListener("click", async () => { + try { + await fetch("/api/logout", { method: "POST" }); + } catch {} + stopPolling(); + showScreen(loginScreen); +}); + +saveConfigBtn.addEventListener("click", async () => { + try { + const res = await fetch("/api/config", { + method: "PUT", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ novavpsUrl: novavpsUrlInput.value }), + }); + const data = await res.json(); + if (!res.ok) { + showMsg(configMsg, data.error || "Save failed", "error"); + return; + } + showMsg(configMsg, "Saved", "success"); + } catch (err) { + showMsg(configMsg, "Network error", "error"); + } +}); + +runBtn.addEventListener("click", async () => { + runMsg.classList.add("hidden"); + try { + const res = await fetch("/api/run", { method: "POST" }); + const data = await res.json(); + if (!res.ok) { + showMsg(runMsg, data.error || "Failed to start", "error"); + return; + } + showMsg(runMsg, "Parser started", "success"); + fetchStatus(); + } catch (err) { + showMsg(runMsg, "Network error", "error"); + } +}); + +// Check if already logged in +fetch("/api/status") + .then((res) => { + if (res.ok) { + showScreen(dashboardScreen); + startPolling(); + } else { + showScreen(loginScreen); + } + }) + .catch(() => showScreen(loginScreen)); diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..6eb5420 --- /dev/null +++ b/public/index.html @@ -0,0 +1,90 @@ + + + + + + VPN Parser + + + +
+
+ +
+ + +
+ + + + diff --git a/public/style.css b/public/style.css new file mode 100644 index 0000000..3f98157 --- /dev/null +++ b/public/style.css @@ -0,0 +1,298 @@ +* { + margin: 0; + padding: 0; + box-sizing: border-box; +} + +body { + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; + background: #0f1117; + color: #e1e4e8; + min-height: 100vh; +} + +.screen { + min-height: 100vh; +} + +.hidden { + display: none !important; +} + +/* Login */ +#login-screen { + display: flex; + align-items: center; + justify-content: center; +} + +.login-box { + background: #161b22; + padding: 2rem; + border-radius: 12px; + width: 100%; + max-width: 360px; + border: 1px solid #30363d; +} + +.login-box h1 { + text-align: center; + margin-bottom: 1.5rem; + font-size: 1.5rem; +} + +.form-group { + margin-bottom: 1rem; +} + +.form-group label { + display: block; + margin-bottom: 0.4rem; + font-size: 0.875rem; + color: #8b949e; +} + +.form-group input { + width: 100%; + padding: 0.6rem 0.8rem; + background: #0d1117; + border: 1px solid #30363d; + border-radius: 6px; + color: #e1e4e8; + font-size: 1rem; +} + +.form-group input:focus { + outline: none; + border-color: #58a6ff; +} + +.login-box button { + width: 100%; + padding: 0.7rem; + background: #238636; + color: #fff; + border: none; + border-radius: 6px; + font-size: 1rem; + cursor: pointer; + margin-top: 0.5rem; +} + +.login-box button:hover { + background: #2ea043; +} + +.error { + color: #f85149; + font-size: 0.875rem; + margin-top: 0.75rem; + text-align: center; +} + +/* Dashboard */ +header { + display: flex; + justify-content: space-between; + align-items: center; + padding: 1rem 2rem; + background: #161b22; + border-bottom: 1px solid #30363d; +} + +header h1 { + font-size: 1.25rem; +} + +#logout-btn { + padding: 0.5rem 1rem; + background: transparent; + border: 1px solid #30363d; + border-radius: 6px; + color: #8b949e; + cursor: pointer; +} + +#logout-btn:hover { + border-color: #f85149; + color: #f85149; +} + +main { + padding: 2rem; + max-width: 900px; + margin: 0 auto; +} + +section { + margin-bottom: 2rem; +} + +section h2 { + font-size: 1rem; + color: #8b949e; + margin-bottom: 1rem; + text-transform: uppercase; + letter-spacing: 0.05em; +} + +/* Config */ +.config-row { + display: flex; + gap: 0.75rem; + align-items: center; +} + +.config-row label { + font-size: 0.875rem; + color: #8b949e; + white-space: nowrap; +} + +.config-row input { + flex: 1; + padding: 0.5rem 0.75rem; + background: #0d1117; + border: 1px solid #30363d; + border-radius: 6px; + color: #e1e4e8; + font-size: 0.875rem; +} + +.config-row input:focus { + outline: none; + border-color: #58a6ff; +} + +.config-row button { + padding: 0.5rem 1rem; + background: #1f6feb; + color: #fff; + border: none; + border-radius: 6px; + cursor: pointer; + white-space: nowrap; +} + +.config-row button:hover { + background: #388bfd; +} + +/* Actions */ +#run-btn { + padding: 0.75rem 1.5rem; + background: #238636; + color: #fff; + border: none; + border-radius: 6px; + font-size: 1rem; + cursor: pointer; +} + +#run-btn:hover:not(:disabled) { + background: #2ea043; +} + +#run-btn:disabled { + opacity: 0.5; + cursor: not-allowed; +} + +.msg { + margin-top: 0.5rem; + font-size: 0.875rem; +} + +.msg.success { + color: #3fb950; +} + +.msg.error { + color: #f85149; +} + +/* Running indicator */ +.running-indicator { + display: flex; + align-items: center; + gap: 0.75rem; + padding: 1rem; + background: #161b22; + border: 1px solid #30363d; + border-radius: 8px; +} + +.spinner { + width: 20px; + height: 20px; + border: 2px solid #30363d; + border-top-color: #58a6ff; + border-radius: 50%; + animation: spin 0.8s linear infinite; +} + +@keyframes spin { + to { transform: rotate(360deg); } +} + +/* Status grid */ +.status-grid { + display: grid; + grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); + gap: 1rem; +} + +.status-card { + background: #161b22; + border: 1px solid #30363d; + border-radius: 8px; + padding: 1rem; +} + +.status-card h3 { + font-size: 0.875rem; + color: #8b949e; + margin-bottom: 0.75rem; +} + +.status-badge { + display: inline-block; + padding: 0.25rem 0.5rem; + border-radius: 4px; + font-size: 0.75rem; + font-weight: 600; + text-transform: uppercase; + margin-bottom: 0.5rem; +} + +.status-badge.idle { + background: #30363d; + color: #8b949e; +} + +.status-badge.success { + background: #122d1a; + color: #3fb950; +} + +.status-badge.error { + background: #2d1215; + color: #f85149; +} + +.status-detail { + font-size: 0.875rem; + color: #c9d1d9; + margin-bottom: 0.25rem; +} + +.status-time { + font-size: 0.75rem; + color: #484f58; +} + +/* Last run */ +#last-run { + font-size: 0.875rem; + color: #c9d1d9; +} diff --git a/src/data-store.ts b/src/data-store.ts new file mode 100644 index 0000000..d5a511b --- /dev/null +++ b/src/data-store.ts @@ -0,0 +1,97 @@ +import path from "path"; +import fs from "fs/promises"; +import { existsSync } from "fs"; + +const DATA_DIR = path.resolve(__dirname, "..", "data"); + +export interface AppConfig { + novavpsUrl: string; +} + +export interface PanelStatus { + status: "idle" | "success" | "error"; + count?: number; + outboundsCount?: number; + synced?: boolean; + timestamp: string | null; + error: string | null; +} + +export interface AppState { + lastRun: string | null; + status: "idle" | "running" | "completed" | "error"; + currentStep: string; + novavps: PanelStatus; + xray1: PanelStatus; + xray2: PanelStatus; +} + +const CONFIG_FILE = path.join(DATA_DIR, "config.json"); +const STATE_FILE = path.join(DATA_DIR, "state.json"); + +const defaultConfig: AppConfig = { + novavpsUrl: "", +}; + +const defaultState: AppState = { + lastRun: null, + status: "idle", + currentStep: "", + novavps: { status: "idle", count: 0, timestamp: null, error: null }, + xray1: { status: "idle", outboundsCount: 0, synced: false, timestamp: null, error: null }, + xray2: { status: "idle", outboundsCount: 0, synced: false, timestamp: null, error: null }, +}; + +async function ensureDataDir(): Promise { + await fs.mkdir(DATA_DIR, { recursive: true }); +} + +async function readJson(filePath: string, defaults: T): Promise { + if (!existsSync(filePath)) return defaults; + try { + const raw = await fs.readFile(filePath, "utf-8"); + return JSON.parse(raw) as T; + } catch { + return defaults; + } +} + +async function writeJson(filePath: string, data: T): Promise { + await ensureDataDir(); + await fs.writeFile(filePath, JSON.stringify(data, null, 2), "utf-8"); +} + +export async function loadConfig(envNovavpsUrl: string): Promise { + const saved = await readJson(CONFIG_FILE, defaultConfig); + if (!saved.novavpsUrl && envNovavpsUrl) { + saved.novavpsUrl = envNovavpsUrl; + await writeJson(CONFIG_FILE, saved); + } + return saved; +} + +export async function saveConfig(config: AppConfig): Promise { + await writeJson(CONFIG_FILE, config); +} + +export async function loadState(): Promise { + return readJson(STATE_FILE, defaultState); +} + +export async function saveState(state: AppState): Promise { + await writeJson(STATE_FILE, state); +} + +export async function resetState(): Promise { + const now = new Date().toISOString(); + const state: AppState = { + lastRun: now, + status: "running", + currentStep: "initializing", + novavps: { status: "idle", count: 0, timestamp: null, error: null }, + xray1: { status: "idle", outboundsCount: 0, synced: false, timestamp: null, error: null }, + xray2: { status: "idle", outboundsCount: 0, synced: false, timestamp: null, error: null }, + }; + await saveState(state); + return state; +} diff --git a/src/server.ts b/src/server.ts new file mode 100644 index 0000000..2f32a98 --- /dev/null +++ b/src/server.ts @@ -0,0 +1,316 @@ +import dotenv from "dotenv"; +dotenv.config(); + +import express, { Request, Response, NextFunction } from "express"; +import cookieParser from "cookie-parser"; +import crypto from "crypto"; +import path from "path"; +import fs from "fs/promises"; + +import { parseNovavps, getValidConnections } from "./novavps"; +import { parseXrayPanel, syncNovavpsToXray } from "./xray-panel"; +import { closeBrowser } from "./browser"; +import { + loadConfig, + saveConfig, + loadState, + saveState, + resetState, + AppState, +} from "./data-store"; + +const app = express(); +const PORT = parseInt(process.env.PORT || "3000", 10); + +const SESSION_SECRET = process.env.SESSION_SECRET || crypto.randomBytes(32).toString("hex"); +const SESSION_TTL = 60 * 60 * 1000; // 1 hour + +const sessions = new Map(); + +app.use(express.json({ limit: "1mb" })); +app.use(cookieParser()); +app.use(express.static(path.resolve(__dirname, "..", "public"))); + +interface PanelConfig { + url: string; + username: string; + password: string; + label: string; +} + +function getPanels(): PanelConfig[] { + const panels: PanelConfig[] = []; + const url1 = process.env.XRAY_URL; + const user1 = process.env.XRAY_USERNAME; + const pass1 = process.env.XRAY_PASSWORD; + if (url1 && user1 && pass1) { + panels.push({ url: url1, username: user1, password: pass1, label: "xray1" }); + } + const url2 = process.env.XRAY_URL2; + const user2 = process.env.XRAY_USERNAME2; + const pass2 = process.env.XRAY_PASSWORD2; + if (url2 && user2 && pass2) { + panels.push({ url: url2, username: user2, password: pass2, label: "xray2" }); + } + return panels; +} + +function validCredentials(username: string, password: string): boolean { + const panels = getPanels(); + return panels.some( + (p) => p.username === username && p.password === password + ); +} + +function createSession(): string { + const token = crypto.randomBytes(32).toString("hex"); + const now = Date.now(); + sessions.set(token, { createdAt: now, lastAccess: now }); + return token; +} + +function getSession(token: string | undefined): { createdAt: number; lastAccess: number } | null { + if (!token) return null; + const session = sessions.get(token); + if (!session) return null; + if (Date.now() - session.lastAccess > SESSION_TTL) { + sessions.delete(token); + return null; + } + session.lastAccess = Date.now(); + return session; +} + +function authMiddleware(req: Request, res: Response, next: NextFunction) { + const token = req.cookies?.session; + if (!getSession(token)) { + res.status(401).json({ error: "Unauthorized" }); + return; + } + next(); +} + +function cleanupSessions() { + const now = Date.now(); + for (const [token, session] of sessions.entries()) { + if (now - session.lastAccess > SESSION_TTL) { + sessions.delete(token); + } + } +} +setInterval(cleanupSessions, 5 * 60 * 1000); + +let isRunning = false; + +async function runParser(): Promise { + if (isRunning) return; + isRunning = true; + + const state = await resetState(); + + try { + const config = await loadConfig(process.env.NOVAVPS_URL || ""); + const novavpsUrl = config.novavpsUrl; + + if (!novavpsUrl) { + state.status = "error"; + state.currentStep = "novavps_url_missing"; + await saveState(state); + return; + } + + const panels = getPanels(); + if (panels.length === 0) { + state.status = "error"; + state.currentStep = "no_xray_panels"; + await saveState(state); + return; + } + + state.currentStep = "novavps_fetching"; + await saveState(state); + + let novavpsConnections: Awaited> = []; + try { + novavpsConnections = await parseNovavps(novavpsUrl); + state.novavps = { + status: "success", + count: novavpsConnections.length, + timestamp: new Date().toISOString(), + error: null, + }; + } catch (err) { + state.novavps = { + status: "error", + count: 0, + timestamp: new Date().toISOString(), + error: err instanceof Error ? err.message : String(err), + }; + } + await saveState(state); + + const valid = getValidConnections(novavpsConnections); + + for (const panel of panels) { + state.currentStep = `${panel.label}_parsing`; + await saveState(state); + + try { + const xray = await parseXrayPanel(panel.url, panel.username, panel.password); + if (panel.label === "xray1") { + state.xray1 = { + status: "success", + outboundsCount: xray.length, + synced: false, + timestamp: new Date().toISOString(), + error: null, + }; + } else { + state.xray2 = { + status: "success", + outboundsCount: xray.length, + synced: false, + timestamp: new Date().toISOString(), + error: null, + }; + } + } catch (err) { + const errorState = { + status: "error" as const, + outboundsCount: 0, + synced: false, + timestamp: new Date().toISOString(), + error: err instanceof Error ? err.message : String(err), + }; + if (panel.label === "xray1") { + state.xray1 = errorState; + } else { + state.xray2 = errorState; + } + } + await saveState(state); + + if (valid.length > 0) { + state.currentStep = `${panel.label}_syncing`; + await saveState(state); + + try { + await syncNovavpsToXray(valid, panel.url, panel.username, panel.password, panel.label); + if (panel.label === "xray1") { + state.xray1.synced = true; + } else { + state.xray2.synced = true; + } + } catch (err) { + const errMsg = err instanceof Error ? err.message : String(err); + if (panel.label === "xray1") { + state.xray1.error = errMsg; + } else { + state.xray2.error = errMsg; + } + } + await saveState(state); + } + } + + state.status = "completed"; + state.currentStep = "done"; + await saveState(state); + } catch (err) { + state.status = "error"; + state.currentStep = "fatal"; + if (state.novavps.status === "idle") { + state.novavps = { status: "error", count: 0, timestamp: new Date().toISOString(), error: err instanceof Error ? err.message : String(err) }; + } + await saveState(state); + } finally { + await closeBrowser(); + isRunning = false; + } +} + +app.post("/api/login", async (req: Request, res: Response) => { + const { username, password } = req.body; + if (!username || !password) { + res.status(400).json({ error: "username and password required" }); + return; + } + if (!validCredentials(username, password)) { + res.status(401).json({ error: "Invalid credentials" }); + return; + } + const token = createSession(); + res.cookie("session", token, { + httpOnly: true, + sameSite: "strict", + maxAge: SESSION_TTL, + path: "/", + }); + res.json({ ok: true }); +}); + +app.post("/api/logout", (_req: Request, res: Response) => { + res.clearCookie("session"); + res.json({ ok: true }); +}); + +app.get("/api/status", authMiddleware, async (_req: Request, res: Response) => { + const state = await loadState(); + res.json(state); +}); + +app.post("/api/run", authMiddleware, async (_req: Request, res: Response) => { + if (isRunning) { + res.status(409).json({ error: "Parser already running" }); + return; + } + runParser().catch((err) => console.error("[server] Parser error:", err)); + res.json({ ok: true, message: "Parser started" }); +}); + +app.get("/api/config", authMiddleware, async (_req: Request, res: Response) => { + const config = await loadConfig(process.env.NOVAVPS_URL || ""); + res.json(config); +}); + +app.put("/api/config", authMiddleware, async (req: Request, res: Response) => { + const { novavpsUrl } = req.body; + if (!novavpsUrl) { + res.status(400).json({ error: "novavpsUrl required" }); + return; + } + const config = await loadConfig(process.env.NOVAVPS_URL || ""); + config.novavpsUrl = novavpsUrl; + await saveConfig(config); + res.json({ ok: true }); +}); + +app.get("/api/data/novavps", authMiddleware, async (_req: Request, res: Response) => { + const filePath = path.resolve(__dirname, "..", "data", "novavps-connections.json"); + try { + const raw = await fs.readFile(filePath, "utf-8"); + res.json(JSON.parse(raw)); + } catch { + res.json([]); + } +}); + +app.get("/api/data/xray", authMiddleware, async (_req: Request, res: Response) => { + const filePath = path.resolve(__dirname, "..", "data", "xray-outbounds.json"); + try { + const raw = await fs.readFile(filePath, "utf-8"); + res.json(JSON.parse(raw)); + } catch { + res.json([]); + } +}); + +(async () => { + const config = await loadConfig(process.env.NOVAVPS_URL || ""); + + app.listen(PORT, "0.0.0.0", () => { + console.log(`[server] Web interface running on http://0.0.0.0:${PORT}`); + console.log(`[server] NOVAVPS_URL: ${config.novavpsUrl || "(not set)"}`); + console.log(`[server] Panels: ${getPanels().map((p) => p.label).join(", ") || "(none)"}`); + }); +})();