Skip to content
Snippets Groups Projects
Commit d07185b6 authored by Bob Mottram's avatar Bob Mottram
Browse files

Add rsync settings screen

parent d9b61c88
No related branches found
No related tags found
No related merge requests found
......@@ -54,6 +54,31 @@ RSYNC_MOBILE_APP_URL=https://f-droid.org/wiki/page/org.amoradi.syncopoli
rsync_variables=(ONION_ONLY
MY_USERNAME)
function rsync_setting_remote {
rsync_hostname="$1"
rsync_module="$2"
# Some sanity checks to ensure that the input is valid
if [[ "$rsync_hostname" != *'.'* || "$rsync_hostname" == *'/'* || \
"$rsync_hostname" == *'$'* || "$rsync_hostname" == *';'* || \
"$rsync_hostname" == *'\n'* || "$rsync_module" == *'\n'* || \
"$rsync_module" == *';'* || "$rsync_module" == *'$'* ]]; then
return
fi
{ echo '#!/bin/bash';
echo "cd $RSYNC_DATA || exit 1";
echo "if torsocks rsync -arm ${rsync_hostname}::${rsync_module}/ $RSYNC_DATA; then";
echo " ${PROJECT_NAME}-notification -s 'rsync succeeded' -m 'Sync with ${rsync_hostname}::${rsync_module} succeeded'";
echo 'else';
echo " ${PROJECT_NAME}-notification -s 'rsync failed' -m 'Sync with ${rsync_hostname}::${rsync_module} failed'";
echo 'fi';
echo "chown -R rsync:rsync $RSYNC_DATA"; } > /etc/rsync/sync.sh
chmod +x /etc/rsync/sync.sh
chown rsync:rsync /etc/rsync/sync.sh
/etc/rsync/sync.sh &
}
function change_default_domain_name_rsync {
new_default_domain_name="$1"
# If anything references DEFAULT_DOMAIN_NAME then change it here
......@@ -153,15 +178,22 @@ function install_rsync {
mkdir /etc/rsync
fi
rsync_translated_str=$(web_admin_translate_text "Files on your local network")
{ echo 'pid file = /var/run/rsyncd.pid';
echo 'lock file = /var/run/rsync.lock';
echo 'log file = /dev/null';
echo "port = $RSYNC_PORT";
echo 'max connections = 2';
echo 'fake super = yes';
echo '';
echo '[files]';
echo 'hosts allow = 192.168.0.0/16;10.0.0.0/16';
echo 'hosts deny = *';
echo 'list = true';
echo "path = $RSYNC_DATA";
echo 'comment = RSYNC FILES';
echo 'read only = true';
echo "comment = $rsync_translated_str";
echo 'read only = false';
echo 'timeout = 300'; } > /etc/rsync/rsyncd.conf
increment_app_install_progress
......@@ -186,7 +218,7 @@ function install_rsync {
echo 'User=rsync';
echo 'Group=rsync';
echo "WorkingDirectory=$RSYNC_DATA";
echo 'ExecStart=/usr/bin/rsync --config=/etc/rsync/rsyncd.conf --daemon';
echo 'ExecStart=/usr/bin/rsync --config=/etc/rsync/rsyncd.conf --bwlimit=100K --daemon';
echo 'Environment=USER=rsync';
echo 'Restart=always';
echo 'StandardError=syslog';
......
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<style>
body {
margin: 0;
font-family: Arial;
background-color: white;
color: black;
}
* {
box-sizing: border-box;
}
a, u {
text-decoration: none;
color: #72a7cf;
font-weight: bold;
}
a:visited{
color: #72a7cf;
font-weight: bold;
}
#headerpic {
width: 60%;
height: auto;
margin-right : auto;
margin-left : auto;
min-width : 220px;
}
.header {
text-align: center;
padding: 32px;
}
.headertext {
color: #72a7cf;
text-align: center;
font-size: 120%;
font-weight: bold;
}
.settingtext {
text-align: center;
font-size: 100%;
}
.row {
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
padding: 0 4px;
}
.column {
-ms-flex: 25%;
flex: 15%;
max-width: 25%;
padding: 0 4px;
}
.column img {
margin-top: 8px;
vertical-align: middle;
}
.card {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
max-width: 600px;
margin: auto;
text-align: center;
font-family: arial;
clear: both;
}
.card input[type=text] {
width: 100%;
clear: both;
text-align: left;
color: black;
background-color: lightblue;
}
</style>
<body>
<div class="card">
<div class="header">
<a href="app_rsync.html" title="Go Back"><img id="headerpic" class="img-responsive" src="images/logo.png" alt="Go Back"></a>
<p class="headertext" translate="yes">rsync</p>
<p class="settingtext">
<form action="settings_rsync.php" method="post">
<p translate="yes">Source hostname</p>
<input type="text" name="rsync_hostname" translate="no" value="freedombone.net">
<br><br>
<p translate="yes">module</p>
<input type="text" name="rsync_module" translate="no" value="images">
<br><br>
<input type="submit" name="submitrsync" translate="yes" value="Continue" />
</form>
</p>
</div>
</div>
</body>
</html>
<?php
// _____ _ _
// | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
// | __| _| -_| -_| . | . | | . | . | | -_|
// |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
//
// Freedom in the Cloud
//
// rsync settings menu
//
// License
// =======
//
// Copyright (C) 2018-2019 Bob Mottram <bob@freedombone.net>
//
// 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 <http://www.gnu.org/licenses/>.
$output_filename = "app_rsync.html";
if (isset($_POST['submitrsync'])) {
$rsync_hostname = htmlspecialchars($_POST['rsync_hostname']);
if (strpos($rsync_hostname, ' ') === false) {
if (strpos($rsync_hostname, '.') === true) {
$rsync_module = htmlspecialchars($_POST['rsync_module']);
if (strpos($rsync_module, ' ') === false) {
$settings_file = fopen(".appsettings.txt", "w") or die("Unable to write to appsettings file");
fwrite($settings_file, "rsync,remote,".$rsync_hostname.",".$rsync_module);
fclose($settings_file);
}
}
}
}
$htmlfile = fopen("$output_filename", "r") or die("Unable to open $output_filename");
echo fread($htmlfile,filesize("$output_filename"));
fclose($htmlfile);
?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment