1
0
Fork 0
This commit is contained in:
Ziver Koc 2010-11-04 15:40:50 +00:00
parent 629114bac5
commit bece225d84
5 changed files with 381 additions and 381 deletions

View file

@ -1,94 +1,94 @@
<?php
require_once("info.php");
/*
trigger_error("Incorrect input vector, array of values expected", E_USER_WARNING);
Value Constant Description
1 E_ERROR (integer) Fatal run-time errors. These indicate errors that can not be recovered from, such as a memory allocation problem. Execution of the script is halted.
2 E_WARNING (integer) Run-time warnings (non-fatal errors). Execution of the script is not halted.
4 E_PARSE (integer) Compile-time parse errors. Parse errors should only be generated by the parser.
8 E_NOTICE (integer) Run-time notices. Indicate that the script encountered something that could indicate an error, but could also happen in the normal course of running a script.
16 E_CORE_ERROR (integer) Fatal errors that occur during PHP's initial startup. This is like an E_ERROR, except it is generated by the core of PHP.
32 E_CORE_WARNING (integer) Warnings (non-fatal errors) that occur during PHP's initial startup. This is like an E_WARNING, except it is generated by the core of PHP.
64 E_COMPILE_ERROR (integer) Fatal compile-time errors. This is like an E_ERROR, except it is generated by the Zend Scripting Engine.
128 E_COMPILE_WARNING (integer) Compile-time warnings (non-fatal errors). This is like an E_WARNING, except it is generated by the Zend Scripting Engine.
256 E_USER_ERROR (integer) User-generated error message. This is like an E_ERROR, except it is generated in PHP code by using the PHP function trigger_error().
512 E_USER_WARNING (integer) User-generated warning message. This is like an E_WARNING, except it is generated in PHP code by using the PHP function trigger_error().
1024 E_USER_NOTICE (integer) User-generated notice message. This is like an E_NOTICE, except it is generated in PHP code by using the PHP function trigger_error().
2048 E_STRICT (integer) Run-time notices. Enable to have PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code.
4096 E_RECOVERABLE_ERROR (integer) Catchable fatal error. It indicates that a probably dangerous error occured, but did not leave the Engine in an unstable state. If the error is not caught by a user defined handle (see also set_error_handler()), the application aborts as it was an E_ERROR.
8191 E_ALL (integer) All errors and warnings, as supported, except of level E_STRICT in PHP < 6.
HTML
<div id="info" style="border:2px solid {'message_color_border'}; padding:5px;margin:10px;background:{'message_color'} none repeat scroll 0%;font-size:13px;">
<center>{'message'}</center>
</div>
*/
$errors = array();
set_error_handler("errorHandler");
register_shutdown_function("printErrors");
if(isset($language["error_unknown"])) $language["error_unknown"] = "Unknown Error Type";
if(isset($language["error"])) $language["error"] = "Error";
if(isset($language["warning"])) $language["warning"] = "Warning";
// error handler function
function errorHandler($errno, $errstr, $errfile, $errline){
GLOBAL $language,$errors;
$info = new Info();
switch ($errno) {
case E_ERROR:
case E_USER_ERROR:
$err = buildError($language["error"],$errno, $errstr, $errfile, $errline);
$errors[] = $info->buildMessage($err,"error");
//dbSaveLog(getURL(),$err,date("Y-m-d H:i:s"));
break;
case E_WARNING:
case E_USER_WARNING:
$err = buildError($language["warning"],$errno, $errstr, $errfile, $errline);
$errors[] = $info->buildMessage($err,"warning");
//dbSaveLog(getURL(),$err,date("Y-m-d H:i:s"));
break;
case E_NOTICE:
case E_USER_NOTICE:
//$err = buildError($language["error_unknown"],$errno, $errstr, $errfile, $errline);
//dbSaveLog(getURL(),$err,date("Y-m-d H:i:s"));
break;
default:
$err = buildError($language["error_unknown"],$errno, $errstr, $errfile, $errline);
$errors[] = $info->buildMessage($err,"error");
//dbSaveLog(getURL(),$err,date("Y-m-d H:i:s"));
break;
}
/* Don't execute PHP internal error handler */
return true;
}
function buildError($errhead,$errno, $errstr, $errfile, $errline){
GLOBAL $config;
//[$errno]
if(!isset($config["debug"]) || $config["debug"])
$error = "<strong>$errhead:</strong> $errfile($errline)<br /><b>$errstr</b>";
else
$error = "<strong>$errhead: </strong>$errstr";
return $error;
}
function getErrors(){
GLOBAL $errors;
if(empty($errors)) return "";
$temp = "";
foreach($errors as $one){
$temp .= $one;
}
$errors = array();
return $temp;
}
function printErrors(){
echo getErrors();
}
?>
<?php
require_once("info.php");
/*
trigger_error("Incorrect input vector, array of values expected", E_USER_WARNING);
Value Constant Description
1 E_ERROR (integer) Fatal run-time errors. These indicate errors that can not be recovered from, such as a memory allocation problem. Execution of the script is halted.
2 E_WARNING (integer) Run-time warnings (non-fatal errors). Execution of the script is not halted.
4 E_PARSE (integer) Compile-time parse errors. Parse errors should only be generated by the parser.
8 E_NOTICE (integer) Run-time notices. Indicate that the script encountered something that could indicate an error, but could also happen in the normal course of running a script.
16 E_CORE_ERROR (integer) Fatal errors that occur during PHP's initial startup. This is like an E_ERROR, except it is generated by the core of PHP.
32 E_CORE_WARNING (integer) Warnings (non-fatal errors) that occur during PHP's initial startup. This is like an E_WARNING, except it is generated by the core of PHP.
64 E_COMPILE_ERROR (integer) Fatal compile-time errors. This is like an E_ERROR, except it is generated by the Zend Scripting Engine.
128 E_COMPILE_WARNING (integer) Compile-time warnings (non-fatal errors). This is like an E_WARNING, except it is generated by the Zend Scripting Engine.
256 E_USER_ERROR (integer) User-generated error message. This is like an E_ERROR, except it is generated in PHP code by using the PHP function trigger_error().
512 E_USER_WARNING (integer) User-generated warning message. This is like an E_WARNING, except it is generated in PHP code by using the PHP function trigger_error().
1024 E_USER_NOTICE (integer) User-generated notice message. This is like an E_NOTICE, except it is generated in PHP code by using the PHP function trigger_error().
2048 E_STRICT (integer) Run-time notices. Enable to have PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code.
4096 E_RECOVERABLE_ERROR (integer) Catchable fatal error. It indicates that a probably dangerous error occured, but did not leave the Engine in an unstable state. If the error is not caught by a user defined handle (see also set_error_handler()), the application aborts as it was an E_ERROR.
8191 E_ALL (integer) All errors and warnings, as supported, except of level E_STRICT in PHP < 6.
HTML
<div id="info" style="border:2px solid {'message_color_border'}; padding:5px;margin:10px;background:{'message_color'} none repeat scroll 0%;font-size:13px;">
<center>{'message'}</center>
</div>
*/
$errors = array();
set_error_handler("errorHandler");
register_shutdown_function("printErrors");
if(isset($language["error_unknown"])) $language["error_unknown"] = "Unknown Error Type";
if(isset($language["error"])) $language["error"] = "Error";
if(isset($language["warning"])) $language["warning"] = "Warning";
// error handler function
function errorHandler($errno, $errstr, $errfile, $errline){
GLOBAL $language,$errors;
$info = new Info();
switch ($errno) {
case E_ERROR:
case E_USER_ERROR:
$err = buildError($language["error"],$errno, $errstr, $errfile, $errline);
$errors[] = $info->buildMessage($err,"error");
//dbSaveLog(getURL(),$err,date("Y-m-d H:i:s"));
break;
case E_WARNING:
case E_USER_WARNING:
$err = buildError($language["warning"],$errno, $errstr, $errfile, $errline);
$errors[] = $info->buildMessage($err,"warning");
//dbSaveLog(getURL(),$err,date("Y-m-d H:i:s"));
break;
case E_NOTICE:
case E_USER_NOTICE:
//$err = buildError($language["error_unknown"],$errno, $errstr, $errfile, $errline);
//dbSaveLog(getURL(),$err,date("Y-m-d H:i:s"));
break;
default:
$err = buildError($language["error_unknown"],$errno, $errstr, $errfile, $errline);
$errors[] = $info->buildMessage($err,"error");
//dbSaveLog(getURL(),$err,date("Y-m-d H:i:s"));
break;
}
/* Don't execute PHP internal error handler */
return true;
}
function buildError($errhead,$errno, $errstr, $errfile, $errline){
GLOBAL $config;
//[$errno]
if(!isset($config["debug"]) || $config["debug"])
$error = "<strong>$errhead:</strong> $errfile($errline)<br /><b>$errstr</b>";
else
$error = "<strong>$errhead: </strong>$errstr";
return $error;
}
function getErrors(){
GLOBAL $errors;
if(empty($errors)) return "";
$temp = "";
foreach($errors as $one){
$temp .= $one;
}
$errors = array();
return $temp;
}
function printErrors(){
echo getErrors();
}
?>

