summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md27
-rw-r--r--src/constants.js2
-rw-r--r--src/main.js22
-rw-r--r--src/retrieve_creds.js13
-rwxr-xr-xwatch_aggietimed.sh17
5 files changed, 39 insertions, 42 deletions
diff --git a/README.md b/README.md
index cc990a5..1a0628d 100644
--- a/README.md
+++ b/README.md
@@ -4,38 +4,27 @@ AggietimeD is a simple daemon service to open a SAML with selenium, steal a cook
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
+sudo pacman -S chromium pass
-git clone https://github.com/Simponic/aggietime-cli
-cd aggietime-cli
+git clone https://github.com/Simponic/aggietimed
+cd aggietimed
npm i
sudo npm install -g .
-cp .env.example .env
-chmod 0700 .env
+# Store password, a-number in gnu pass:
+pass insert --multiline usu.edu
+# <password>
+# anumber: <anumber>
```
-Then, set your A-Number and password in `.env`.
-
-### SystemD Service
-
-UPDATE: (no) Thanks to the SAML update to AggieTime, we require selenium for auth.
-The SystemD service will not work. Instead, I suggest starting a script to watch
-`aggietimed` with your window manager / desktop environment, restarting if it fails,
-as in `watch_aggietimed.sh`.
-
-If at some point CAS does come back, checkout the `cas-auth` branch.
-
## Usage
-Look at `aggietimed -h`.
+Look at `aggietimed -h`. (hey, at least it's _something_)
diff --git a/src/constants.js b/src/constants.js
index b2e3f9a..9b6c037 100644
--- a/src/constants.js
+++ b/src/constants.js
@@ -25,3 +25,5 @@ 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";
diff --git a/src/main.js b/src/main.js
index 4b8a1bf..690b55f 100644
--- a/src/main.js
+++ b/src/main.js
@@ -2,11 +2,13 @@
import {
DEFAULT_SOCKET_PATH,
+ DEFAULT_PASS_CMD,
KILL_SIGNALS,
REFRESH_JWT_MS,
} from "./constants.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";
@@ -18,9 +20,12 @@ export default async () => {
if (args.daemon) {
try {
- start_server(args.socket_path, session.logout);
- } catch {
- fs.unlinkSync(args.socket_path);
+ start_server(args.socket_path, args.pass_cmd, session.logout);
+ } catch (e) {
+ console.error(e);
+ if (fs.existsSync(args.socket_path)) {
+ fs.unlinkSync(args.socket_path);
+ }
}
} else if (args.action) {
if (fs.existsSync(args.socket_path)) {
@@ -58,6 +63,11 @@ const build_args = () => {
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.`,
});
@@ -67,7 +77,6 @@ const build_args = () => {
const kill_server = (server, socket_path) => {
server.close();
-
try {
fs.unlinkSync(socket_path);
} finally {
@@ -75,7 +84,7 @@ const kill_server = (server, socket_path) => {
}
};
-const start_server = async (socket_path, on_exit = () => {}) => {
+const start_server = async (socket_path, login_cmd, on_exit = () => {}) => {
if (fs.existsSync(socket_path)) {
console.error(
`ERR: Socket '${socket_path}' already exists.
@@ -86,7 +95,8 @@ specify another socket path with --socket_path`
process.exit(1);
}
- await session.login(process.env.A_NUMBER, process.env.PASSWORD);
+ const { anumber, password } = await retrieve_creds(login_cmd);
+ await session.login(anumber, password);
session.refresh_jwt();
setInterval(session.refresh_jwt, REFRESH_JWT_MS);
diff --git a/src/retrieve_creds.js b/src/retrieve_creds.js
new file mode 100644
index 0000000..cd596a0
--- /dev/null
+++ b/src/retrieve_creds.js
@@ -0,0 +1,13 @@
+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,
+ });
+ });
+ });
diff --git a/watch_aggietimed.sh b/watch_aggietimed.sh
deleted file mode 100755
index d8cce82..0000000
--- a/watch_aggietimed.sh
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/bin/sh
-
-socket=/tmp/aggietimed.sock
-env_file=/home/lizzy/work/simple_scripts/aggietime_cli/.env
-
-export $(cat $env_file | xargs)
-
-while true
-do
- aggietimed -d -s $socket
- if [ $? -eq 0 ]
- then
- break
- else
- sleep 1
- fi
-done