. // // schedule_functions.php Copyright (C) 2005 VerCom Systems, Inc. & Ron Hartmann (rhartmann@vercomsystems.com) // Asterisk Management Portal Copyright (C) 2004 Coalescent Systems Inc. (info@coalescentsystems.ca) // function Get_Tar_Files($dir="", $display="", $file="") { global $type; global $asterisk_conf; global $amp_conf; if (is_dir($dir)) { if (($file!=".") && ($file!="..") && ($file!="")){ echo "
  • "; echo _("DELETE ALL THE DATA IN THIS SET"); echo ""; echo _("Delete this backup set and all data associated with this backup set..");echo "
  • "; echo "
    "; } if ($dh = opendir($dir)){ while (($file = readdir($dh)) !== false) { $file_arr[] = $file; } rsort($file_arr); $count = 25; foreach ($file_arr as $file) { if (($file!=".") && ($file!="..") && ($dir==$amp_conf['ASTVARLIBDIR']."/backups/")) { echo "
  • $file
  • "; $count--; } else if (($file!=".") && ($file!="..") ) { echo "
  • $file
  • "; $count--; } } closedir($dh); for ($i = $count; $i > 0; $i--) { echo "
    "; } } } else if (substr($dir, -6)=="tar.gz" ){ echo "
  • "; echo _("Delete File Set"); echo ""; echo _("Delete this backup set."); echo "
  • "; echo "
    "; $tar_string="tar tfz \"$dir\" | cut -d'/' -f4"; exec($tar_string,$restore_files,$error); echo "
  • "; echo _("Restore Entire Backup Set"); echo ""; echo _("Restore your Complete Backup set overwriting all files."); echo "
  • "; echo "
    "; if (array_search('voicemail.tar.gz',$restore_files)){ echo "
  • "; echo _("Restore VoiceMail Files"); echo ""; echo _("Restore your Voicemail files from this backup set. NOTE! This will delete any voicemail currently in the voicemail boxes."); echo "
  • "; echo "
    "; } if (array_search('recordings.tar.gz',$restore_files)){ echo "
  • "; echo _("Restore System Recordings Files"); echo ""; echo _("Restore your system Voice Recordings including AutoAttendant files from this backup set. NOTE! This will OVERWRITE any voicerecordings currently on the system. It will NOT delete new files not currently in the backup set"); echo "
  • "; echo "
    "; } if (array_search('configurations.tar.gz',$restore_files)){ echo "
  • "; echo _("Restore System Configuration"); echo ""; echo _("Restore your system configuration from this backup set. NOTE! This will OVERWRITE any System changes you have made since this backup... ALL items will be reset to what they were at the time of this backup set.."); echo "
  • "; echo "
    "; } if (array_search('fop.tar.gz',$restore_files)){ echo "
  • "; echo _("Restore Operator Panel"); echo ""; echo _("Restore the Operator Panel from this backup set. NOTE! This will OVERWRITE any Operator Panel Changes you have made since this backup... ALL items will be reset to what they were at the time of this backup set.."); echo "
  • "; echo "
    "; } if (array_search('cdr.tar.gz',$restore_files)){ echo "
  • "; echo _("Restore Call Detail Report"); echo ""; echo _("Restore the Call Detail Records from this backup set. NOTE! This will DELETE ALL CALL RECORDS that have been saved since this backup set.."); echo "
  • "; echo "
    "; } } else { echo "

    "; echo _("ERROR its not a BACKUP SET file");echo "

    "; } } function Restore_Tar_Files($dir="", $file="",$filetype="", $display="") { global $asterisk_conf; global $amp_conf; $error = false; if($filetype=="ALL") { $fileholder=substr($file, 0,-7); exec("/bin/rm -rf /tmp/ampbackups.$fileholder 2>&1",$out_arr,$ret); $error = ($error || ($ret != 0)); // First restore voicemial (for some reason if you do it all at once these don't get restored // exec('/bin/rm -rf '.$amp_conf['ASTSPOOLDIR'].'/voicemail 2>&1',$out_arr,$ret); $error = ($error || ($ret != 0)); $tar_cmd="tar -PxvOz -f \"$dir\" /tmp/ampbackups.$fileholder/voicemail.tar.gz | tar -Pxvz"; exec($tar_cmd,$out_arr,$ret); $error = ($error || ($ret != 0)); // Next, recordings cause same issue as above // $tar_cmd="tar -PxvOz -f \"$dir\" /tmp/ampbackups.$fileholder/recordings.tar.gz | tar -Pxvz"; exec($tar_cmd,$out_arr,$ret); $error = ($error || ($ret != 0)); // Now the rest and then we'll get on with the databases // $tar_cmd="tar -PxvOz -f \"$dir\" /tmp/ampbackups.$fileholder/configurations.tar.gz | tar -Pxvz"; exec($tar_cmd,$out_arr,$ret); $error = ($error || ($ret != 0)); $tar_cmd="tar -PxvOz -f \"$dir\" /tmp/ampbackups.$fileholder/fop.tar.gz /tmp/ampbackups.$fileholder/cdr.tar.gz | tar -Pxvz"; exec($tar_cmd,$out_arr,$ret); $error = ($error || ($ret != 0)); $tar_cmd="tar -Pxvz -f \"$dir\" /tmp/ampbackups.$fileholder/asterisk.sql /tmp/ampbackups.$fileholder/asteriskcdr.sql /tmp/ampbackups.$fileholder/astdb.dump"; exec($tar_cmd,$out_arr,$ret); $error = ($error || ($ret != 0)); $sql_cmd="mysql -u ".$amp_conf['AMPDBUSER']." -p".$amp_conf['AMPDBPASS']." < /tmp/ampbackups.$fileholder/asterisk.sql 2>&1"; exec($sql_cmd,$out_arr,$ret); $error = ($error || ($ret != 0)); $sql_cmd="mysql -u ".$amp_conf['AMPDBUSER']." -p".$amp_conf['AMPDBPASS']." < /tmp/ampbackups.$fileholder/asteriskcdr.sql 2>&1"; exec($sql_cmd,$out_arr,$ret); $error = ($error || ($ret != 0)); exec($amp_conf['AMPBIN']."/restoreastdb.php $fileholder 2>&1",$out_arr,$ret); $error = ($error || ($ret != 0)); exec("/bin/rm -rf /tmp/ampbackups.$fileholder",$out_arr,$ret); $error = ($error || ($ret != 0)); if (!error) { $Message=_("Restored All Files in Backup Set"); } } else if($filetype=="VoiceMail") { $fileholder=substr($file, 0,-7); exec("/bin/rm -rf /tmp/ampbackups.$fileholder 2>&1",$out_arr,$ret); $error = ($error || ($ret != 0)); exec('/bin/rm -rf '.$amp_conf['ASTSPOOLDIR'].'/voicemail 2>&1',$out_arr,$ret); $error = ($error || ($ret != 0)); $tar_cmd="tar -PxvOz -f \"$dir\" /tmp/ampbackups.$fileholder/voicemail.tar.gz | tar -Pxvz"; exec($tar_cmd,$out_arr,$ret); $error = ($error || ($ret != 0)); exec("/bin/rm -rf /tmp/ampbackups.$fileholder 2>&1",$out_arr,$ret); $error = ($error || ($ret != 0)); if (!error) { $Message=_("Restored VoiceMail"); } } else if($filetype=="Recordings") { $fileholder=substr($file, 0,-7); exec("/bin/rm -rf /tmp/ampbackups.$fileholder 2>&1",$out_arr,$ret); $error = ($error || ($ret != 0)); $tar_cmd="tar -PxvOz -f \"$dir\" /tmp/ampbackups.$fileholder/recordings.tar.gz | tar -Pxvz"; exec($tar_cmd,$out_arr,$ret); $error = ($error || ($ret != 0)); exec("/bin/rm -rf /tmp/ampbackups.$fileholder 2>&1",$out_arr,$ret); $error = ($error || ($ret != 0)); if (!error) { $Message=_("Restored System Recordings"); } } else if($filetype=="Configurations"){ $fileholder=substr($file, 0,-7); exec("/bin/rm -rf /tmp/ampbackups.$fileholder 2>&1",$out_arr,$ret); $error = ($error || ($ret != 0)); $tar_cmd="tar -PxvOz -f \"$dir\" /tmp/ampbackups.$fileholder/configurations.tar.gz | tar -Pxvz"; exec($tar_cmd,$out_arr,$ret); $error = ($error || ($ret != 0)); $tar_cmd="tar -Pxvz -f \"$dir\" /tmp/ampbackups.$fileholder/asterisk.sql /tmp/ampbackups.$fileholder/astdb.dump"; exec($tar_cmd,$out_arr,$ret); $error = ($error || ($ret != 0)); $sql_cmd="mysql -u ".$amp_conf['AMPDBUSER']." -p".$amp_conf['AMPDBPASS']." < /tmp/ampbackups.$fileholder/asterisk.sql"; exec($sql_cmd,$out_arr,$ret); $error = ($error || ($ret != 0)); exec($amp_conf['AMPBIN']."/restoreastdb.php $fileholder 2>&1",$out_arr,$ret); $error = ($error || ($ret != 0)); exec("/bin/rm -rf /tmp/ampbackups.$fileholder 2>&1",$out_arr,$ret); $error = ($error || ($ret != 0)); if (!error) { $Message=_("Restored System Configuration"); } } else if($filetype=="FOP"){ $fileholder=substr($file, 0,-7); exec("/bin/rm -rf /tmp/ampbackups.$fileholder 2>&1",$out_arr,$ret); $error = ($error || ($ret != 0)); $tar_cmd="tar -PxvOz -f \"$dir\" /tmp/ampbackups.$fileholder/fop.tar.gz | tar -Pxvz"; exec($tar_cmd,$out_arr,$ret); $error = ($error || ($ret != 0)); exec("/bin/rm -rf /tmp/ampbackups.$fileholder 2>&1",$out_arr,$ret); $error = ($error || ($ret != 0)); if (!error) { $Message=_("Restored Operator Panel"); } } else if($filetype=="CDR"){ $fileholder=substr($file, 0,-7); exec("/bin/rm -rf /tmp/ampbackups.$fileholder 2>&1",$out_arr,$ret); $error = ($error || ($ret != 0)); $tar_cmd="tar -PxvOz -f \"$dir\" /tmp/ampbackups.$fileholder/cdr.tar.gz | tar -Pxvz"; exec($tar_cmd,$out_arr,$ret); $error = ($error || ($ret != 0)); $tar_cmd="tar -Pxvz -f \"$dir\" /tmp/ampbackups.$fileholder/asteriskcdr.sql"; exec($tar_cmd,$out_arr,$ret); $error = ($error || ($ret != 0)); $sql_cmd="mysql -u ".$amp_conf['AMPDBUSER']." -p".$amp_conf['AMPDBPASS']." < /tmp/ampbackups.$fileholder/asteriskcdr.sql 2>&1"; exec($sql_cmd,$out_arr,$ret); $error = ($error || ($ret != 0)); exec("/bin/rm -rf /tmp/ampbackups.$fileholder 2>&1",$out_arr,$ret); $error = ($error || ($ret != 0)); if (!error) { $Message=_("Restored CDR logs"); } } if (! $error) { $Message=_("Restore Failed, see System Status Notification for details"); return ($Message); } else { // TODO: put in notification error and add code above to collect details // along the way to put something meaningful in it // return ($Message); } } function Get_Backup_Sets() { global $db; $sql = "SELECT * FROM Backup"; $results = $db->getAll($sql); if(DB::IsError($results)) { $results = null; } return $results; } function Delete_Backup_Set($ID="") { global $db; global $asterisk_conf; global $amp_conf; $sql = "DELETE FROM Backup WHERE ID = '$ID'"; $result = $db->query($sql); if(DB::IsError($result)) { die_freepbx($result->getMessage()); } //$Cron_Script=$asterisk_conf['astvarlibdir']."/bin/retrieve_backup_cron.php"; //exec($Cron_Script); //TODO: should we check and act on false return backup_retrieve_backup_cron(); } function Save_Backup_Schedule($Backup_Parms, $backup_options ) { global $db; global $asterisk_conf; global $amp_conf; if ($Backup_Parms[1]=="now") { $Cron_Script=$asterisk_conf['astvarlibdir']."/bin/ampbackup.pl '$Backup_Parms[0]' $backup_options[0] $backup_options[1] $backup_options[2] $backup_options[3] $backup_options[4]"; //echo "$Cron_Script"; exec($Cron_Script); } $sql = "INSERT INTO Backup (Name, Voicemail, Recordings, Configurations, CDR, FOP, Minutes, Hours, Days, Months,Weekdays, Command, Method ) VALUES ("; $sql .= "'".$Backup_Parms[0]."',"; $sql .= "'".$backup_options[0]."',"; $sql .= "'".$backup_options[1]."',"; $sql .= "'".$backup_options[2]."',"; $sql .= "'".$backup_options[3]."',"; $sql .= "'".$backup_options[4]."',"; $sql .= "'".$Backup_Parms[2]."',"; $sql .= "'".$Backup_Parms[3]."',"; $sql .= "'".$Backup_Parms[4]."',"; $sql .= "'".$Backup_Parms[5]."',"; $sql .= "'".$Backup_Parms[6]."',"; $sql .= "'".$Backup_Parms[7]."',"; $sql .= "'".$Backup_Parms[1]."');"; $result = $db->query($sql); if(DB::IsError($result)) { die_freepbx($result->getMessage().'
    '.$sql); } //$Cron_Script=$asterisk_conf['astvarlibdir']."/bin/retrieve_backup_cron.php"; //exec($Cron_Script); backup_retrieve_backup_cron(); } function Get_Backup_String($name, $backup_schedule, $ALL_days, $ALL_months, $ALL_weekdays, $mins="", $hours="", $days="", $months="", $weekdays="") { global $asterisk_conf; if ($backup_schedule=="hourly") $Cron_String="0 * * * * ".$asterisk_conf['astvarlibdir']."/bin/ampbackup.pl"; else if ($backup_schedule=="daily") $Cron_String="0 0 * * * ".$asterisk_conf['astvarlibdir']."/bin/ampbackup.pl"; else if ($backup_schedule=="weekly") $Cron_String="0 0 * * 0 ".$asterisk_conf['astvarlibdir']."/bin/ampbackup.pl"; else if ($backup_schedule=="monthly") $Cron_String="0 0 1 * * ".$asterisk_conf['astvarlibdir']."/bin/ampbackup.pl"; else if ($backup_schedule=="yearly") $Cron_String="0 0 1 1 * ".$asterisk_conf['astvarlibdir']."/bin/ampbackup.pl"; else if ($backup_schedule=="follow_schedule") { if (count($mins)<1) $mins_string=":0:"; else{ foreach ($mins as $value) $mins_string.=":$value:"; } if (count($hours)<1) $hours_string=":0:"; else{ foreach ($hours as $value) $hours_string.=":$value:"; } if(($ALL_days=="1")||(count($days)<1)) $days_string="*"; else{ foreach ($days as $value) $days_string.=":$value:"; } if(($ALL_months=="1")||(count($months)<1)) $months_string="*"; else{ foreach ($months as $value) $months_string.=":$value:"; } if($ALL_weekdays=="1"||(count($weekdays)<1)) $weekdays_string="*"; else{ foreach ($weekdays as $value) $weekdays_string.=":$value:"; } $cron_mins_string=trim($mins_string,":"); $cron_hours_string=trim($hours_string,":"); $cron_days_string=trim($days_string,":"); $cron_months_string=trim($months_string,":"); $cron_weekdays_string=trim($weekdays_string,":"); $Cron_String=str_replace("::", ",", "$cron_mins_string $cron_hours_string $cron_days_string $cron_months_string $cron_weekdays_string ".$asterisk_conf['astvarlibdir']."/bin/ampbackup.pl"); } else if ($backup_schedule=="now") $Cron_String="0 0 0 0 0 ".$asterisk_conf['astvarlibdir']."/bin/ampbackup.pl"; $Backup_String[]="$name"; $Backup_String[]="$backup_schedule"; $Backup_String[]="$mins_string"; $Backup_String[]="$hours_string"; $Backup_String[]="$days_string"; $Backup_String[]="$months_string"; $Backup_String[]="$weekdays_string"; $Backup_String[]="$Cron_String"; return ($Backup_String); } function Get_Backup_Times($BackupID) { global $db; $sql = "SELECT Minutes, Hours, Days, Months, Weekdays, Method From Backup where ID=\"$BackupID\""; $results = $db->getAll($sql); if(DB::IsError($results)) { $results = Array(null, null, null, null, null, null); } return $results; } function Get_Backup_Options($BackupID) { global $db; $sql = "SELECT Name, Voicemail, Recordings, Configurations, CDR, FOP FROM Backup where ID=\"$BackupID\""; $results = $db->getAll($sql); if(DB::IsError($results)) { $results = Array(null, null, null, null, null, null); } return $results; } function Show_Backup_Options($ID="") { if ($ID==""){ $name=""; $voicemail="no"; $sysrecordings="no"; $sysconfig="no"; $cdr="no"; $fop="no";} else{ $backup_options=Get_Backup_Options($ID); foreach ($backup_options as $bk_options) $name="$bk_options[0]";$voicemail="$bk_options[1]"; $sysrecordings="$bk_options[2]"; $sysconfig="$bk_options[3]"; $cdr="$bk_options[4]"; $fop="$bk_options[5]"; } ?> :           :           :           :           :          
    "; echo ""; echo ""; echo "
    "; } function Schedule_Show_Hours($Hours_Set="") { echo "

    "; echo ""; echo ""; echo "
    "; } function Schedule_Show_Days($Days_Set="") { if (($Days_Set=="") || ($Days_Set=="*")){ echo ""; echo _("All"); echo "
    "; echo ""; echo _("Selected"); echo "
    "; } else{ echo ""; echo _("All"); echo "
    "; echo ""; echo _("Selected"); echo "
    "; } echo ""; echo ""; echo ""; echo "
    "; } function Schedule_Show_Months($Months_Set="") { if (($Months_Set=="") || ($Months_Set=="*")){ echo ""; echo _("All"); echo "
    "; echo ""; echo _("Selected"); echo "
    "; } else{ echo ""; echo _("All"); echo "
    "; echo ""; echo _("Selected"); echo "
    "; } echo ""; echo ""; echo "
    "; } function Schedule_Show_Weekdays($Weekdays_Set="") { if (($Weekdays_Set=="") || ($Weekdays_Set=="*")){ echo "";echo _("All"); echo "
    "; echo "";echo _("Selected"); echo "
    "; } else{ echo "";echo _("All"); echo "
    "; echo "";echo _("Selected"); echo "
    "; } echo ""; echo ""; echo "
    "; } function show_quickbar($Method="") { ?> "; echo ""._("Minutes")." "._("Hours")." "._("Days")." "._("Months").""._("Weekdays")." "; echo ""; Schedule_Show_Minutes($Minutes); echo ""; Schedule_Show_Hours($Hours); echo ""; Schedule_Show_Days($Days); echo ""; Schedule_Show_Months($Months); echo ""; Schedule_Show_Weekdays($Weekdays); }