Compare commits

..

No commits in common. "main" and "cas-auth" have entirely different histories.

14 changed files with 404 additions and 627 deletions

2
.env.example Normal file
View File

@ -0,0 +1,2 @@
A_NUMBER=A12345671
PASSWORD=

View File

@ -1,30 +1,33 @@
# AggietimeD
AggietimeD is a simple daemon service to open a SAML with selenium, steal a cookie,
AggietimeD is a simple daemon service to do some hacked CAS authentication,
then sit in the background listening to requests over a unix socket - making it
"easy" to write scripts to get Aggie Time data, wherever you need it!
https://user-images.githubusercontent.com/25559600/219797856-76c82934-ceb2-4562-90bc-fff2250562a1.mp4
## Installation
Something among the lines of:
```
sudo pacman -S chromium pass
git clone https://github.com/Simponic/aggietimed
cd aggietimed
git clone https://github.com/Simponic/aggietime-cli
cd aggietime-cli
npm i
sudo npm install -g .
# Store password, a-number in gnu pass:
pass insert --multiline usu.edu
# <password>
# anumber: <anumber>
cp .env.example .env
chmod 0700 .env
```
Then, set your A-Number and password in `.env`.
Finally (optional), change the values in `aggietimed.service` and install it in
`~/.config/systemd/user`, and enable it with
`systemctl --user daemon-reload && systemctl enable --now --user aggietimed`.
## Usage
Look at `aggietimed -h`. (hey, at least it's _something_)
Look at `aggietimed -h`.

View File

@ -1,12 +1,10 @@
[Unit]
Description=aggietimed
Wants=display.target
[Service]
Environment=DISPLAY=:0
Type=simple
EnvironmentFile=/home/lizzy/work/simple_scripts/aggietime_cli/.env
ExecStart=/usr/bin/aggietimed -d -s /tmp/aggietimed.sock
Restart=always
[Install]
WantedBy=default.target

2
cli.js
View File

@ -1,4 +1,4 @@
#!/usr/bin/env node
import main from "./src/main.js";
import main from './src/main.js';
main();

593
package-lock.json generated
View File

@ -1,23 +1,17 @@
{
"name": "aggietimed",
"version": "0.0.1",
"name": "aggietime_cli",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "aggietimed",
"version": "0.0.1",
"dependencies": {
"argparse": "^2.0.1",
"axios": "^1.3.3",
"axios-cookiejar-support": "^4.0.6",
"dotenv": "^16.0.3",
"expire-cache": "^1.0.0",
"selenium-webdriver": "^4.8.1",
"node-html-parser": "^6.1.4",
"tough-cookie": "^4.1.2"
},
"bin": {
"aggietimed": "cli.js"
}
},
"node_modules/agent-base": {
@ -69,19 +63,10 @@
"tough-cookie": ">=4.0.0"
}
},
"node_modules/balanced-match": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw=="
},
"node_modules/brace-expansion": {
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
"dependencies": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
}
"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/combined-stream": {
"version": "1.0.8",
@ -94,15 +79,31 @@
"node": ">= 0.8"
}
},
"node_modules/concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg=="
"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"
},
"node_modules/core-util-is": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
"integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ=="
"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/debug": {
"version": "4.3.4",
@ -128,6 +129,57 @@
"node": ">=0.4.0"
}
},
"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/dotenv": {
"version": "16.0.3",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz",
@ -136,6 +188,17 @@
"node": ">=12"
}
},
"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/expire-cache": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/expire-cache/-/expire-cache-1.0.0.tgz",
@ -173,28 +236,12 @@
"node": ">= 6"
}
},
"node_modules/fs.realpath": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
"integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw=="
},
"node_modules/glob": {
"version": "7.2.3",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz",
"integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==",
"dependencies": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.1.1",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
},
"engines": {
"node": "*"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
"node_modules/he": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz",
"integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==",
"bin": {
"he": "bin/he"
}
},
"node_modules/http-cookie-agent": {
@ -224,49 +271,6 @@
}
}
},
"node_modules/immediate": {
"version": "3.0.6",
"resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz",
"integrity": "sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ=="
},
"node_modules/inflight": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
"integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==",
"dependencies": {
"once": "^1.3.0",
"wrappy": "1"
}
},
"node_modules/inherits": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
},
"node_modules/isarray": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
"integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ=="
},
"node_modules/jszip": {
"version": "3.10.1",
"resolved": "https://registry.npmjs.org/jszip/-/jszip-3.10.1.tgz",
"integrity": "sha512-xXDvecyTpGLrqFrvkrUSoxxfJI5AH7U8zxxtVclpsUtMCq4JQ290LY8AW5c7Ggnr/Y/oK+bQMbqK2qmtk3pN4g==",
"dependencies": {
"lie": "~3.3.0",
"pako": "~1.0.2",
"readable-stream": "~2.3.6",
"setimmediate": "^1.0.5"
}
},
"node_modules/lie": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/lie/-/lie-3.3.0.tgz",
"integrity": "sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ==",
"dependencies": {
"immediate": "~3.0.5"
}
},
"node_modules/mime-db": {
"version": "1.52.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
@ -286,48 +290,31 @@
"node": ">= 0.6"
}
},
"node_modules/minimatch": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",
"integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==",
"dependencies": {
"brace-expansion": "^1.1.7"
},
"engines": {
"node": "*"
}
},
"node_modules/ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
},
"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==",
"node_modules/node-html-parser": {
"version": "6.1.4",
"resolved": "https://registry.npmjs.org/node-html-parser/-/node-html-parser-6.1.4.tgz",
"integrity": "sha512-3muP9Uy/Pz7bQa9TNYVQzWJhNZMqyCx7xJle8kz2/y1UgzAUyXXShc1IcPaJy6u07CE3K5rQcRwlvHzmlySRjg==",
"dependencies": {
"wrappy": "1"
"css-select": "^5.1.0",
"he": "1.2.0"
}
},
"node_modules/pako": {
"version": "1.0.11",
"resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz",
"integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw=="
"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"
},
"node_modules/path-is-absolute": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
"integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==",
"engines": {
"node": ">=0.10.0"
"funding": {
"url": "https://github.com/fb55/nth-check?sponsor=1"
}
},
"node_modules/process-nextick-args": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
"integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag=="
},
"node_modules/proxy-from-env": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
@ -351,81 +338,11 @@
"resolved": "https://registry.npmjs.org/querystringify/-/querystringify-2.2.0.tgz",
"integrity": "sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ=="
},
"node_modules/readable-stream": {
"version": "2.3.8",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz",
"integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==",
"dependencies": {
"core-util-is": "~1.0.0",
"inherits": "~2.0.3",
"isarray": "~1.0.0",
"process-nextick-args": "~2.0.0",
"safe-buffer": "~5.1.1",
"string_decoder": "~1.1.1",
"util-deprecate": "~1.0.1"
}
},
"node_modules/requires-port": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz",
"integrity": "sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ=="
},
"node_modules/rimraf": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
"integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==",
"dependencies": {
"glob": "^7.1.3"
},
"bin": {
"rimraf": "bin.js"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/safe-buffer": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
},
"node_modules/selenium-webdriver": {
"version": "4.8.1",
"resolved": "https://registry.npmjs.org/selenium-webdriver/-/selenium-webdriver-4.8.1.tgz",
"integrity": "sha512-p4MtfhCQdcV6xxkS7eI0tQN6+WNReRULLCAuT4RDGkrjfObBNXMJ3WT8XdK+aXTr5nnBKuh+PxIevM0EjJgkxA==",
"dependencies": {
"jszip": "^3.10.0",
"tmp": "^0.2.1",
"ws": ">=8.11.0"
},
"engines": {
"node": ">= 14.20.0"
}
},
"node_modules/setimmediate": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz",
"integrity": "sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA=="
},
"node_modules/string_decoder": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
"integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
"dependencies": {
"safe-buffer": "~5.1.0"
}
},
"node_modules/tmp": {
"version": "0.2.1",
"resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.1.tgz",
"integrity": "sha512-76SUhtfqR2Ijn+xllcI5P1oyannHNHByD80W1q447gU3mp9G9PSpGdWmjUOHRDPiHYacIk66W7ubDTuPF3BEtQ==",
"dependencies": {
"rimraf": "^3.0.0"
},
"engines": {
"node": ">=8.17.0"
}
},
"node_modules/tough-cookie": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.1.2.tgz",
@ -456,36 +373,6 @@
"querystringify": "^2.1.1",
"requires-port": "^1.0.0"
}
},
"node_modules/util-deprecate": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
"integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw=="
},
"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=="
},
"node_modules/ws": {
"version": "8.12.1",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.12.1.tgz",
"integrity": "sha512-1qo+M9Ba+xNhPB+YTWUlK6M17brTut5EXbcBaMRN5pH5dFrXz7lzz1ChFSUq3bOUl8yEvSenhHmYUNJxFzdJew==",
"engines": {
"node": ">=10.0.0"
},
"peerDependencies": {
"bufferutil": "^4.0.1",
"utf-8-validate": ">=5.0.2"
},
"peerDependenciesMeta": {
"bufferutil": {
"optional": true
},
"utf-8-validate": {
"optional": true
}
}
}
},
"dependencies": {
@ -525,19 +412,10 @@
"http-cookie-agent": "^5.0.2"
}
},
"balanced-match": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw=="
},
"brace-expansion": {
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
}
"boolbase": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz",
"integrity": "sha512-JZOSA7Mo9sNGB8+UjSgzdLtokWAky1zbztM3WRLCbZ70/3cTANmQmOdR7y2g+J0e2WXywy1yS468tY+IruqEww=="
},
"combined-stream": {
"version": "1.0.8",
@ -547,15 +425,22 @@
"delayed-stream": "~1.0.0"
}
},
"concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg=="
"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"
}
},
"core-util-is": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
"integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ=="
"css-what": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/css-what/-/css-what-6.1.0.tgz",
"integrity": "sha512-HTUrgRJ7r4dsZKU6GjmpfRK1O76h97Z8MfS1G0FozR+oF2kG6Vfe8JE6zwrkbxigziPHinCJ+gCPjA9EaBDtRw=="
},
"debug": {
"version": "4.3.4",
@ -570,11 +455,49 @@
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ=="
},
"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"
}
},
"dotenv": {
"version": "16.0.3",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz",
"integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ=="
},
"entities": {
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/entities/-/entities-4.4.0.tgz",
"integrity": "sha512-oYp7156SP8LkeGD0GF85ad1X9Ai79WtRsZ2gxJqtBuzH+98YUV6jkHEKlZkMbcrjJjIVJNIDP/3WL9wQkoPbWA=="
},
"expire-cache": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/expire-cache/-/expire-cache-1.0.0.tgz",
@ -595,23 +518,10 @@
"mime-types": "^2.1.12"
}
},
"fs.realpath": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
"integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw=="
},
"glob": {
"version": "7.2.3",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz",
"integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==",
"requires": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.1.1",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
}
"he": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz",
"integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw=="
},
"http-cookie-agent": {
"version": "5.0.2",
@ -621,49 +531,6 @@
"agent-base": "^6.0.2"
}
},
"immediate": {
"version": "3.0.6",
"resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz",
"integrity": "sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ=="
},
"inflight": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
"integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==",
"requires": {
"once": "^1.3.0",
"wrappy": "1"
}
},
"inherits": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
},
"isarray": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
"integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ=="
},
"jszip": {
"version": "3.10.1",
"resolved": "https://registry.npmjs.org/jszip/-/jszip-3.10.1.tgz",
"integrity": "sha512-xXDvecyTpGLrqFrvkrUSoxxfJI5AH7U8zxxtVclpsUtMCq4JQ290LY8AW5c7Ggnr/Y/oK+bQMbqK2qmtk3pN4g==",
"requires": {
"lie": "~3.3.0",
"pako": "~1.0.2",
"readable-stream": "~2.3.6",
"setimmediate": "^1.0.5"
}
},
"lie": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/lie/-/lie-3.3.0.tgz",
"integrity": "sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ==",
"requires": {
"immediate": "~3.0.5"
}
},
"mime-db": {
"version": "1.52.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
@ -677,41 +544,27 @@
"mime-db": "1.52.0"
}
},
"minimatch": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",
"integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==",
"requires": {
"brace-expansion": "^1.1.7"
}
},
"ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
},
"once": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
"integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==",
"node-html-parser": {
"version": "6.1.4",
"resolved": "https://registry.npmjs.org/node-html-parser/-/node-html-parser-6.1.4.tgz",
"integrity": "sha512-3muP9Uy/Pz7bQa9TNYVQzWJhNZMqyCx7xJle8kz2/y1UgzAUyXXShc1IcPaJy6u07CE3K5rQcRwlvHzmlySRjg==",
"requires": {
"wrappy": "1"
"css-select": "^5.1.0",
"he": "1.2.0"
}
},
"pako": {
"version": "1.0.11",
"resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz",
"integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw=="
},
"path-is-absolute": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
"integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg=="
},
"process-nextick-args": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
"integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag=="
"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"
}
},
"proxy-from-env": {
"version": "1.1.0",
@ -733,69 +586,11 @@
"resolved": "https://registry.npmjs.org/querystringify/-/querystringify-2.2.0.tgz",
"integrity": "sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ=="
},
"readable-stream": {
"version": "2.3.8",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz",
"integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==",
"requires": {
"core-util-is": "~1.0.0",
"inherits": "~2.0.3",
"isarray": "~1.0.0",
"process-nextick-args": "~2.0.0",
"safe-buffer": "~5.1.1",
"string_decoder": "~1.1.1",
"util-deprecate": "~1.0.1"
}
},
"requires-port": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz",
"integrity": "sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ=="
},
"rimraf": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
"integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==",
"requires": {
"glob": "^7.1.3"
}
},
"safe-buffer": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
},
"selenium-webdriver": {
"version": "4.8.1",
"resolved": "https://registry.npmjs.org/selenium-webdriver/-/selenium-webdriver-4.8.1.tgz",
"integrity": "sha512-p4MtfhCQdcV6xxkS7eI0tQN6+WNReRULLCAuT4RDGkrjfObBNXMJ3WT8XdK+aXTr5nnBKuh+PxIevM0EjJgkxA==",
"requires": {
"jszip": "^3.10.0",
"tmp": "^0.2.1",
"ws": ">=8.11.0"
}
},
"setimmediate": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz",
"integrity": "sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA=="
},
"string_decoder": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
"integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
"requires": {
"safe-buffer": "~5.1.0"
}
},
"tmp": {
"version": "0.2.1",
"resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.1.tgz",
"integrity": "sha512-76SUhtfqR2Ijn+xllcI5P1oyannHNHByD80W1q447gU3mp9G9PSpGdWmjUOHRDPiHYacIk66W7ubDTuPF3BEtQ==",
"requires": {
"rimraf": "^3.0.0"
}
},
"tough-cookie": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.1.2.tgz",
@ -820,22 +615,6 @@
"querystringify": "^2.1.1",
"requires-port": "^1.0.0"
}
},
"util-deprecate": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
"integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw=="
},
"wrappy": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ=="
},
"ws": {
"version": "8.12.1",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.12.1.tgz",
"integrity": "sha512-1qo+M9Ba+xNhPB+YTWUlK6M17brTut5EXbcBaMRN5pH5dFrXz7lzz1ChFSUq3bOUl8yEvSenhHmYUNJxFzdJew==",
"requires": {}
}
}
}

