From 9f0221822c6f357a6ac012607c2ce7d8ca8df9b4 Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Sun, 25 Feb 2018 23:30:58 -0500 Subject: Add stop --- .gitignore | 3 ++- Makefile | 2 +- create.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ destroy.c | 40 ++++++++++++++++++++++++++++++++++++++++ setup.c | 49 ------------------------------------------------- ssh-command.sh | 35 ++++++++++++++++++++--------------- 6 files changed, 112 insertions(+), 66 deletions(-) create mode 100644 create.c create mode 100644 destroy.c delete mode 100644 setup.c diff --git a/.gitignore b/.gitignore index db06a66..cd963a4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,9 @@ chroot.tar +create +destroy ingest ptee root -setup ssh-command tags view diff --git a/Makefile b/Makefile index 58e7cc9..e37fc70 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -BINS = ingest ptee setup ssh-command view +BINS = create destroy ingest ptee ssh-command view USER = stream CFLAGS += -Wall -Wextra -Wpedantic diff --git a/create.c b/create.c new file mode 100644 index 0000000..49cadb6 --- /dev/null +++ b/create.c @@ -0,0 +1,49 @@ +/* Copyright (C) 2018 Causal Agent June + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) { + if (argc < 2) errx(EX_USAGE, "missing public id"); + + uint32_t id[4]; + char public[10 + 32 + 1]; + char private[8 + 32 + 1]; + + arc4random_buf(id, sizeof(id)); + snprintf(public, sizeof(public), "public/%s", argv[1]); + snprintf( + private, sizeof(private), + "private/%08x%08x%08x%08x", + id[0], id[1], id[2], id[3] + ); + + int fd = open(public, O_CREAT | O_EXCL, 0644); + if (fd < 0) err(EX_CANTCREAT, "%s", public); + + snprintf(public, sizeof(public), "../public/%s", argv[1]); + int error = symlink(public, private); + if (error) err(EX_CANTCREAT, "%s", private); + + printf("%08x%08x%08x%08x\n", id[0], id[1], id[2], id[3]); + return EX_OK; +} diff --git a/destroy.c b/destroy.c new file mode 100644 index 0000000..02355f0 --- /dev/null +++ b/destroy.c @@ -0,0 +1,40 @@ +/* Copyright (C) 2018 Causal Agent June + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include + +int main(int argc, char *argv[]) { + if (argc < 2) errx(EX_USAGE, "missing private id"); + + int fd = open("private", 0); + if (fd < 0) err(EX_NOINPUT, "private"); + + const char *private = argv[1]; + char public[10 + 32 + 1] = {0}; + ssize_t n = readlinkat(fd, private, public, sizeof(public) - 1); + if (n < 0) err(EX_NOINPUT, "%s", private); + + int error = unlinkat(fd, public, 0); + if (error) err(EX_NOINPUT, "%s", public); + + error = unlinkat(fd, private, 0); + if (error) err(EX_NOINPUT, "%s", private); + + return EX_OK; +} diff --git a/setup.c b/setup.c deleted file mode 100644 index 92509e3..0000000 --- a/setup.c +++ /dev/null @@ -1,49 +0,0 @@ -/* Copyright (C) 2018 Causal Agent June - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include - -int main(int argc, char *argv[]) { - if (argc < 2) errx(EX_USAGE, "missing public id"); - - uint32_t id[4]; - char public[7 + 32 + 1]; - char private[8 + 32 + 1]; - - arc4random_buf(id, sizeof(id)); - snprintf(public, sizeof(public), "public/%s", argv[1]); - snprintf( - private, sizeof(private), - "private/%08x%08x%08x%08x", - id[0], id[1], id[2], id[3] - ); - - int fd = open(public, O_CREAT | O_EXCL, 0644); - if (fd < 0) err(EX_CANTCREAT, "%s", public); - - snprintf(public, sizeof(public), "../public/%s", argv[1]); - int error = symlink(public, private); - if (error) err(EX_CANTCREAT, "%s", private); - - printf("%08x%08x%08x%08x\n", id[0], id[1], id[2], id[3]); - return EX_OK; -} diff --git a/ssh-command.sh b/ssh-command.sh index 4433717..3381d40 100644 --- a/ssh-command.sh +++ b/ssh-command.sh @@ -6,35 +6,39 @@ GIT_URL=git@ascii.town:stream.git welcome() { echo - echo 'Welcome to Twinch dot ptee vee!' + echo ' [~ The Stream at ASCII Town ~] ' echo - echo 'To view a public stream, run one of the following commands:' - echo - cd public for id in *; do echo " ssh -t $SSH_URL $id" done echo + echo ' [~ A Stream of Your Own ~] ' + echo + echo " ssh -t $SSH_URL start" } start() { - local id - id=$(setup $1) + local public private trash + read -p 'Public ID: ' -r public trash + public=${public##*/} + private=$(create $public) + echo "Private ID: $private" echo - echo 'Stream created!' + echo ' [~ Stop ~] ' echo - echo 'To view the stream, run:' + echo " ssh -t $SSH_URL stop $private" echo - echo " ssh -t $SSH_URL $1" + echo ' [~ View ~] ' echo - echo 'To broadcast to the stream, run:' + echo " ssh -t $SSH_URL $public" echo - echo " git clone $GIT_URL" - echo " cd stream" - echo " make ptee" - echo " ./ptee | ssh $SSH_URL ingest $id" + echo ' [~ Broadcast ~] ' echo + echo " git clone $GIT_URL" + echo ' cd stream' + echo ' make ptee' + echo " ./ptee | ssh $SSH_URL ingest $private" } if [ -z "${SSH_ORIGINAL_COMMAND:-}" ]; then @@ -43,7 +47,8 @@ if [ -z "${SSH_ORIGINAL_COMMAND:-}" ]; then else set $SSH_ORIGINAL_COMMAND case $1 in - start) start ${2##*/} ;; + start) start ;; + stop) exec destroy ${2##*/} ;; ingest) exec ingest private/${2##*/} ;; view) exec view public/${2##*/} ;; *) exec view public/${1##*/} ;; -- cgit 1.4.1