From 03b4efc97dc9d026c8abd1eb9f834df43c17b3bd Mon Sep 17 00:00:00 2001 From: xf0r3m Date: Thu, 15 Feb 2024 18:11:54 +0100 Subject: [PATCH] Dodano skrypt propagate i mmftp --- mmftp | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ propagate | 14 ++++++++++ 2 files changed, 90 insertions(+) create mode 100755 mmftp create mode 100755 propagate diff --git a/mmftp b/mmftp new file mode 100755 index 0000000..b2ec447 --- /dev/null +++ b/mmftp @@ -0,0 +1,76 @@ +#!/bin/bash + +RUSER="xf0r3m" +SERVER="192.168.122.99" +SSH_OPTS="" +ssh_opts=$(echo $SSH_OPTS | tr [A-Z] [a-z]); + +function help() { + echo "mmftp - script for handling Apache's user dirs"; + echo "@ 2024 morketsmerke.org"; + echo; + echo "Options: "; + echo; + echo "put [dest] - upload file/s. Destination"; + echo " should be from \${HOME}/public_html, if none files will be"; + echo " placed in \${HOME}/public_html"; + echo; + echo "get [dest] - download file/s. Source"; + echo " should be from \${HOME}/public_html. If destination"; + echo " is none, then . (dot) will be used"; + echo; + echo "weblinks [-n] - print URL-s for all files in dir"; + echo " dir should be relative path from \${HOME}/public_html"; + echo " -n - use IP address instead of FQDN in URL-s"; + echo; + echo "list [dir] - list elements in dir, if dir is none then"; + echo " \${HOME}/public_html will be used."; + echo; + echo "hide [dir] - emits index.html file to all subdirs in dir"; + echo " dir should be relative path from \${HOME}/public_html"; + echo " if dir is none emmision starts from \${HOME}/public_html"; + echo; + echo "unhide [dir] - remove index.html from all subdirs in dir"; + echo " dir should be relative path from \${HOME}/public_html"; + echo " if dir is none deletion starts from \${HOME}/public_html"; + echo; + echo "Configuration: "; + echo; + echo "Befor you use this script, you must point in script source"; + echo "code: remote user, server address and extra SSH options"; + echo "(eg. port). SSH options are optional."; + echo; + echo "RUSER = remote user"; + echo "SERVER = server address"; + echo "SSH_OPTS = extra SSH options (optional)"; + echo; + echo "Usage: "; + echo "$ ./mmftp put images"; + echo "$ ./mmftp get examples ~/Documents"; + echo "$ ./mmftp weblinks images"; + echo "$ ./mmftp list"; + echo "$ ./mmftp hide images"; + echo "$ ./mmftp unhide images"; + echo; +} + +if [ ! "$RUSER" ]; then help; exit 1; fi +if [ ! "$SERVER" ]; then help; exit 1; fi + +if [ ! "$1" ]; then help; exit 1; +else + +case $1 in + "put") scp ${SSH_OPTS} -r $2 ${RUSER}@${SERVER}:/home/${RUSER}/public_html/$3;; + "get") scp ${SSH_OPTS} -r ${RUSER}@${SERVER}:/home/${RUSER}/public_html/$2 ${3:-.};; + "weblinks") if [ "$2" ] && [ "$2" = "-n" ]; then + ssh ${ssh_opts} ${RUSER}@${SERVER} "weblinks -n $3"; + else + ssh ${ssh_opts} ${RUSER}@${SERVER} "weblinks $2"; + fi;; + "list") ssh ${ssh_opts} ${RUSER}@${SERVER} "ls -AF /home/${RUSER}/public_html/$2";; + "hide") ssh ${ssh_opts} ${RUSER}@${SERVER} "if [ -f ~/index.html ]; then propagate index.html $2; else echo 'It works\!' > ~/index.html; propagate index.html $2; fi";; + "unhide") ssh ${ssh_opts} ${RUSER}@${SERVER} "propagate -u index.html $2";; +esac + +fi diff --git a/propagate b/propagate new file mode 100755 index 0000000..faf0471 --- /dev/null +++ b/propagate @@ -0,0 +1,14 @@ +#!/bin/bash + +if [ "$1" ] && [ "$1" = "-u" ]; then delFlag=1; shift; fi + +FILE=${HOME}/$1; +DIR=${HOME}/public_html/$2; + +for P in $(find ${DIR} -type d -print | awk '{printf $1" "}'); do + if [ "$delFlag" ]; then + rm -v ${P}/$(basename $FILE); + else + cp -v $FILE $P; + fi +done -- 2.39.5