#!/usr/local/bin/php
<?php
error_reporting (0);
if (count($argv) <= 1 || $argv[1] == "-h") {
die ("No file or directory to sync./nUsage: synchronize file1[directory1] file2[directory2] .../n/n");
}
//$hosts = unserialize (file_get_contents("/bin/hosts"));
$hosts = file("/bin/hosts.line");
//$path = get_pwd();
$path = getcwd();
for ($i = 1; $i < count($argv); $i ++) {
if (strstr($argv[$i], "/") != $argv[$i]) $src = $path."/".$argv[$i];
else $src = $argv[$i];
if ($_SERVER["LOGNAME"] != 'root' || substr ($src, 0, 30) !== "/usr/local/apache2/htdocs/")
{
echo $src." not allowed./n";
continue;
}
$tar = dirname($src)."/";
if (is_dir($src)) {
foreach ($hosts as $h){
$h = trim ($h);
$cmd = "sudo /usr/bin/scp -r ".$src." test@".$h.":".$tar;
ex ($cmd);
}
} elseif (is_file($src)) {
foreach ($hosts as $h){
$h = trim ($h);
$cmd = "sudo /usr/bin/scp ".$src." test@".$h.":".$tar;
ex ($cmd);
}
} else {
echo "ignore ".$src." (does not exists?)/n";
}
}
function get_pwd () {
return $_SERVER['PWD'];
}
function ex ($cmd) {
echo substr($cmd, 14)."->executing, please wait...";
system ($cmd);
echo "ok!/n";
}
?>