symlinkcheck script for making sure the symlinks are correct
Posted: Wed Jul 13, 2005 12:58 am
I have been awake way to long and the knogon has shut down I think.
Maybe someone else can catch my error. PHP function->
Cheers,
Cordel
Maybe someone else can catch my error. PHP function->
Code: Select all
function checklinks($path)
{
/*
It will return false if the path is not a dir or if it couldn't open the folder.
It will return an array with the name of the symlinks that for some reason couldn't be created.
It will return true if it was able to create all missing symlinks.
*/
# Get from the database Monitors that are configured
$sql = "select Id as MonitorId, Name as MonitorName from Monitors";
$result = mysql_query( $sql ) or die(mysql_error());
while($row = mysql_fetch_assoc( $result ))
{
$Monitor['id'][] = $row['MonitorId'];
$Monitor['name'][] = $row['MonitorName'];
}
if(!is_dir($path)) return false;
if(!($dir = opendir( $path ))) return false;
while (false !== ($file = readdir($dir)))
{
#Get the symlinks
if (is_link($file))
{
$symlinks[] = $file;
}
}
closedir($dir);
foreach ($symlinks as $key=>$value)
{
if(!in_array($value,$Monitor['name']))
{
unlink("$path/$value");
unset($symlinks[$key]);
}
}
$diff = array_diff($Monitor['name'], $symlinks[$key]);
if(!empty($diff))
{
foreach ($diff as $key=>$value)
{
if (!symlink($path.'/'.$Monitor['id'][$key],$value))
#if(!symlink("$path/{$Monitor['id'][$key]}",$value))
{
$symlinks_not_created[] = $value;
}
}
if(empty($symlinks_not_created))
{
return true;
}
else return $symlinks_not_created;
}
}
I am hoping to have this done and tested by Wednesday night so this can go in the next release. Any input my be useful as I'm drawing a blank.Apache Error log wrote:PHP Warning: array_diff(): Argument #2 is not an array in /usr/lib/zm/html/zm_export_funcs.php on line 312, referer: http://192.168.10.20/index.php?view=export&eids[]=92315
Cheers,
Cordel