init from 4 old repositories

This commit is contained in:
ivan 2019-08-05 16:07:57 +03:00
parent c750e17675
commit fa1425a67b
20 changed files with 378 additions and 2 deletions

View File

@ -1,3 +1,6 @@
# variousscripts
Simple scripts for different purposes
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

View File

@ -0,0 +1,4 @@
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://192.168.1.127/$1 [R,L]
Options +Indexes

View File

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

View File

@ -0,0 +1,2 @@
# User privilege specification
www-data ALL=(ALL) /usr/bin/veracrypt, /usr/bin/phpreboot, /usr/bin/phphalt

View File

@ -0,0 +1,8 @@
<?php
if ($_GET["pass"] == "simplepass") {
shell_exec('echo www-data-password | sudo -S /usr/bin/phphalt');
echo "Shutdown...please wait";
} else echo "wrong password";
?>

View File

@ -0,0 +1,91 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Control page</title>
</head>
<body>
Status: <b id="status"></b>
<br><br>
<input type="button" onclick="checkStatus();" value="Check status"/>
<input id="pwdButton" type="button" onclick="password();" value="Enter password"/>
<input type="button" onclick="rebootS();" value="Reboot"/>
<input type="button" onclick="haltS();" value="Shutdown"/>
<script type="text/javascript">
var waitState = "false";
function checkStatus() {
var xhr = new XMLHttpRequest();
xhr.open('GET', 'status.php');
xhr.send(null);
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200) {
xhr.responseText.split('\n').forEach(function(line) {
if (waitState == "true") { document.getElementById("status").innerHTML = "<font color=red>wait ... </font>" + line }
else { document.getElementById("status").innerHTML = line; }
})
}
}
}
function password() {
var answer = prompt('Enter password', '');
if (!((answer == null) || (answer == ''))) {
document.getElementById("pwdButton").disabled = true;
document.getElementById("status").innerHTML = "<font color=red>wait</font>";
waitState = "true";
var xhr = new XMLHttpRequest();
xhr.open('GET', 'password.php?pass=' + answer);
xhr.send(null);
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200) {
xhr.responseText.split('\n').forEach(function(line) {
document.getElementById("status").innerHTML = line;
document.getElementById("pwdButton").disabled = false;
waitState = "false";
})
}
document.getElementById("status").innerHTML = "";
document.getElementById("pwdButton").disabled = false;
waitState = "false";
checkStatus();
}
}
}
function rebootS() {
var answerpw = prompt('Enter password for reboot', '');
if (!((answerpw == null) || (answerpw == ''))) {
var xhr = new XMLHttpRequest();
xhr.open('GET', 'reboot.php?pass=' + answerpw);
xhr.send(null);
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200) {
xhr.responseText.split('\n').forEach(function(line) {
document.getElementById("status").innerHTML = line;
})
}
}
}
}
function haltS() {
var answerpw = prompt('Enter password for sutdown', '');
if (!((answerpw == null) || (answerpw == ''))) {
var xhr = new XMLHttpRequest();
xhr.open('GET', 'halt.php?pass=' + answerpw);
xhr.send(null);
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200) {
xhr.responseText.split('\n').forEach(function(line) {
document.getElementById("status").innerHTML = line;
})
}
}
}
}
</script>
</body>
</html>

View File

@ -0,0 +1,6 @@
<?php
$p = "vcmnt.sh ".$_GET["pass"];
echo exec($p);
?>

View File

@ -0,0 +1,8 @@
<?php
if ($_GET["pass"] == "simplepass") {
echo "Rebooting...";
shell_exec('echo www-data-password | sudo -S /usr/bin/phpreboot');
} else echo "wrong password";
?>

View File

@ -0,0 +1,12 @@
<?php
$mountCheck = "ls /media/veracrypt/check/";
// if file 'accept' exists, then disk is mounted
if (exec($mountCheck) == 'accept') $mountStatus = "mounted";
else $mountStatus = "dismounted";
$result = $mountStatus;
echo $result;
?>

View File

@ -0,0 +1,10 @@
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
int main() {
setuid(0);
char *command = "/sbin/shutdown";
execl(command, command, NULL);
return 0;
}

View File

@ -0,0 +1,10 @@
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
int main() {
setuid(0);
char *command = "/sbin/reboot";
execl(command, command, NULL);
return 0;
}

View File

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

View File

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

46
crontabbackupdaily/backup.sh Executable file
View File

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

11
pylogextractor/README.md Normal file
View File

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

104
pylogextractor/logextractor.py Executable file
View File

@ -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'&gt; ',(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'&gt; ',(re.sub(r'\<[^>]*\>',
'', currentstring))))[-1]
filedump.write(currentstring.rstrip() + '\n')
stringsnumber = stringsnumber + 1
openedfile.close()
filedump.close()
print (stringsnumber," strings added.")

View File

@ -0,0 +1,3 @@
### restartprocesspage
Web page for restart some process

View File

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<h1 id="res"></h1>
<script type="text/javascript">
var answer = prompt('Enter "yes" if you want to restart process');
if (answer == "yes") {
var tch = new XMLHttpRequest();
tch.open('GET', 'touch.php');
tch.send(null);
document.getElementById("res").innerHTML = "Process was restarted";
} else document.getElementById("res").innerHTML = "Process was not restarted";
</script>
</body>
</html>

4
restartprocesspage/start.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
pkill "part_of_process_name"
delay 2
process_exec -param

View File

@ -0,0 +1,6 @@
<?php
$e = "/var/www/restart/start.sh";
shell_exec("$e");
?>