commit b960c387e5c1f2c46fa31284923fcd984b64ebd0 Author: Fizzgig Date: Sat Aug 16 06:45:14 2025 -0400 commit version 1.1 diff --git a/README.md b/README.md new file mode 100644 index 0000000..b6add3a --- /dev/null +++ b/README.md @@ -0,0 +1,22 @@ +About FileSync + +FileSync is designed to store a backup of your file(s) on remote servers. + +Due to the limitations of php script timeout files should be small. For example: 6 SSL keys zipped to a file is around 90kb. This is small enough to use for this. +Do not try to backup files that are several mbs. It may not work correctly. +How it works + + Unpack FileSync.zip to a folder on your server. For example: https://example.com/filesync/ + Add the other servers that you will link to in the server list. + When you upload a file to your server it will also send the file to the linked servers. + You can upload a new version of the file at a later time. It will also update the linked servers. + +File status + + ✔ - Good - Multiple servers have a backup of this file. + + ⚠ - Warning - You do not have a backup of this file locally. + To resolve: Use the download button to get the file from a remote server. Then re-upload that file. + + ✖ - Critical - No other servers have a backup of this file. + To resolve: You should contact the other admins to resolve server availability. Then try to upload the file again. \ No newline at end of file diff --git a/config.php b/config.php new file mode 100644 index 0000000..aa5681a --- /dev/null +++ b/config.php @@ -0,0 +1,30 @@ + 'filesync.sqlite', //'kro_server', + 'host' => 'localhost', + 'user' => '', + 'pass' => '' + ]; + + return isset($database[$key]) ? $database[$key] : null; +} + //Table Config + function table($key='', $link=''){ + $table=[ + 'FILE_TABLE'=>'filesync' + ]; + + return isset($table[$key]) ? $table[$key] : null; + } +?> \ No newline at end of file diff --git a/filesync.sqlite b/filesync.sqlite new file mode 100644 index 0000000..3fa93c0 Binary files /dev/null and b/filesync.sqlite differ diff --git a/includes/DB_MYSQL.php b/includes/DB_MYSQL.php new file mode 100644 index 0000000..239a713 --- /dev/null +++ b/includes/DB_MYSQL.php @@ -0,0 +1,17 @@ +=0){ + mysqli_data_seek($result,$i); + $data = (is_numeric($field)) ? mysqli_fetch_row($result) : mysqli_fetch_assoc($result); + if (isset($data[$field])){ return $data[$field]; } + } + return false; +} +?> \ No newline at end of file diff --git a/includes/DB_SQLITE.php b/includes/DB_SQLITE.php new file mode 100644 index 0000000..8ac14d7 --- /dev/null +++ b/includes/DB_SQLITE.php @@ -0,0 +1,19 @@ +close();} +function DBquery($link,$query){return $link->query($query);} +function DBnum_rows($result){$n=0; while($result->fetchArray()){$n++;} return $n;} +function DBresult($result,$i=0,$field=0){ + $n=0; + $value = false; + while ($row = $result->fetchArray()) { + if($n==$i){if(isset($row[$field])){$value=$row[$field];}} + $n++; + } + return $value; +} +?> \ No newline at end of file diff --git a/includes/isMobile.php b/includes/isMobile.php new file mode 100644 index 0000000..70e7776 --- /dev/null +++ b/includes/isMobile.php @@ -0,0 +1,25 @@ + \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..769148d --- /dev/null +++ b/index.php @@ -0,0 +1,405 @@ + 'ping', 'ip'=>$ip)); + + if(CheckVersion($content) && $server!=$SITE_URL){ + //store server + $query="INSERT INTO ".table('FILE_TABLE')." VALUES ('$id', 2, '$ip', '', '', '', '$server')"; DBquery($link,$query); + $server_list[count($server_list)]=$server; + + $s_output = "The server was added.
"; + $server=''; + } + else{$s_output = "Error. The server could not be added.
";} + + break; + case 'deleteserver': + $tab='settings'; + + foreach($server_list as $s){ + if(isset($_POST['del_'.FILTER_('.',$s)])){ + $query="DELETE FROM ".table('FILE_TABLE')." WHERE url='$s'"; DBquery($link,$query); + break; + } + } + + //Get Server List + $server_list=array(); + $server_list[0]=$SITE_URL; + $query="SELECT * FROM ".table('FILE_TABLE')." WHERE type = 2"; + $result = DBquery($link,$query); $rows = DBnum_rows($result); + for($i=0;$i<$rows;$i++){$server_list[$i+1]=DBresult($result,$i,'url');} + + break; + case 'file': + if($_POST['request'] == $SITE_URL){ + //Close Database + DBclose($link); + exit(); + } + + //Upload Algorythm + //1:get user from db + if(isset($_POST['user'])){$user = $_POST['user'];} + + if($user==''){$f_output="Error. User not result.
";} + else{ + //Create Paths + $target_path = "save/"; + $target_path = FILTER_SPACES($target_path .$user."-". basename( $_FILES['uploadedfile']['name'])); + + $store_path = "save/store/"; + $store_path = FILTER_SPACES($store_path .$user."-". basename( $_FILES['uploadedfile']['name'])); + + //2a:Backup the old file if it exists + if(file_exists($target_path)){rename($target_path, $store_path);} + //2b:copy the new file to the storage folder + if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { + $f_output="The file ". basename( $_FILES['uploadedfile']['name'])." has been uploaded
"; + //2c:insert the file record + $query="DELETE FROM ".table('FILE_TABLE')." WHERE user='$user' AND file='".basename( $_FILES['uploadedfile']['name'])."'"; DBquery($link,$query); + $query="INSERT INTO ".table('FILE_TABLE')." VALUES ('$id', 3, '$ip', '$user', '".basename( $_FILES['uploadedfile']['name'])."', '$id', '')"; DBquery($link,$query); + } + else{$f_output="There was an error uploading the file, please try again!
";} + + //3:send file/post data to the servers + $post=array('formid'=>'file', 'user'=>$user, 'ip'=>$ip, 'time'=>$id, 'uploadedfile'=>new CurlFile($target_path, '', $_FILES['uploadedfile']['name']),'request'=>$SITE_URL); + foreach ($server_list as $s) {curl($s, $post);} + } + break; + case 'deletefile': + if($_POST['request'] == $SITE_URL){ + //Close Database + DBclose($link); + exit(); + } + + if(isset($_POST['user'])){$user = $_POST['user'];} + + $query="SELECT * FROM ".table('FILE_TABLE')." WHERE type = 3"; + $result = DBquery($link,$query); $rows = DBnum_rows($result); + for($i=0;$i<$rows;$i++){ + if(isset($_POST['del_'.FILTER_('.', DBresult($result,$i,'file'))])){break;} + } + if($i<$rows){ + $filename=DBresult($result,$i,'file'); + $query="DELETE FROM ".table('FILE_TABLE')." WHERE user='$user' AND file='".$filename."'"; DBquery($link,$query); + + $post=array('formid'=>'deletefile', 'user'=>$user, 'ip'=>$ip, 'time'=>$id, 'del_'.FILTER_('.',$filename)=>'X', 'request'=>$SITE_URL); + foreach ($server_list as $s) {curl($s, $post);} + + } + + break; + } + } + + //Build File List + if($user!=''){ + $post=array('formid'=>'list', 'user'=>$user, 'ip'=>$ip, 'time'=>time()); + foreach ($server_list as $s) { + $content = explode('|',curl($s, $post)); + if(count($content)>=2){ + + switch($s==$SITE_URL){ + case true: + for($i=0;$i$content[$i], 'time'=>$content[$i+1], 'server'=>$s, 'status'=>1);} + } + break; + case false: + for($i=0;$i= 1){$f['status'] += 1; $file_list[$content[$i]] = $f;} + if($f['time'] > $content[$i+1]){$f['time'] = $content[$i+1]; $f['server'] = $s; $f['status'] = 0; $file_list[$content[$i]] = $f;} + } + else{ + //doesnt exist + if($content[$i]!=""){ + $file_list[$content[$i]]=array('file'=>$content[$i], 'time'=>$content[$i+1], 'server'=>$s, 'status'=>0); + } + } + } + break; + } + } + } + } + + //Set Tab State + $tab = $user=='' || count($server_list)<=1?'settings':$tab; + +//Close Database +DBclose($link); + +//Functions + function CheckVersion(string $check){ + $result=false; + foreach($GLOBALS['COMPATIBLE'] as $v){ + if($v==$check){$result=true; break;} + } + return $result; + } + function curl($url, $post){ + $handle=curl_init(); + curl_setopt($handle, CURLOPT_URL, $url); + curl_setopt($handle, CURLOPT_VERBOSE, true); + curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); + curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($handle, CURLOPT_POSTFIELDS, $post); + $content = curl_exec($handle); + curl_close($handle); + + return $content; + } + function ShortHash($hash){ + $arr = str_split($hash); + $start=0;$length=0; + foreach($arr as $c){ + if (is_numeric($c)) { + if($start==0){$start=(intval($c)<5?intval($c)+5:intval($c));} else{$length=(intval($c)<5?intval($c)+5:intval($c));} + if($length!=0){break;} + } + } + return substr($hash, $start, $length); + } + function FILTER_(string $search, string $string): string{return str_replace($search,'_',$string);} + function FILTER_SPACES(string $string): string{return str_replace(' ','_',$string);} + function FILTER_SANITIZE_STRING(string $string): string { return str_replace(["'", '"'], [''', '"'], preg_replace('/\x00|<[^>]*>?/', '', $string)); } +?> + + + + + + ':'';?> + + + + +
+ +