View file

@ -1,34 +1,34 @@
<?php
require_once("template.php");
class Info{
var $type = array (
"warning" => array("#F0FF69","#FFFB3E"),
"error" => array("#FFDDCC","#FF0000"),
"info" => array("#9BFB66","#039C00")
);
var $defaultStyle = "
<div id=\"info\" style=\"border:2px solid {'message_color_border'}; padding:5px;margin:10px;background:{'message_color'} none repeat scroll 0%;font-size:13px;\">
<center>{'message'}</center>
</div>
";
function buildMessage($msg, $t="warning"){
GLOBAL $template;
if(isset($template["message"])){
$temp = new Template($template["message"]);
}
else{
$temp = new Template($this->defaultStyle);
}
$temp->replace_tags(array(
"message_color" => $this->type[$t][0],
"message_color_border" => $this->type[$t][1],
"message" => $msg
));
return $temp->getOutput();
}
}
<?php
require_once("template.php");
class Info{
var $type = array (
"warning" => array("#F0FF69","#FFFB3E"),
"error" => array("#FFDDCC","#FF0000"),
"info" => array("#9BFB66","#039C00")
);
var $defaultStyle = "
<div id=\"info\" style=\"border:2px solid {'message_color_border'}; padding:5px;margin:10px;background:{'message_color'} none repeat scroll 0%;font-size:13px;\">
<center>{'message'}</center>
</div>
";
function buildMessage($msg, $t="warning"){
GLOBAL $template;
if(isset($template["message"])){
$temp = new Template($template["message"]);
}
else{
$temp = new Template($this->defaultStyle);
}
$temp->replace_tags(array(
"message_color" => $this->type[$t][0],
"message_color_border" => $this->type[$t][1],
"message" => $msg
));
return $temp->getOutput();
}
}
?>