View File

@ -8,7 +8,7 @@
"axios-cookiejar-support": "^4.0.6",
"dotenv": "^16.0.3",
"expire-cache": "^1.0.0",
"selenium-webdriver": "^4.8.1",
"node-html-parser": "^6.1.4",
"tough-cookie": "^4.1.2"
},
"type": "module",

View File

@ -6,7 +6,6 @@ const ACTIONS = {
"current-shift": aggietime.current_shift,
"current-user": aggietime.get_user_info,
"status-line": aggietime.get_status_line,
"past-week": aggietime.last_week,
};
export const do_action = async (body) => {

View File

@ -5,13 +5,10 @@ import {
USER_CACHE_EXP_SEC,
CLOCKIN_PATH,
CLOCKOUT_PATH,
SUMMARY_PATH,
OPEN_SHIFT_PATH,
OPEN_SHIFT_EXP_SEC,
PAST_WEEK_EXP_SEC,
} from "./constants.js";
import { with_exponential_retry } from "./exponential_retry.js";
import { client } from "./axios_client.js";
import expireCache from "expire-cache";
@ -23,44 +20,42 @@ const aggietime = client.create({
const replace_path_args = (path, map) =>
path.replaceAll(/:([a-zA-Z0-9_]+)/g, (_, key) => map[key]);
const get_user_position_or_specified = async (position_id) => {
const get_user_position_or_specified = async (position) => {
const { positions } = await get_user_info();
if (position_id === undefined && positions.length != 1) {
if (!position && positions.length != 1) {
throw "Must specify a position when there's not only one to choose from";
} else if (position_id === undefined) {
return positions[0];
} else if (!position) {
position = positions[0];
}
return position_id;
return position;
};
export const get_user_info = async () => {
if (!expireCache.get("user")) {
const user = await with_exponential_retry(() =>
aggietime.get(USER_PATH).then(({ data, config }) => {
const user = await aggietime.get(USER_PATH).then(({ data, config }) => {
const csrf_token = config.jar
.toJSON()
.cookies.find(
({ domain, key }) =>
domain === AGGIETIME_DOMAIN && key === "XSRF-TOKEN",
domain === AGGIETIME_DOMAIN && key === "XSRF-TOKEN"
).value;
expireCache.set("aggietime-csrf", csrf_token);
return data;
}),
);
});
expireCache.set("user", user, USER_CACHE_EXP_SEC);
}
return expireCache.get("user");
};
const do_clock_mutation = async (path, { position_id } = {}) => {
position_id = await get_user_position_or_specified(position_id);
const do_clock_mutation = async (path, { position } = {}) => {
position = await get_user_position_or_specified(position);
return await aggietime
.post(
replace_path_args(path, { position_id }),
replace_path_args(path, { position }),
{
comment: "",
},
@ -68,7 +63,7 @@ const do_clock_mutation = async (path, { position_id } = {}) => {
headers: {
"X-XSRF-TOKEN": expireCache.get("aggietime-csrf"),
},
},
}
)
.then(({ data }) => {
expireCache.remove("status_line");
@ -76,8 +71,6 @@ const do_clock_mutation = async (path, { position_id } = {}) => {
});
};
// Actions
export const clock_in = async (rest) => do_clock_mutation(CLOCKIN_PATH, rest);
export const clock_out = async (rest) => do_clock_mutation(CLOCKOUT_PATH, rest);
@ -92,7 +85,7 @@ export const current_shift = async () => {
if (`${AGGIETIME_URI}/${req_path}` != response_url) {
// IMO a very weird decision - when there is no open shift the api redirects
// home instead of sending back a 404 or something
// home instead of sending back a 404 or something actually *reasonable* :3
return null;
}
@ -109,42 +102,15 @@ export const get_status_line = async () => {
const start = new Date(shift?.start);
status_line =
((new Date().getTime() - start.getTime()) / (1000 * 60 * 60)).toFixed(
2,
2
) + " hours";
}
expireCache.set(
"status_line",
`${anumber} - ${status_line}`,
OPEN_SHIFT_EXP_SEC,
OPEN_SHIFT_EXP_SEC
);
}
return { status: expireCache.get("status_line") };
};
export const last_week = async ({ position_id }) => {
position_id = await get_user_position_or_specified(position_id);
const [start, end] = [
((d) => {
const day = d.getDay();
const diff = d.getDate() - day + (day == 0 ? -6 : 1);
return new Date(d.setDate(diff));
})(new Date()),
new Date(),
].map((d) => d.toISOString().split("T")[0]);
if (!expireCache.get("past_week")) {
const { anumber } = await get_user_info();
const hours = await aggietime
.get(replace_path_args(SUMMARY_PATH, { position_id, start, end }))
.then(({ data: { undisputed_hours } }) => undisputed_hours);
expireCache.set(
"past_week",
`${anumber} - ${hours} hours`,
PAST_WEEK_EXP_SEC,
);
}
return { status: expireCache.get("past_week") };
};

View File

@ -2,5 +2,5 @@ import { wrapper } from "axios-cookiejar-support";
import { CookieJar } from "tough-cookie";
import axios from "axios";
export const jar = new CookieJar();
const jar = new CookieJar();
export const client = wrapper(axios.create({ jar, withCredentials: true }));

View File

@ -3,30 +3,29 @@ export const KILL_SIGNALS = ["SIGINT", "SIGTERM", "SIGQUIT"];
export const AGGIETIME_DOMAIN = "aggietimeultra.usu.edu";
export const AGGIETIME_URI = `https://${AGGIETIME_DOMAIN}`;
export const AGGIETIME_AUTH_COOKIE_NAME = "access_token_cookie";
export const AGGIETIME_URL_CONTAINS_SIGNIFIES_AUTH_COMPLETE = "employee";
export const REFRESH_JWT_MS = 5 * 1000 * 60;
export const LOGIN_PATH = "api/v1/auth/login";
export const CLOCKIN_PATH = "api/v1/positions/:position_id/clock_in";
export const CLOCKOUT_PATH = "api/v1/positions/:position_id/clock_out";
export const LOGOUT_PATH = "api/v1/auth/logout";
export const CLOCKIN_PATH = "api/v1/positions/:position/clock_in";
export const CLOCKOUT_PATH = "api/v1/positions/:position/clock_out";
export const USER_PATH = "api/v1/auth/get_user_info";
export const SUMMARY_PATH =
"api/v1/positions/:position_id/summary?start=:start&end=:end";
export const OPEN_SHIFT_PATH = "api/v1/users/:anumber/open_shift";
export const OPEN_SHIFT_EXP_SEC = 60;
export const PAST_WEEK_EXP_SEC = 180;
export const EXECUTION_SELECTOR = "input[type=hidden][name=execution]";
export const DUO_IFRAME_SELECTOR = "#duo_iframe";
export const DUO_FACTOR = "Duo Push";
export const DUO_INPUT_FIELD_SELECTORS = [
"input[type=hidden][name=sid]",
"input[type=hidden][name=out_of_date]",
"input[type=hidden][name=days_out_of_date]",
"input[type=hidden][name=days_to_block]",
"input[type=hidden][name=preferred_device]",
];
export const USER_CACHE_EXP_SEC = 30;
export const SAML_SIGN_IN_TITLE = "Sign in to your account";
export const SAML_SUBMIT_SELECTOR = "input[type=submit]";
export const SAML_EMAIL_SELECTOR = "input[type=email]";
export const SAML_PASSWORD_SELECTOR = "input[type=password]";
export const MAX_DEFAULT_RETRY_AMOUNT = 3;
export const WAIT_MS = 2000;
export const RETRY_EXPONENT = 1.2;
export const RETRY_EXPONENTIAL_FACTOR = 1.1;
export const DEFAULT_PASS_CMD = "pass usu.edu";

View File

@ -11,12 +11,12 @@ export const with_exponential_retry = async (
promise_fn,
validation_fn = (x) => Promise.resolve(!!x),
max_retries = MAX_DEFAULT_RETRY_AMOUNT,
retries = 0,
retries = 0
) => {
try {
if (retries)
await wait_for(
WAIT_MS * Math.pow(RETRY_EXPONENT, RETRY_EXPONENTIAL_FACTOR * retries),
WAIT_MS * Math.pow(RETRY_EXPONENT, RETRY_EXPONENTIAL_FACTOR * retries)
);
const res = await promise_fn();
@ -29,7 +29,7 @@ export const with_exponential_retry = async (
promise_fn,
validation_fn,
max_retries,
retries + 1,
retries + 1
);
}
};

View File

@ -2,13 +2,12 @@
import {
DEFAULT_SOCKET_PATH,
DEFAULT_PASS_CMD,
KILL_SIGNALS,
REFRESH_JWT_MS,
} from "./constants.js";
import { with_exponential_retry } from "./exponential_retry.js";
import * as actions from "./actions.js";
import * as session from "./session.js";
import retrieve_creds from "./retrieve_creds.js";
import * as argparse from "argparse";
import * as net from "net";
import * as dotenv from "dotenv";
@ -20,26 +19,21 @@ export default async () => {
if (args.daemon) {
try {
start_server(args, session.logout);
} catch (e) {
console.error(e);
if (fs.existsSync(args.socket_path)) {
start_server(args.socket_path, session.logout);
} catch {
fs.unlinkSync(args.socket_path);
}
}
} else if (args.action) {
if (fs.existsSync(args.socket_path)) {
run_action(args);
run_action(args.socket_path, args.action);
} else {
console.error(`ERR: No such socket '${args.socket_path}'`);
}
}
};
const run_action = (args) => {
const { socket_path, action, position_id } = args;
const run_action = (socket_path, action) => {
const connection = net.connect(socket_path);
connection.on("data", (data) => {
if (Buffer.isBuffer(data)) {
console.log(data.toString().trim());
@ -48,40 +42,23 @@ const run_action = (args) => {
}
connection.end();
});
connection.write(JSON.stringify({ action, rest: { position_id } }));
connection.write(JSON.stringify({ action }));
};
const build_args = () => {
const parser = new argparse.ArgumentParser({ description: "AggieTime CLI" });
parser.add_argument("-cos", "--cookie-on-stdin", {
help: "Set a cookie from whatever is on stdin",
action: argparse.BooleanOptionalAction,
default: false,
});
parser.add_argument("-d", "--daemon", {
help: "Start server as a process blocking daemon",
action: argparse.BooleanOptionalAction,
default: false,
});
parser.add_argument("-pos", "--position-id", {
help: "Position ID (for usage with --action clock_in or clock_out)",
default: undefined,
});
parser.add_argument("-s", "--socket_path", {
default: DEFAULT_SOCKET_PATH,
help: `Set server socket path, defaults to ${DEFAULT_SOCKET_PATH}`,
});
parser.add_argument("-p", "--pass_cmd", {
default: DEFAULT_PASS_CMD,
help: `Set GNU pass retrieval command, defaults to ${DEFAULT_PASS_CMD}`,
});
parser.add_argument("-a", "--action", {
help: `Ignored when daemon flag is set. Returns the value of action (see actions.js) when sent over the socket.`,
});
@ -91,6 +68,7 @@ const build_args = () => {
const kill_server = (server, socket_path) => {
server.close();
try {
fs.unlinkSync(socket_path);
} finally {
@ -98,35 +76,26 @@ const kill_server = (server, socket_path) => {
}
};
const start_server = async (
{ cookie_on_stdin, socket_path, pass_cmd },
on_exit = () => {},
) => {
const start_server = async (socket_path, on_exit = () => {}) => {
if (fs.existsSync(socket_path)) {
console.error(
`ERR: Socket '${socket_path}' already exists.
If no server process is running, remove it (this should've been done automatically, except in the event of a catastrophic failure)
OR
specify another socket path with --socket_path`,
specify another socket path with --socket_path`
);
process.exit(1);
}
if (!cookie_on_stdin) {
const { anumber, password } = await retrieve_creds(pass_cmd);
await session.login(anumber, password);
} else {
let cookie = "";
for await (const chunk of process.stdin) cookie += chunk;
await session.setCookie(cookie);
}
await with_exponential_retry(() =>
session.login(process.env.A_NUMBER, process.env.PASSWORD)
);
session.refresh_jwt();
setInterval(session.refresh_jwt, REFRESH_JWT_MS);
const unix_server = net.createServer((client) => {
client.on("data", (data) => {
// 4096 byte limitation since we don't buffer here
// 4096 byte limitation since we don't buffer here :3
let body;
try {
body = JSON.parse(data);
@ -155,6 +124,6 @@ specify another socket path with --socket_path`,
// Attempt to clean up socket before process gets killed
KILL_SIGNALS.forEach((signal) =>
process.on(signal, () => kill_server(unix_server, socket_path)),
process.on(signal, () => kill_server(unix_server, socket_path))
);
};

View File

@ -1,13 +0,0 @@
import { exec } from "node:child_process";
export default async (cmd) =>
new Promise((res, rej) => {
exec(cmd, (_err, stdout, _stderr) => {
const [password, user_line] = stdout.split("\n");
const [_anumber_specifier, anumber] = user_line.split("anumber: ");
res({
password,
anumber,
});
});
});

View File

@ -1,19 +1,112 @@
import { Builder, Browser, By, Key, until } from "selenium-webdriver";
import { Cookie } from "tough-cookie";
import {
AGGIETIME_AUTH_COOKIE_NAME,
AGGIETIME_DOMAIN,
AGGIETIME_URI,
AGGIETIME_URL_CONTAINS_SIGNIFIES_AUTH_COMPLETE,
LOGIN_PATH,
SAML_SIGN_IN_TITLE,
SAML_SUBMIT_SELECTOR,
SAML_EMAIL_SELECTOR,
SAML_PASSWORD_SELECTOR,
LOGOUT_PATH,
USER_PATH,
DUO_IFRAME_SELECTOR,
DUO_FACTOR,
DUO_INPUT_FIELD_SELECTORS,
EXECUTION_SELECTOR,
} from "./constants.js";
import { jar } from "./axios_client.js";
import * as aggietime from "./aggietime.js";
import { client } from "./axios_client.js";
import { parse } from "node-html-parser";
const make_auth_params = (username, password, execution) =>
new URLSearchParams({
username,
password,
execution,
_eventId: "submit",
geolocation: "",
});
const make_duo_push_params = (
sid,
out_of_date,
days_out_of_date,
days_to_block,
device
) =>
new URLSearchParams({
sid,
out_of_date,
days_out_of_date,
days_to_block,
device,
factor: DUO_FACTOR,
});
const push_duo_get_cookie = async (
duo_iframe_obj,
response_url,
username,
password,
execution
) => {
const [duo_host, duo_sig, duo_src] = [
"data-host",
"data-sig-request",
"src",
].map((attr) => duo_iframe_obj.getAttribute(attr));
const duo = client.create({
baseURL: `https://${duo_host}`,
});
const transaction_id = duo_sig.split(":").at(0);
const app = duo_sig.split(":APP").at(-1);
console.log("Retrieving DUO frame DOM for this transaction...");
const duo_frame = await duo
.post(
`/frame/web/v1/auth?tx=${transaction_id}&parent=${response_url}&v=2.6`
)
.then(({ data }) => parse(data));
const push_param_list = DUO_INPUT_FIELD_SELECTORS.map((selector) =>
duo_frame.querySelector(selector).getAttribute("value")
);
let [sid, _] = push_param_list;
const {
response: { txid },
} = await duo
.post("/frame/prompt", make_duo_push_params.apply(null, push_param_list))
.then(({ data }) => data);
console.log("Waiting for approval...");
const { cookie, parent } = await wait_approve_duo_cookie_resp(duo, sid, txid);
return { duo_signed_resp: cookie + ":APP" + app, parent };
};
const wait_approve_duo_cookie_resp = async (duo, sid, txid) => {
// First status to confirm device was pushed to,
// Second to create a long-poll connection-alive socket for approval status :3
const status_params = new URLSearchParams({
sid,
txid,
});
const {
response: { result_url },
} = await duo.post("/frame/status", status_params).then(async ({ data }) => {
if (data.stat === "OK" && data.response.status_code === "pushed")
return await duo
.post("/frame/status", status_params)
.then(({ data }) => data);
return data;
});
const {
response: { cookie, parent },
} = await duo
.post(result_url, new URLSearchParams({ sid }))
.then(({ data }) => data);
if (!cookie) throw "Unable to retrieve signed cookie from DUO";
return { cookie, parent };
};
export const refresh_jwt = () => {
console.log("Refreshing JWT...");
@ -21,71 +114,53 @@ export const refresh_jwt = () => {
return aggietime.get_user_info();
};
export const setCookie = (jwt) =>
jar.setCookie(`${AGGIETIME_AUTH_COOKIE_NAME}=${jwt}`, AGGIETIME_URI);
export const logout = () => client.get(`${AGGIETIME_URI}/${LOGOUT_PATH}`);
export const login = async (a_number, password) => {
const driver = await new Builder().forBrowser(Browser.CHROME).build();
let cookie;
export const login = async (username, password) => {
const login_page_promise = client.get(`${AGGIETIME_URI}/${LOGIN_PATH}`);
console.log("Retreiving login page...");
try {
console.log("Navigating to login path...");
await driver.get(`${AGGIETIME_URI}/${LOGIN_PATH}`);
const {
request: {
res: { responseUrl: response_url },
},
} = await login_page_promise;
if (a_number && password) {
console.log("Waiting until we eventually redirect to SAML...");
await driver.wait(until.titleIs(SAML_SIGN_IN_TITLE));
let cas_root = await login_page_promise.then(({ data }) => parse(data));
console.log("Waiting until email field is located...");
await driver.wait(until.elementLocated(By.css(SAML_EMAIL_SELECTOR)));
console.log("Parsing DOM for spring execution token...");
const login_execution = cas_root
.querySelector(EXECUTION_SELECTOR)
.getAttribute("value");
console.log("Filling email field...");
await driver
.findElement(By.css(SAML_EMAIL_SELECTOR))
.sendKeys(`${a_number}@usu.edu`);
await driver.findElement(By.css(SAML_SUBMIT_SELECTOR)).click();
console.log("Sending CAS credentials...");
cas_root = await client
.post(response_url, make_auth_params(username, password, login_execution))
.then(({ data }) => parse(data));
console.log("Waiting until password field is located...");
await Promise.all(
[SAML_PASSWORD_SELECTOR, SAML_SUBMIT_SELECTOR].map((selector) =>
driver.wait(until.elementLocated(By.css(selector))),
),
console.log("Parsing DOM for authenticated spring execution token...");
const authed_execution = cas_root
.querySelector(EXECUTION_SELECTOR)
.getAttribute("value");
const duo_iframe_obj = cas_root.querySelector(DUO_IFRAME_SELECTOR);
console.log("Starting DUO authentication...");
const { duo_signed_resp, parent: signed_response_url } =
await push_duo_get_cookie(
duo_iframe_obj,
response_url,
username,
password,
login_execution
);
console.log("Filling password...");
await driver
.findElement(By.css(SAML_PASSWORD_SELECTOR))
.sendKeys(password);
console.log("Debouncing a bit...");
await new Promise((res) => setTimeout(res, 500));
console.log("Submit!");
await driver
.wait(until.elementLocated(By.css(SAML_SUBMIT_SELECTOR)))
.then(() => driver.findElement(By.css(SAML_SUBMIT_SELECTOR)).click());
}
await driver.wait(
until.urlContains(AGGIETIME_URL_CONTAINS_SIGNIFIES_AUTH_COMPLETE),
console.log("Sending DUO signed response back to CAS...");
return await client.post(
signed_response_url,
new URLSearchParams({
execution: authed_execution,
signedDuoResponse: duo_signed_resp,
_eventId: "submit",
})
);
console.log("Retrieving cookie...");
cookie = await driver.manage().getCookie(AGGIETIME_AUTH_COOKIE_NAME);
await jar.setCookie(
new Cookie({
...cookie,
key: cookie.name,
}),
AGGIETIME_URI,
);
console.log("Got it!");
} finally {
await driver.quit();
}
return cookie;
};