Use GNU pass

This commit is contained in:
Lizzy Hunt 2023-03-24 15:12:43 -06:00
parent cce2aa17de
commit 2201d2d9c9
No known key found for this signature in database
GPG Key ID: 8AC6A4B840C0EC49
5 changed files with 39 additions and 42 deletions

View File

@ -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 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! "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 https://user-images.githubusercontent.com/25559600/219797856-76c82934-ceb2-4562-90bc-fff2250562a1.mp4
## Installation ## Installation
Something among the lines of: Something among the lines of:
``` ```
sudo pacman -S chromium sudo pacman -S chromium pass
git clone https://github.com/Simponic/aggietime-cli git clone https://github.com/Simponic/aggietimed
cd aggietime-cli cd aggietimed
npm i npm i
sudo npm install -g . sudo npm install -g .
cp .env.example .env # Store password, a-number in gnu pass:
chmod 0700 .env 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 ## Usage
Look at `aggietimed -h`. Look at `aggietimed -h`. (hey, at least it's _something_)

View File

@ -25,3 +25,5 @@ export const MAX_DEFAULT_RETRY_AMOUNT = 3;
export const WAIT_MS = 2000; export const WAIT_MS = 2000;
export const RETRY_EXPONENT = 1.2; export const RETRY_EXPONENT = 1.2;
export const RETRY_EXPONENTIAL_FACTOR = 1.1; export const RETRY_EXPONENTIAL_FACTOR = 1.1;
export const DEFAULT_PASS_CMD = "pass usu.edu";

View File

@ -2,11 +2,13 @@
import { import {
DEFAULT_SOCKET_PATH, DEFAULT_SOCKET_PATH,
DEFAULT_PASS_CMD,
KILL_SIGNALS, KILL_SIGNALS,
REFRESH_JWT_MS, REFRESH_JWT_MS,
} from "./constants.js"; } from "./constants.js";
import * as actions from "./actions.js"; import * as actions from "./actions.js";
import * as session from "./session.js"; import * as session from "./session.js";
import retrieve_creds from "./retrieve_creds.js";
import * as argparse from "argparse"; import * as argparse from "argparse";
import * as net from "net"; import * as net from "net";
import * as dotenv from "dotenv"; import * as dotenv from "dotenv";
@ -18,10 +20,13 @@ export default async () => {
if (args.daemon) { if (args.daemon) {
try { try {
start_server(args.socket_path, session.logout); start_server(args.socket_path, args.pass_cmd, session.logout);
} catch { } catch (e) {
console.error(e);
if (fs.existsSync(args.socket_path)) {
fs.unlinkSync(args.socket_path); fs.unlinkSync(args.socket_path);
} }
}
} else if (args.action) { } else if (args.action) {
if (fs.existsSync(args.socket_path)) { if (fs.existsSync(args.socket_path)) {
run_action(args.socket_path, args.action); run_action(args.socket_path, args.action);
@ -58,6 +63,11 @@ const build_args = () => {
help: `Set server socket path, defaults to ${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", { 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.`, 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) => { const kill_server = (server, socket_path) => {
server.close(); server.close();
try { try {
fs.unlinkSync(socket_path); fs.unlinkSync(socket_path);
} finally { } 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)) { if (fs.existsSync(socket_path)) {
console.error( console.error(
`ERR: Socket '${socket_path}' already exists. `ERR: Socket '${socket_path}' already exists.
@ -86,7 +95,8 @@ specify another socket path with --socket_path`
process.exit(1); 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(); session.refresh_jwt();
setInterval(session.refresh_jwt, REFRESH_JWT_MS); setInterval(session.refresh_jwt, REFRESH_JWT_MS);

13
src/retrieve_creds.js Normal file
View File

@ -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,
});
});
});

View File

@ -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