View file

@ -1,35 +1,35 @@
<?php
class Template{
var $page;
function Template($template = "HelloWorld!!!") {
$this->page = $template;
}
function replace_tags($tags = array()) {
if (sizeof($tags) > 0)
foreach ($tags as $tag => $data) {
//$data = (file_exists($data)) ? $this->parse($data) : $data;
$this->page = str_ireplace("{'" . $tag . "'}", $data, $this->page);//eregi_replace
}
else
die("No tags designated for replacement.");
}
function output() {
echo $this->page;
}
function getOutput() {
return $this->page;
}
function parse($file) {
ob_start();
include($file);
$buffer = ob_get_contents();
ob_end_clean();
return $buffer;
}
}
<?php
class Template{
var $page;
function Template($template = "HelloWorld!!!") {
$this->page = $template;
}
function replace_tags($tags = array()) {
if (sizeof($tags) > 0)
foreach ($tags as $tag => $data) {
//$data = (file_exists($data)) ? $this->parse($data) : $data;
$this->page = str_ireplace("{'" . $tag . "'}", $data, $this->page);//eregi_replace
}
else
die("No tags designated for replacement.");
}
function output() {
echo $this->page;
}
function getOutput() {
return $this->page;
}
function parse($file) {
ob_start();
include($file);
$buffer = ob_get_contents();
ob_end_clean();
return $buffer;
}
}
?>

