diff --git a/README.md b/README.md index 611b9b7..0170f87 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ # variousscripts - -Simple scripts for different purposes \ No newline at end of file +Simple scripts for different purposes released under DWTWL 2.55: +controlserverwebpage - web page and scripts for basic control of server with Veracrypt/Truecrypt storage +crontabbackupdaily - backup script for everyday cron execution +pylogextractor - tool for extracting specific strings from log files +restartprocesspage - web page for restart some process diff --git a/controlserverwebpage/.htaccess b/controlserverwebpage/.htaccess new file mode 100644 index 0000000..27fc73f --- /dev/null +++ b/controlserverwebpage/.htaccess @@ -0,0 +1,4 @@ +RewriteEngine On +RewriteCond %{SERVER_PORT} 80 +RewriteRule ^(.*)$ https://192.168.1.127/$1 [R,L] +Options +Indexes diff --git a/controlserverwebpage/README.md b/controlserverwebpage/README.md new file mode 100644 index 0000000..940e0c6 --- /dev/null +++ b/controlserverwebpage/README.md @@ -0,0 +1,17 @@ +### controlserverwebpage + +Web page and scripts for basic control of server with Veracrypt/Truecrypt storage + +This software is released under the DWTW license. + +Warning! Use only https connection for sending passwords via this page. + +Change /etc/sudoers for adding root previlegies to www-data. +Compile phphalt.c and phpreboot.c in /usr/bin: + +``` +gcc -Wall phphalt.c -o phphalt +gcc -Wall phpreboot.c -o phpreboot +``` + +( https://stackoverflow.com/questions/24100055/ ) diff --git a/controlserverwebpage/etc/sudoers b/controlserverwebpage/etc/sudoers new file mode 100644 index 0000000..bf16a31 --- /dev/null +++ b/controlserverwebpage/etc/sudoers @@ -0,0 +1,2 @@ +# User privilege specification +www-data ALL=(ALL) /usr/bin/veracrypt, /usr/bin/phpreboot, /usr/bin/phphalt diff --git a/controlserverwebpage/halt.php b/controlserverwebpage/halt.php new file mode 100644 index 0000000..49c9511 --- /dev/null +++ b/controlserverwebpage/halt.php @@ -0,0 +1,8 @@ + diff --git a/controlserverwebpage/index.html b/controlserverwebpage/index.html new file mode 100644 index 0000000..471b137 --- /dev/null +++ b/controlserverwebpage/index.html @@ -0,0 +1,91 @@ + + + + + Control page + + +Status: +

