Switch to PHP
This commit is contained in:
@@ -16,8 +16,7 @@
|
||||
sudo apt update
|
||||
sudo apt dist-upgrade -y
|
||||
sudo apt update
|
||||
sudo apt install acl git-core screen rsync exfat-fuse exfat-utils ntfs-3g gphoto2 libimage-exiftool-perl dialog python3-pip minidlna -y
|
||||
sudo pip3 install bottle
|
||||
sudo apt install acl git-core screen rsync exfat-fuse exfat-utils ntfs-3g gphoto2 libimage-exiftool-perl dialog php7.1 minidlna -y
|
||||
|
||||
echo "------------------------------------"
|
||||
echo "Creating the required directories..."
|
||||
@@ -70,17 +69,17 @@ case $CHOICE in
|
||||
1)
|
||||
crontab -l | { cat; echo "#@reboot sudo /home/"$USER"/little-backup-box/scripts/card-backup.sh >> /home/"$USER"/little-backup-box.log 2>&1"; } | crontab
|
||||
crontab -l | { cat; echo "#@reboot sudo /home/"$USER"/little-backup-box/scripts/camera-backup.sh >> /home/"$USER"/little-backup-box.log 2>&1"; } | crontab
|
||||
crontab -l | { cat; echo "@reboot sudo /home/"$USER"/little-backup-box/scripts/rc.sh >> /home/"$USER"/little-backup-box.log 2>&1"; } | crontab
|
||||
crontab -l | { cat; echo "@reboot sudo /home/"$USER"/little-backup-box/scripts/php.sh >> /home/"$USER"/little-backup-box.log 2>&1"; } | crontab
|
||||
;;
|
||||
2)
|
||||
crontab -l | { cat; echo "@reboot sudo /home/"$USER"/little-backup-box/scripts/card-backup.sh >> /home/"$USER"/little-backup-box.log 2>&1"; } | crontab
|
||||
crontab -l | { cat; echo "#@reboot sudo /home/"$USER"/little-backup-box/scripts/camera-backup.sh >> /home/"$USER"/little-backup-box.log 2>&1"; } | crontab
|
||||
crontab -l | { cat; echo "#@reboot sudo /home/"$USER"/little-backup-box/scripts/rc.sh >> /home/"$USER"/little-backup-box.log 2>&1"; } | crontab
|
||||
crontab -l | { cat; echo "#@reboot sudo /home/"$USER"/little-backup-box/scripts/php.sh >> /home/"$USER"/little-backup-box.log 2>&1"; } | crontab
|
||||
;;
|
||||
3)
|
||||
crontab -l | { cat; echo "#@reboot sudo /home/"$USER"/little-backup-box/scripts/card-backup.sh >> /home/"$USER"/little-backup-box.log 2>&1"; } | crontab
|
||||
crontab -l | { cat; echo "@reboot sudo /home/"$USER"/little-backup-box/scripts/camera-backup.sh >> /home/"$USER"/little-backup-box.log 2>&1"; } | crontab
|
||||
crontab -l | { cat; echo "#@reboot sudo /home/"$USER"/little-backup-box/scripts/rc.sh >> /home/"$USER"/little-backup-box.log 2>&1"; } | crontab
|
||||
crontab -l | { cat; echo "#@reboot sudo /home/"$USER"/little-backup-box/scripts/php.sh >> /home/"$USER"/little-backup-box.log 2>&1"; } | crontab
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
41
rc/exit.tpl
41
rc/exit.tpl
@@ -1,41 +0,0 @@
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<style>
|
||||
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
|
||||
|
||||
p.left {
|
||||
text-align: left;
|
||||
}
|
||||
p.center {
|
||||
text-align: center;
|
||||
}
|
||||
img {
|
||||
display: block;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
#content {
|
||||
font: 1em/1.5em 'Lato', sans-serif;
|
||||
margin: 0px auto;
|
||||
width: 275px;
|
||||
text-align: center;
|
||||
}
|
||||
#dialog {
|
||||
width: auto; height: auto;
|
||||
background: #009933;
|
||||
border-radius: 5px;
|
||||
color: #fff;
|
||||
font-family: 'Lato', sans-serif; font-size: 17px;
|
||||
padding-right: 0.5em;
|
||||
padding-left: 0.5em;
|
||||
padding-top: 0.5em;
|
||||
padding-bottom: 0.5em;
|
||||
border:none;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<title>Little Backup Box</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<div id="content">
|
||||
<div id="dialog">Command sent. You can close this page.</div>
|
||||
</div>
|
||||
43
rc/rc.py
43
rc/rc.py
@@ -1,43 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from bottle import post, route, request, template, static_file, run
|
||||
import os, subprocess
|
||||
|
||||
@route('/')
|
||||
@route('/', method='POST')
|
||||
def remote_control():
|
||||
st_home = os.statvfs("/home")
|
||||
free_home = "%.2f" % float((st_home.f_bavail * st_home.f_frsize)/1.073741824e9)
|
||||
|
||||
if (request.POST.get("cardbackup")):
|
||||
process = subprocess.Popen("sudo /home/pi/little-backup-box/scripts/card-backup.sh", shell=True)
|
||||
return template('exit.tpl')
|
||||
if (request.POST.get("camerabackup")):
|
||||
process = subprocess.Popen("sudo /home/pi/little-backup-box/scripts/camera-backup.sh", shell=True)
|
||||
return template('exit.tpl')
|
||||
if (request.POST.get("devicebackup")):
|
||||
process = subprocess.Popen("sudo /home/pi/little-backup-box/scripts/device-backup.sh", shell=True)
|
||||
return template('exit.tpl')
|
||||
if (request.POST.get("shutdown")):
|
||||
process = subprocess.Popen("sudo shutdown -h now", shell=True)
|
||||
return template('exit.tpl')
|
||||
return template('rc.tpl', freespace_home=free_home)
|
||||
|
||||
@route('/static/:path#.+#', name='static')
|
||||
def static(path):
|
||||
return static_file(path, root='static')
|
||||
|
||||
run(host="0.0.0.0", port=8080, debug=True, reloader=True)
|
||||
59
rc/rc.tpl
59
rc/rc.tpl
@@ -1,59 +0,0 @@
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<style>
|
||||
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
|
||||
|
||||
p.left {
|
||||
text-align: left;
|
||||
}
|
||||
p.center {
|
||||
text-align: center;
|
||||
}
|
||||
img {
|
||||
display: block;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
#content {
|
||||
font: 1em/1.5em 'Lato', sans-serif;
|
||||
margin: 0px auto;
|
||||
width: 275px;
|
||||
text-align: left;
|
||||
}
|
||||
#header {
|
||||
font: bold 1.7em/2em 'Lato', sans-serif;
|
||||
text-align: center;
|
||||
}
|
||||
#btn {
|
||||
width: 11em; height: 2em;
|
||||
background: #3399ff;
|
||||
border-radius: 5px;
|
||||
color: #fff;
|
||||
font-family: 'Lato', sans-serif; font-size: 25px; font-weight: 900;
|
||||
letter-spacing: 3px;
|
||||
border:none;
|
||||
}
|
||||
#btn.orange {
|
||||
background: #ff9900;
|
||||
}
|
||||
#btn.red {
|
||||
background: #cc0000;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<title>Little Backup Box</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<form method="POST" action="/">
|
||||
<div id="content">
|
||||
<div id="header"><img src="static/ichigo.svg" height="39px" alt="Ichigo" align=""> Little Backup Box</div>
|
||||
<p class="center">Free disk space on <i>/home</i>: <b>{{freespace_home}}</b> GB</p>
|
||||
<hr>
|
||||
<p class="left">Back up a storage card connected via a card reader</p>
|
||||
<p><input id="btn" name="cardbackup" type="submit" value="Card backup"></p>
|
||||
<p class="left">Transfer files directly from the connected camera</p>
|
||||
<p><input id="btn" name="camerabackup" type="submit" value="Camera backup"></p>
|
||||
<p class="left">Back up files from the internal storage to an external storage device</p>
|
||||
<p><input id="btn" class="orange" name="devicebackup" type="submit" value="Device backup"></p>
|
||||
<p class="left">Shut down the Little Backup Box</p>
|
||||
<p><input id="btn" class="red" name="shutdown" value="Shut down" type="submit" /></p>
|
||||
</div>
|
||||
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
104
scripts/index.php
Normal file
104
scripts/index.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<html lang="en">
|
||||
<!-- Author: Dmitri Popov, dmpop@linux.com
|
||||
License: GPLv3 https://www.gnu.org/licenses/gpl-3.0.txt -->
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
<style>
|
||||
|
||||
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
|
||||
|
||||
p.left {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
p.center {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
img {
|
||||
display: block;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
#content {
|
||||
font: 1em/1.5em 'Lato', sans-serif;
|
||||
margin: 0px auto;
|
||||
width: 275px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
#header {
|
||||
font: bold 1.7em/2em 'Lato', sans-serif;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#btn {
|
||||
width: 11em;
|
||||
height: 2em;
|
||||
background: #3399ff;
|
||||
border-radius: 5px;
|
||||
color: #fff;
|
||||
font-family: 'Lato', sans-serif;
|
||||
font-size: 25px;
|
||||
font-weight: 900;
|
||||
letter-spacing: 3px;
|
||||
border: none;
|
||||
}
|
||||
|
||||
#btn.orange {
|
||||
background: #ff9900;
|
||||
}
|
||||
|
||||
#btn.red {
|
||||
background: #cc0000;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<title>Little Backup Box</title>
|
||||
|
||||
<div id="content">
|
||||
<div id="header"><img src="ichigo.svg" height="39px" alt="Ichigo" align=""> Little Backup Box</div>
|
||||
<hr>
|
||||
<p class="left">Back up a storage card connected via a card reader</p>
|
||||
<p>
|
||||
<form method="post">
|
||||
<button id="btn" name="cardbackup">Card backup</button>
|
||||
</form>
|
||||
</p>
|
||||
<p class="left">Transfer files directly from the connected camera</p>
|
||||
<p>
|
||||
<form method="post">
|
||||
<button id="btn" class="orange" name="camerabackup">Camera backup</button>
|
||||
</form>
|
||||
</p>
|
||||
<p class="left">Shut down the Little Backup Box</p>
|
||||
<p>
|
||||
<form method="post">
|
||||
<button id="btn" class="red" name="shutdown">Shut down</button>
|
||||
</form>
|
||||
</p>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
<?php
|
||||
if (isset($_POST['cardbackup']))
|
||||
{
|
||||
shell_exec('sudo ./card-backup.sh');
|
||||
}
|
||||
if (isset($_POST['camerabackup']))
|
||||
{
|
||||
shell_exec('sudo ./camera-backup.sh');
|
||||
}
|
||||
if (isset($_POST['shutdown']))
|
||||
{
|
||||
shell_exec('sudo shutdown -h now');
|
||||
}
|
||||
?>
|
||||
6
scripts/rc.sh → scripts/php.sh
Executable file → Normal file
6
scripts/rc.sh → scripts/php.sh
Executable file → Normal file
@@ -17,8 +17,8 @@
|
||||
|
||||
while :
|
||||
do
|
||||
if [[ ! $(pgrep -f rc.py) ]]; then
|
||||
cd /home/pi/little-backup-box/rc/
|
||||
sudo python3 rc.py
|
||||
if [[ ! $(pgrep php) ]]; then
|
||||
cd /home/$USER/little-backup-box/script/
|
||||
php -S localhost:8000
|
||||
fi
|
||||
done
|
||||
Reference in New Issue
Block a user