134
db.php
View file

@ -1,68 +1,68 @@
<?php
$db_host = "koc.se";
$db_database = "";
$db_user = "";
$db_password = "";
function dbconnect(){
@mysql_pconnect($GLOBALS['db_host'],$GLOBALS['db_user'],$GLOBALS['db_password'])
or die("ERROR CONNECTING TO DATABASE ".$GLOBALS['db_host']."!!!");
@mysql_select_db($GLOBALS['db_database'])
or die("THE DATABASE <b>".$GLOBALS['db_database']."</b> DO NOT EXIST!!!");
}
function dbdisconnect(){
@mysql_close();
}
function getTableRow($table, $id){
$sqlSats = "SELECT * FROM ".$table." WHERE id=".$id;
return runSimpleQuery($sqlSats);
}
function getTableCount($table){
$sqlSats = "SELECT * FROM ".$table;
return runSimpleQuery($sqlSats);
}
function getDBLastUpdateTime(){
$query = runQueryArray("SHOW TABLE STATUS");
foreach($query as $row){
if(empty($ret) || $row["Update_time"] > $ret){
$ret = $row["Update_time"];
}
}
return date("D F o H:i",strtotime($ret));
}
function dbSaveLog($url,$message,$date){
runSimpleQuery("INSERT INTO log VALUES (null,'$url','$message','$date')");
}
function runQueryArray($sqlSats){
$resultat = array();
$sql = @mysql_query($sqlSats);
if($sql == false){
trigger_error("ARRAY QUERY FAILD: \"".$sqlSats."\"", E_USER_ERROR);
die();
}
while ($row = mysql_fetch_array($sql,MYSQL_ASSOC)){
array_push($resultat, $row);
}
return $resultat;
}
function runSimpleQuery($sqlSats){
$resultat = @mysql_query($sqlSats);
if($resultat == false){
trigger_error("QUERY FAILD: \"".$sqlSats."\"", E_USER_ERROR);
die();
}
if(is_bool($resultat) || is_int($resultat))
return $resultat;
else
return @mysql_fetch_assoc($resultat);
}
<?php
$db_host = "koc.se";
$db_database = "";
$db_user = "";
$db_password = "";
function dbconnect(){
@mysql_pconnect($GLOBALS['db_host'],$GLOBALS['db_user'],$GLOBALS['db_password'])
or die("ERROR CONNECTING TO DATABASE ".$GLOBALS['db_host']."!!!");
@mysql_select_db($GLOBALS['db_database'])
or die("THE DATABASE <b>".$GLOBALS['db_database']."</b> DO NOT EXIST!!!");
}
function dbdisconnect(){
@mysql_close();
}
function getTableRow($table, $id){
$sqlSats = "SELECT * FROM ".$table." WHERE id=".$id;
return runSimpleQuery($sqlSats);
}
function getTableCount($table){
$sqlSats = "SELECT * FROM ".$table;
return runSimpleQuery($sqlSats);
}
function getDBLastUpdateTime(){
$query = runQueryArray("SHOW TABLE STATUS");
foreach($query as $row){
if(empty($ret) || $row["Update_time"] > $ret){
$ret = $row["Update_time"];
}
}
return date("D F o H:i",strtotime($ret));
}
function dbSaveLog($url,$message,$date){
runSimpleQuery("INSERT INTO log VALUES (null,'$url','$message','$date')");
}
function runQueryArray($sqlSats){
$resultat = array();
$sql = @mysql_query($sqlSats);
if($sql == false){
trigger_error("ARRAY QUERY FAILD: \"".$sqlSats."\"", E_USER_ERROR);
die();
}
while ($row = mysql_fetch_array($sql,MYSQL_ASSOC)){
array_push($resultat, $row);
}
return $resultat;
}
function runSimpleQuery($sqlSats){
$resultat = @mysql_query($sqlSats);
if($resultat == false){
trigger_error("QUERY FAILD: \"".$sqlSats."\"", E_USER_ERROR);
die();
}
if(is_bool($resultat) || is_int($resultat))
return $resultat;
else
return @mysql_fetch_assoc($resultat);
}
?>