File Sync

+ + | | + +
+ + + + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/readme.html b/readme.html new file mode 100644 index 0000000..eedfd51 --- /dev/null +++ b/readme.html @@ -0,0 +1,27 @@ +

About FileSync

+

FileSync is designed to store a backup of your file(s) on remote servers.

+

Due to the limitations of php script timeout files should be small. For example: 6 SSL keys zipped to a file is around 90kb. This is small enough to use for this. +Do not try to backup files that are several mbs. It may not work correctly.

+ +

How it works

+
    +
  • Unpack FileSync.zip to a folder on your server. For example: https://example.com/filesync/
  • +
  • Add the other servers that you will link to in the server list.
  • +
  • When you upload a file to your server it will also send the file to the linked servers.
  • +
  • You can upload a new version of the file at a later time. It will also update the linked servers.
  • +
+ +

File status

+
    +
  • ✔ - Good - Multiple servers have a backup of this file. +

    +
  • +
  • ⚠ - Warning - You do not have a backup of this file locally.
    +To resolve: Use the download button to get the file from a remote server. Then re-upload that file. +

    +
  • +
  • ✖ - Critical - No other servers have a backup of this file.
    +To resolve: You should contact the other admins to resolve server availability. Then try to upload the file again. +

    +
  • +
\ No newline at end of file diff --git a/save/Place_Holder.txt b/save/Place_Holder.txt new file mode 100644 index 0000000..e69de29 diff --git a/save/store/Place_Holder.txt b/save/store/Place_Holder.txt new file mode 100644 index 0000000..e69de29 diff --git a/styles.css b/styles.css new file mode 100644 index 0000000..a215e7a --- /dev/null +++ b/styles.css @@ -0,0 +1,25 @@ +html,body { + background-color:#303030; + color:#CCCCCC; + margin:0; + font-family: "Lato", sans-serif; +} +.center {max-width: fit-content; margin: auto;} +h1{color:#CCCCCC;} +h2{color:#CCCCCC;} +h3{ + color:#CCCCCC; + margin-top: 0px; + margin-bottom: 0px; +} +input,button{background-color: #555555; color: #CCC;} +.form-button{background-color: #555555; color: #CCC; border-width:1px; border-style:solid; border-color:grey; margin-top: 8px;} +select{background-color: #555555; color: #CCC;} +.form-center{text-align:center;} +.form-element{display:flex;} +.form-input{border-width:1px; border-style:solid; border-color:grey; width:100%; font-family:arial; margin:2px; padding-left:2px;} +.form-error{border-width:1px; border-style:solid; border-color:red; width:100%; font-family:arial; margin:2px; padding-left:2px;} +.form-submit{color:#4caf50; font-family:arial; margin:2px;} +.left{text-align: left;} +.right{text-align: right;} +.click{cursor: pointer; text-decoration: underline;} \ No newline at end of file diff --git a/styles_m.css b/styles_m.css new file mode 100644 index 0000000..bcc64a3 --- /dev/null +++ b/styles_m.css @@ -0,0 +1,6 @@ +html {font-size:2.25em;} +button,input {font-size:1.25em;} +input[type=checkbox] { + transform: scale(1.25); + margin: 10px; +} \ No newline at end of file