+ + + + + + + \ No newline at end of file diff --git a/controlserverwebpage/password.php b/controlserverwebpage/password.php new file mode 100644 index 0000000..7fd8972 --- /dev/null +++ b/controlserverwebpage/password.php @@ -0,0 +1,6 @@ + diff --git a/controlserverwebpage/reboot.php b/controlserverwebpage/reboot.php new file mode 100644 index 0000000..7e76fd4 --- /dev/null +++ b/controlserverwebpage/reboot.php @@ -0,0 +1,8 @@ + diff --git a/controlserverwebpage/status.php b/controlserverwebpage/status.php new file mode 100644 index 0000000..fb7c1be --- /dev/null +++ b/controlserverwebpage/status.php @@ -0,0 +1,12 @@ + diff --git a/controlserverwebpage/usr/bin/phphalt.c b/controlserverwebpage/usr/bin/phphalt.c new file mode 100644 index 0000000..0811690 --- /dev/null +++ b/controlserverwebpage/usr/bin/phphalt.c @@ -0,0 +1,10 @@ +#include +#include +#include + +int main() { + setuid(0); + char *command = "/sbin/shutdown"; + execl(command, command, NULL); + return 0; +} diff --git a/controlserverwebpage/usr/bin/phpreboot.c b/controlserverwebpage/usr/bin/phpreboot.c new file mode 100644 index 0000000..931279a --- /dev/null +++ b/controlserverwebpage/usr/bin/phpreboot.c @@ -0,0 +1,10 @@ +#include +#include +#include + +int main() { + setuid(0); + char *command = "/sbin/reboot"; + execl(command, command, NULL); + return 0; +} diff --git a/controlserverwebpage/usr/bin/stmnt.sh b/controlserverwebpage/usr/bin/stmnt.sh new file mode 100755 index 0000000..9c9f5ee --- /dev/null +++ b/controlserverwebpage/usr/bin/stmnt.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +echo www-data-password | sudo -S veracrypt -t -v --non-interactive --mount /tmp/crypt_container.dat /media/veracrypt/ -p $1 +sleep 1 +echo www-data-password | sudo -S echo "there some another command" + +exit diff --git a/crontabbackupdaily/README.md b/crontabbackupdaily/README.md new file mode 100644 index 0000000..3d18cd4 --- /dev/null +++ b/crontabbackupdaily/README.md @@ -0,0 +1,6 @@ +### crontab backup daily +Simple backup script for everyday cron execution. +After execution `crontab -e` add new line to crontab schedule: +``` +@daily sh /home/user/backup.sh +``` \ No newline at end of file diff --git a/crontabbackupdaily/backup.sh b/crontabbackupdaily/backup.sh new file mode 100755 index 0000000..77524e7 --- /dev/null +++ b/crontabbackupdaily/backup.sh @@ -0,0 +1,46 @@ +#!/bin/bash +# simple backup script for everyday cron execution +# after execution `crontab -e` add new line to crontab schedule: +# @daily sh /home/user/backup.sh + +# files and dirs for backup: +backups[0]=/home/user/some.file +backups[1]=/home/user/somedir +# dir for archives: +SAVEDIR=/home/user/archive/ +# number of days for backup +DAYS=5 +WEEKS=10 + +# create archive with file name 'arc.tar.gz' +tar -cvzf ${SAVEDIR}arc.tar.gz ${backups[*]} + +# save last WEEKS +if [ -e ${SAVEDIR}arc-w1.tar.gz ] +then + oneweek=${SAVEDIR}arc-w1.tar.gz + oneweekripen=`find ${SAVEDIR}arc-w1.tar.gz -type f -mtime +10` + echo $oneweek + echo $oneweekripen + if [ "$oneweek" = "$oneweekripen" ] + then + for ((a=WEEKS; a >= 2 ; a--)) + do + let b=a-1 + mv ${SAVEDIR}arc-w${b}.tar.gz ${SAVEDIR}arc-w${a}.tar.gz + done + mv ${SAVEDIR}arc-d5.tar.gz ${SAVEDIR}arc-w1.tar.gz + fi +else + mv ${SAVEDIR}arc-d5.tar.gz ${SAVEDIR}arc-w1.tar.gz +fi + +# save last DAYS +for ((a=DAYS; a >= 2 ; a--)) +do + let b=a-1 + mv ${SAVEDIR}arc-d${b}.tar.gz ${SAVEDIR}arc-d${a}.tar.gz +done +mv ${SAVEDIR}arc.tar.gz ${SAVEDIR}arc-d1.tar.gz + +exit 0 diff --git a/pylogextractor/README.md b/pylogextractor/README.md new file mode 100644 index 0000000..c7fd444 --- /dev/null +++ b/pylogextractor/README.md @@ -0,0 +1,11 @@ +### pyLogExtractor + +Simple tool for extracting specific strings from log files. +It could be useful for extracting all warnings or errors from +debug log or all specific user quotes from chat log. + +pyLogExtractor requires Python 3. + +Using: + +Run python script, enter source path, path for save, and substring for searching. diff --git a/pylogextractor/logextractor.py b/pylogextractor/logextractor.py new file mode 100755 index 0000000..71d281d --- /dev/null +++ b/pylogextractor/logextractor.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import os +import re +import codecs + +globalvars = { + "version": "0.92" +} + +def searchuri(): + prompt = ("File or directory for searching ["+ + os.path.abspath(os.curdir)+"]:") + uri = input (prompt) + if uri == "": + uri = os.path.abspath(os.curdir) + return uri + if os.path.exists(uri): + if os.access(uri, os.R_OK): + return uri + else: + print ("You don't have permission to read "+uri+ + ". Try to change privileges or type another path.") + return searchuri() + else: + print ("File or directory not found. Plese type correct path.") + return searchuri() + +def writefile(): + prompt = ("File for writing[dump]:") + filename = input (prompt) + if filename == "": + filename = "dump" + try: + filedump = open(filename, 'x') + filedump.close() + return filename + except FileExistsError: + try: + filedump = open(filename, 'a') + filedump.close() + return filename + except PermissionError: + print ("You don't have permission to write "+filename) + return writefile() + except PermissionError: + print ("You don't have permission to write "+filename) + return writefile() + +def substring(): + prompt = ("Enter substring for search:") + substr = input (prompt) + if substr == "": + return substring() + return substr + +if __name__ == "__main__": + print ("pyLogExtractor v",globalvars["version"]) + uri = searchuri() + if os.path.isfile(uri): + print ("File for search: "+os.path.abspath(uri)) + elif os.path.isdir(uri): + filesnumber = 0 + for top, dirs, files in os.walk(uri): + filesnumber = (filesnumber + (len(files))) + print ("Directory for search: "+os.path.abspath(uri)+ + " ("+str(filesnumber)+" files)") + filename = writefile() + print ("File for writing: "+filename) + substr = substring() + print ("Substring: "+substr) + + filedump = open(filename, 'a') + stringsnumber = 0 + if os.path.isdir(uri): + for top, dirs, files in os.walk(uri): + for nm in files: + with codecs.open(os.path.join(top, nm), "r", + encoding='utf-8', errors='ignore') as openedfile: + for currentstring in openedfile: + if currentstring.find(substr) > 0: + currentstring = (re.split(r': ',(re.sub(r'\<[^>]*\>', + '', currentstring))))[-1] + currentstring = (re.split(r'> ',(re.sub(r'\<[^>]*\>', + '', currentstring))))[-1] + filedump.write(currentstring.rstrip() + '\n') + stringsnumber = stringsnumber + 1 + openedfile.close() + elif os.path.isfile(uri): + print ("sdf") + with codecs.open(uri, "r", + encoding='utf-8', errors='ignore') as openedfile: + for currentstring in openedfile: + if currentstring.find(substr) > 0: + currentstring = (re.split(r': ',(re.sub(r'\<[^>]*\>', + '', currentstring))))[-1] + currentstring = (re.split(r'> ',(re.sub(r'\<[^>]*\>', + '', currentstring))))[-1] + filedump.write(currentstring.rstrip() + '\n') + stringsnumber = stringsnumber + 1 + openedfile.close() + filedump.close() + print (stringsnumber," strings added.") diff --git a/restartprocesspage/README.md b/restartprocesspage/README.md new file mode 100644 index 0000000..4d73391 --- /dev/null +++ b/restartprocesspage/README.md @@ -0,0 +1,3 @@ +### restartprocesspage + +Web page for restart some process \ No newline at end of file diff --git a/restartprocesspage/index.html b/restartprocesspage/index.html new file mode 100644 index 0000000..ef72737 --- /dev/null +++ b/restartprocesspage/index.html @@ -0,0 +1,18 @@ + + + + + + +

+ + + diff --git a/restartprocesspage/start.sh b/restartprocesspage/start.sh new file mode 100755 index 0000000..1a52cb3 --- /dev/null +++ b/restartprocesspage/start.sh @@ -0,0 +1,4 @@ +#!/bin/bash +pkill "part_of_process_name" +delay 2 +process_exec -param diff --git a/restartprocesspage/touch.php b/restartprocesspage/touch.php new file mode 100644 index 0000000..be1d25a --- /dev/null +++ b/restartprocesspage/touch.php @@ -0,0 +1,6 @@ +