306
sync.php
View file

@ -1,153 +1,153 @@
<?php
$sync = true;
$localDir = "projects";
$remoteFileSyncURL = "http://www.nada.kth.se/~ziver/sync.php";
$skip_filetype = array ("..",".");
$sessionPassword = "lol";
if(isset($_GET["fileList"])){
if($_GET["fileList"] == "array") print_r(getFileArray($localDir));
else echo serialize(getFileArray($localDir));
}
else if(isset($_GET["copyid"]) && $sync){
session_start();
if($_SESSION['auth'] == $sessionPassword){
echo "
<html>
<body onload='stop = true;'>
<div id='load'>|</div>
<script language='javascript'>
var stop = false;
function load() {
var loading = document.getElementById('load');
if (loading.innerHTML == '-') {
loading.innerHTML = '\\\\';
}
else if(loading.innerHTML == '\\\\'){
loading.innerHTML = '|';
}
else if(loading.innerHTML == '|'){
loading.innerHTML = '/';
}
else if(loading.innerHTML == '/'){
loading.innerHTML = '-';
}
if(stop){
loading.innerHTML = 'OK';
return;
}
setTimeout('load()',200);
}
load();
</script>
</body>
</html>
";
flush();
copyFile($_SESSION["id".$_GET["copyid"]]["copy"],$_SESSION["id".$_GET["copyid"]]["to"],$_SESSION["id".$_GET["copyid"]]["date"]);
}
else{
echo "<font color=red>ERROR</font>";
}
}
else if($sync){
session_start();
$_SESSION['auth'] = $sessionPassword;
$sessionId = 0;
$remoteFileList = unserialize(file_get_contents($remoteFileSyncURL."?fileList"));
$localFileList = getFileArray($localDir);
echo "<center><b>KOC SYNC: </b>".$remoteFileSyncURL."<br /><table width='200' border='1' style='border:1px solid #CCCCCC; border-collapse:collapse; width:95%;'>";
foreach($remoteFileList as $remoteFile){
$temp = searchFile($remoteFile, $localFileList);
if($temp >= 0){
if($remoteFile[0] > $localFileList[$temp][0]){
$_SESSION["id".$sessionId]["copy"] = $remoteFile[2];
$_SESSION["id".$sessionId]["to"] = $localDir.$localFileList[$temp][1];
$_SESSION["id".$sessionId]["date"] = $remoteFile[0];
echo "<tr bgcolor='#FF6F5C'><td>Local File Old!</td><td><iframe src='sync.php?copyid=".$sessionId."' width='25' height='20' frameborder='0' marginwidth='0' marginheight='0'></iframe></td>";
$sessionId++;
//copyFile($remoteFile[2],$localDir.$localFileList[$temp][1], $remoteFile[0]);
}
else if($remoteFile[0] < $localFileList[$temp][0]){
echo "<tr bgcolor='#A9B4FF'><td>Local File Newer!</td><td></td>";
}
else{
echo "<tr><td>Synced!</td><td></td>";
}
}
else{
$_SESSION["id".$sessionId]["copy"] = $remoteFile[2];
$_SESSION["id".$sessionId]["to"] = $localDir.$remoteFile[1];
$_SESSION["id".$sessionId]["date"] = $remoteFile[0];
echo "<tr bgcolor='#89FF8B'><td>New File!</td><td><iframe src='sync.php?copyid=".$sessionId."' width='25' height='20' frameborder='0' marginwidth='0' marginheight='0'></iframe></td>";
$sessionId++;
//copyFile($remoteFile[2],$localDir.$remoteFile[1],$remoteFile[0]);
}
echo "<td>".$remoteFile[2]."</td><td> => </td><td>".$remoteFile[1]."</td></tr>";
}
echo "</table></center>";
}
else {
echo"<center><font color=red>Sync disabled for this server!</font></center>";
}
function copyFile($source,$dest, $lastModDate = null){
@$file = fopen ($source, "rb");
if (!$file) {
echo"<font color=red>Failed to copy $source -> $dest!</font><br>";
return false;
}else {
if(!file_exists(dirname($dest)))
mkdir(dirname($dest),0777,true);
$filename = basename($source);
$fc = fopen($dest, "wb");
echo "<font color=green>$source => $dest</font><br><font color=black>";
while (!feof ($file)) {
$line = fread ($file, 1028);
fwrite($fc,$line);
echo "#";
}
fclose($fc);
if($lastModDate != null) touch($dest,$lastModDate);
echo "</font><br>";
return true;
}
}
$tempFilesArray = array();
function getFileArray($foldername) {
GLOBAL $localDir, $skip_filetype, $tempFilesArray;
$dirhandle = @opendir($foldername); //öppnar mappen
if($dirhandle !== false){ //gick det att öppna mappen?
while($filename = readdir($dirhandle)){ //loopar igenom alla filer i mappen
$filepath = $foldername ."/". $filename;
if($filename != "." && $filename != ".." && is_dir($filepath)){ //är det en mapp?
getFileArray($filepath);
}
else{ // its a file
$filetype = ereg_replace("^.+\\.([^.]+)$", "\\1", $filename);
if (!in_array($filetype, $skip_filetype)) {
$tempFilesArray[] = array(filemtime($filepath),str_replace($localDir, "", $filepath),("http://".$_SERVER['SERVER_NAME'].str_replace("sync.php","",$_SERVER['SCRIPT_NAME']).$filepath),$filename);
}
}
}
}
return $tempFilesArray;
}
function searchFile($remoteFile, $localFileList){
if(isset($localFileList)){
foreach($localFileList as $key => $localFile){
if($localFile[1] == $remoteFile[1]){
return $key;
}
}
}
return -1;
}
?>
<?php
$sync = true;
$localDir = "projects";
$remoteFileSyncURL = "http://www.nada.kth.se/~ziver/sync.php";
$skip_filetype = array ("..",".");
$sessionPassword = "lol";
if(isset($_GET["fileList"])){
if($_GET["fileList"] == "array") print_r(getFileArray($localDir));
else echo serialize(getFileArray($localDir));
}
else if(isset($_GET["copyid"]) && $sync){
session_start();
if($_SESSION['auth'] == $sessionPassword){
echo "
<html>
<body onload='stop = true;'>
<div id='load'>|</div>
<script language='javascript'>
var stop = false;
function load() {
var loading = document.getElementById('load');
if (loading.innerHTML == '-') {
loading.innerHTML = '\\\\';
}
else if(loading.innerHTML == '\\\\'){
loading.innerHTML = '|';
}
else if(loading.innerHTML == '|'){
loading.innerHTML = '/';
}
else if(loading.innerHTML == '/'){
loading.innerHTML = '-';
}
if(stop){
loading.innerHTML = 'OK';
return;
}
setTimeout('load()',200);
}
load();
</script>
</body>
</html>
";
flush();
copyFile($_SESSION["id".$_GET["copyid"]]["copy"],$_SESSION["id".$_GET["copyid"]]["to"],$_SESSION["id".$_GET["copyid"]]["date"]);
}
else{
echo "<font color=red>ERROR</font>";
}
}
else if($sync){
session_start();
$_SESSION['auth'] = $sessionPassword;
$sessionId = 0;
$remoteFileList = unserialize(file_get_contents($remoteFileSyncURL."?fileList"));
$localFileList = getFileArray($localDir);
echo "<center><b>KOC SYNC: </b>".$remoteFileSyncURL."<br /><table width='200' border='1' style='border:1px solid #CCCCCC; border-collapse:collapse; width:95%;'>";
foreach($remoteFileList as $remoteFile){
$temp = searchFile($remoteFile, $localFileList);
if($temp >= 0){
if($remoteFile[0] > $localFileList[$temp][0]){
$_SESSION["id".$sessionId]["copy"] = $remoteFile[2];
$_SESSION["id".$sessionId]["to"] = $localDir.$localFileList[$temp][1];
$_SESSION["id".$sessionId]["date"] = $remoteFile[0];
echo "<tr bgcolor='#FF6F5C'><td>Local File Old!</td><td><iframe src='sync.php?copyid=".$sessionId."' width='25' height='20' frameborder='0' marginwidth='0' marginheight='0'></iframe></td>";
$sessionId++;
//copyFile($remoteFile[2],$localDir.$localFileList[$temp][1], $remoteFile[0]);
}
else if($remoteFile[0] < $localFileList[$temp][0]){
echo "<tr bgcolor='#A9B4FF'><td>Local File Newer!</td><td></td>";
}
else{
echo "<tr><td>Synced!</td><td></td>";
}
}
else{
$_SESSION["id".$sessionId]["copy"] = $remoteFile[2];
$_SESSION["id".$sessionId]["to"] = $localDir.$remoteFile[1];
$_SESSION["id".$sessionId]["date"] = $remoteFile[0];
echo "<tr bgcolor='#89FF8B'><td>New File!</td><td><iframe src='sync.php?copyid=".$sessionId."' width='25' height='20' frameborder='0' marginwidth='0' marginheight='0'></iframe></td>";
$sessionId++;
//copyFile($remoteFile[2],$localDir.$remoteFile[1],$remoteFile[0]);
}
echo "<td>".$remoteFile[2]."</td><td> => </td><td>".$remoteFile[1]."</td></tr>";
}
echo "</table></center>";
}
else {
echo"<center><font color=red>Sync disabled for this server!</font></center>";
}
function copyFile($source,$dest, $lastModDate = null){
@$file = fopen ($source, "rb");
if (!$file) {
echo"<font color=red>Failed to copy $source -> $dest!</font><br>";
return false;
}else {
if(!file_exists(dirname($dest)))
mkdir(dirname($dest),0777,true);
$filename = basename($source);
$fc = fopen($dest, "wb");
echo "<font color=green>$source => $dest</font><br><font color=black>";
while (!feof ($file)) {
$line = fread ($file, 1028);
fwrite($fc,$line);
echo "#";
}
fclose($fc);
if($lastModDate != null) touch($dest,$lastModDate);
echo "</font><br>";
return true;
}
}
$tempFilesArray = array();
function getFileArray($foldername) {
GLOBAL $localDir, $skip_filetype, $tempFilesArray;
$dirhandle = @opendir($foldername); //öppnar mappen
if($dirhandle !== false){ //gick det att öppna mappen?
while($filename = readdir($dirhandle)){ //loopar igenom alla filer i mappen
$filepath = $foldername ."/". $filename;
if($filename != "." && $filename != ".." && is_dir($filepath)){ //är det en mapp?
getFileArray($filepath);
}
else{ // its a file
$filetype = ereg_replace("^.+\\.([^.]+)$", "\\1", $filename);
if (!in_array($filetype, $skip_filetype)) {
$tempFilesArray[] = array(filemtime($filepath),str_replace($localDir, "", $filepath),("http://".$_SERVER['SERVER_NAME'].str_replace("sync.php","",$_SERVER['SCRIPT_NAME']).$filepath),$filename);
}
}
}
}
return $tempFilesArray;
}
function searchFile($remoteFile, $localFileList){
if(isset($localFileList)){
foreach($localFileList as $key => $localFile){
if($localFile[1] == $remoteFile[1]){
return $key;
}
}
}
return -1;
}
?>