function mount_usb($pattern, $ID, $testwrite = true) { $backup = new backup_protocols(); $uuid = $backup->extractFirsRessource($pattern); $unix = new unix(); $rsync = $unix->find_program("rsync"); if ($uuid == null) { backup_events($ID, "initialization", "ERROR, (usb) usb protocol error {$pattern}", __LINE__); writelogs(date('m-d H:i:s') . " " . "[TASK {$ID}]: usb protocol error {$pattern}", __FUNCTION__, __FILE__, __LINE__); return false; } $usb = new usb($uuid); writelogs(date('m-d H:i:s') . " " . "[TASK {$ID}]: {$uuid} {$usb->path} FS_TYPE: {$usb->ID_FS_TYPE}", __FUNCTION__, __FILE__, __LINE__); if ($usb->ID_FS_TYPE == null) { backup_events($ID, "initialization", "ERROR, (usb) usb type error {$pattern}", __LINE__); return false; } if ($usb->path == null) { backup_events($ID, "initialization", "ERROR, (usb) usb dev error {$pattern}", __LINE__); return false; } $mount = new mount($GLOBALS["ADDLOG"]); $mount_path = "/opt/artica/mounts/backup/{$ID}"; if (!$mount->ismounted($mount_path)) { backup_events($ID, "initialization", "ERROR, (usb) local mount point {$mount_path} not mounted"); @mkdir($mount_path, null, true); } if (!$mount->usb_mount($mount_path, $usb->ID_FS_TYPE, $usb->path)) { backup_events($ID, "initialization", "ERROR, (usb) unable to mount target point"); return false; } if (!$testwrite) { writelogs(date('m-d H:i:s') . " " . "[TASK {$ID}]: Test write has been cancelled", __FUNCTION__, __FILE__, __LINE__); return true; } $md5 = md5(date('Y-m-d H:i:s')); writelogs(date('m-d H:i:s') . " " . "[TASK {$ID}]: Test write Creating file \"{$mount_path}/{$md5}\"", __FUNCTION__, __FILE__, __LINE__); try { file_put_contents("{$mount_path}/{$md5}", time()); } catch (Exception $e) { $IOERROR = $e->getMessage(); } if (is_file("{$mount_path}/{$md5}")) { @unlink("{$mount_path}/{$md5}"); if (is_file($rsync)) { $GLOBALS["COMMANDLINECOPY"] = "{$rsync} -ar {SRC_PATH} {NEXT} --stats --chmod=ug=rwX,o=rwX"; } else { $GLOBALS["COMMANDLINECOPY"] = "/bin/cp -ru {SRC_PATH} {NEXT}"; } $GLOBALS["COMMANDLINE_MOUNTED_PATH"] = $mount_path; writelogs(date('m-d H:i:s') . " " . "[TASK {$ID}]: OK !", __FUNCTION__, __FILE__, __LINE__); if ($GLOBALS["ONLY_TESTS"]) { writelogs(date('m-d H:i:s') . " " . "<H2>{success}</H2>", __FUNCTION__, __FILE__, __LINE__); } return true; } else { backup_events($ID, "initialization", "ERROR, (usb) {$mount_path}/{$md5} {$IOERROR}"); backup_events($ID, "initialization", "ERROR, (usb) {$mount_path}/{$md5} should be a permission denied (I/O error)"); $unix = new unix(); $unix->send_email_events("Backup: task id {$ID} aborted, unable to write into the device {$usb->path} FS_TYPE: {$usb->ID_FS_TYPE}", "Artica has tried to write {$mount_path}/{$md5} into this mounted device but it seems that it is impossible\n{$IOERROR}", "backup"); writelogs(date('m-d H:i:s') . " " . "[TASK {$ID}]: Failed !!!, umounting...{$mount_path}", __FUNCTION__, __FILE__, __LINE__); $umount = $unix->find_program("umount"); exec("{$umount} -l {$mount_path}"); } }
function tasks_list(){ $sql=new mysql(); $sock=new sockets(); $sql="SELECT * FROM backup_schedules ORDER BY ID DESC"; $q=new mysql(); $results=$q->QUERY_SQL($sql,"artica_backup"); $backup=new backup_protocols(); $cron=new cron_macros(); $storages["usb"]="{usb_external_drive}"; $storages["smb"]="{remote_smb_server}"; $storages["rsync"]="{remote_rsync_server}"; $storages["automount"]="{automount_ressource}"; $storages["local"]="{local_directory}"; $html="<table cellspacing='0' cellpadding='0' border='0' class='tableView' style='width:100%'> <thead class='thead'> <th>{task}</th> <th> </th> <th> </th> <th>{test}</th> <th>{STORAGE_TYPE}</th> <th>{resource}</th> <th>{schedule}</th> <th>{sources}</th> <th> </th> </thead> <tbody class='tbody'>"; while($ligne=@mysql_fetch_array($results,MYSQL_ASSOC)){ if($classtr=="oddRow"){$classtr=null;}else{$classtr="oddRow";} $ressources=unserialize(base64_decode($ligne["datasbackup"])); $sources=(count($ressources)-1)+FOLDER_BACKUPED_NUMBER($ligne["ID"])." {sources}"; $sources=texttooltip($sources,"{show}","BACKUP_TASKS_SOURCE({$ligne["ID"]})",null,0,"font-size:12px"); $run=imgtootltip("run-24.png","{run_task}","BACKUP_TASK_RUN({$ligne["ID"]})"); if($ligne["pid"]>5){ $array_pid=unserialize(base64_decode($sock->getFrameWork("cmd.php?procstat={$ligne["pid"]}"))); if($array_pid["since"]<>null){ $run=imgtootltip("ajax-menus-loader.gif","{running}: {since} {$array_pid["since"]}",""); } } $html=$html. "<tr class=$classtr> <td width=1% align='center'><strong style='font-size:12px'>{$ligne["ID"]}</strong></td> <td width=1% style='font-size:12px' align='left'>". imgtootltip("events-24.png","{events}","TASK_EVENTS_DETAILS({$ligne["ID"]})")."</td> <td width=1%>$run</td> <td width=1%>". imgtootltip("eclaire-24.png","{BACKUP_TASK_TEST}","BACKUP_TASK_TEST({$ligne["ID"]})")."</td> <td style='font-size:12px' nowrap><a href=\"javascript:BACKUP_TASK_MODIFY_RESSOURCES('{$ligne["ID"]}')\" style='text-decoration:underline'>[{$storages[$ligne["resource_type"]]}]</a></td> <td style='font-size:12px'>". $backup->extractFirsRessource($ligne["pattern"])."</td> <td style='font-size:12px' nowrap>". $cron->cron_human($ligne["schedule"])."</td> <td style='font-size:12px'>$sources</td> <td style='font-size:12px'>". imgtootltip("delete-24.png","{delete}","DeleteBackupTask({$ligne["ID"]})")."</td> </tr>"; } $html=$html."</tbody></table> <hr> <table style='width:100%'> <tr> <td align='left'>". button("{add_task}","Loadjs('wizard.backup-all.php');")."</td> <td align='right'><div style='width:100%;text-align:right'>". imgtootltip('32-refresh.png',"{refresh}","BACKUP_TASKS_LISTS()")."</div></td> </tr> </table> "; $tpl=new templates(); echo $tpl->_ENGINE_parse_body($html); }
function tasks_list() { $sql = new mysql(); $sock = new sockets(); $sql = "SELECT * FROM backup_schedules ORDER BY ID DESC"; $q = new mysql(); $results = $q->QUERY_SQL($sql, "artica_backup"); $backup = new backup_protocols(); $cron = new cron_macros(); $storages["usb"] = "{usb_external_drive}"; $storages["smb"] = "{remote_smb_server}"; $storages["rsync"] = "{remote_rsync_server}"; $html = "<table style='width:99%'>\n\t<th> </th>\n\t<th>{task}</th>\n\t<th>{STORAGE_TYPE}</th>\n\t<th>{resource}</th>\n\t<th>{schedule}</th>\n\t</tr>"; while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $ressources = unserialize(base64_decode($ligne["datasbackup"])); $sources = count($ressources) . " {sources}"; $html = $html . "<tr " . CellRollOver("TasksListConnectSource({$ligne["ID"]})", "{choose}:{task} {$ligne["ID"]}") . ">\n\t\t<td width=1%><img src='img/fw_bold.gif'></td>\n\t\t<td width=1% nowrap><strong>{task} {$ligne["ID"]}</strong></td>\n\t\t<td style='font-size:12px'>{$storages[$ligne["resource_type"]]}</td>\n\t\t<td style='font-size:12px'>" . $backup->extractFirsRessource($ligne["pattern"]) . "</td>\n\t\t<td style='font-size:12px'>" . $cron->cron_human($ligne["schedule"]) . "</td>\n\t\t</tr>"; } $html = $html . "</table>\n\t<hr>\n\t<div style='width:100%;text-align:right'>" . imgtootltip('32-refresh.png', "{refresh}", "BACKUP_TASKS_LISTS()") . "</div>\n\t"; $tpl = new templates(); echo $tpl->_ENGINE_parse_body($html); }
function tasks_list() { $sql = new mysql(); $sock = new sockets(); $sql = "SELECT * FROM backup_schedules ORDER BY ID DESC"; $q = new mysql(); $results = $q->QUERY_SQL($sql, "artica_backup"); $backup = new backup_protocols(); $cron = new cron_macros(); $storages["usb"] = "{usb_external_drive}"; $storages["smb"] = "{remote_smb_server}"; $storages["rsync"] = "{remote_rsync_server}"; $html = "<table style='width:99%'>\n\t<th>{task}</th>\n\t<th> </th>\n\t<th> </th>\n\t<th>{test}</th>\n\t<th>{STORAGE_TYPE}</th>\n\t<th>{resource}</th>\n\t<th>{schedule}</th>\n\t<th>{sources}</th>\n\t<th> </th>\n\t</tr>"; while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $ressources = unserialize(base64_decode($ligne["datasbackup"])); $sources = count($ressources) - 1 + FOLDER_BACKUPED_NUMBER($ligne["ID"]) . " {sources}"; $sources = texttooltip($sources, "{show}", "BACKUP_TASKS_SOURCE({$ligne["ID"]})", null, 0, "font-size:12px"); $run = imgtootltip("run-24.png", "{run_task}", "BACKUP_TASK_RUN({$ligne["ID"]})"); if ($ligne["pid"] > 5) { $array_pid = unserialize(base64_decode($sock->getFrameWork("cmd.php?procstat={$ligne["pid"]}"))); if ($array_pid["since"] != null) { $run = imgtootltip("ajax-menus-loader.gif", "{running}: {since} {$array_pid["since"]}", ""); } } $html = $html . "<tr " . CellRollOver() . ">\n\t\t\n\t\t<td width=1% align='center'><strong style='font-size:12px'>{$ligne["ID"]}</strong></td>\n\t\t<td width=1% style='font-size:12px' align='left'>" . imgtootltip("events-24.png", "{events}", "TASK_EVENTS_DETAILS({$ligne["ID"]})") . "</td>\n\t\t<td width=1%>{$run}</td>\n\t\t<td width=1%>" . imgtootltip("eclaire-24.png", "{BACKUP_TASK_TEST}", "BACKUP_TASK_TEST({$ligne["ID"]})") . "</td>\n\t\t<td style='font-size:12px' nowrap>{$storages[$ligne["resource_type"]]}</td>\n\t\t<td style='font-size:12px'>" . $backup->extractFirsRessource($ligne["pattern"]) . "</td>\n\t\t<td style='font-size:12px' nowrap>" . $cron->cron_human($ligne["schedule"]) . "</td>\n\t\t<td style='font-size:12px'>{$sources}</td>\n\t\t<td style='font-size:12px'>" . imgtootltip("delete-24.png", "{delete}", "DeleteBackupTask({$ligne["ID"]})") . "</td>\n\t\t</tr>"; } $html = $html . "</table>\n\t<hr>\n\t<table style='width:100%'>\n\t<tr>\n\t<td align='left'>" . button("{add_task}", "Loadjs('wizard.backup-all.php');") . "</td>\n\t<td align='right'><div style='width:100%;text-align:right'>" . imgtootltip('32-refresh.png', "{refresh}", "BACKUP_TASKS_LISTS()") . "</div></td>\n\t</tr>\n\t</table>\n\t"; $tpl = new templates(); echo $tpl->_ENGINE_parse_body($html); }
function mount_usb($pattern,$ID,$testwrite=true){ $backup=new backup_protocols(); $uuid=$backup->extractFirsRessource($pattern); $unix=new unix(); $rsync=$unix->find_program("rsync"); if($uuid==null){ backup_events($ID,"initialization","ERROR, (usb) usb protocol error $pattern"); writelogs(date('m-d H:i:s')." "."[TASK $ID]: usb protocol error $pattern",__FUNCTION__,__FILE__,__LINE__); return false; } $usb=new usb($uuid); writelogs(date('m-d H:i:s')." "."[TASK $ID]: $uuid $usb->path FS_TYPE: $usb->ID_FS_TYPE",__FUNCTION__,__FILE__,__LINE__); if($usb->ID_FS_TYPE==null){ backup_events($ID,"initialization","ERROR, (usb) usb type error $pattern"); return false; } if($usb->path==null){ backup_events($ID,"initialization","ERROR, (usb) usb dev error $pattern"); return false; } $mount=new mount($GLOBALS["ADDLOG"]); $mount_path="/opt/artica/mounts/backup/$ID"; if(!$mount->ismounted($mount_path)){ backup_events($ID,"initialization","ERROR, (usb) local mount point $mount_path not mounted"); @mkdir($mount_path,null,true); } if(!$mount->usb_mount($mount_path,$usb->ID_FS_TYPE,$usb->path)){ backup_events($ID,"initialization","ERROR, (usb) unable to mount target point"); return false; } if(!$testwrite){return true;} $md5=md5(date('Y-m-d H:i:s')); @file_put_contents("$mount_path/$md5","#"); if(is_file("$mount_path/$md5")){ @unlink("$mount_path/$md5"); if(is_file($rsync)){ $GLOBALS["COMMANDLINECOPY"]="$rsync -ar {SRC_PATH} {NEXT} --stats --chmod=ug=rwX,o=rwX"; }else{ $GLOBALS["COMMANDLINECOPY"]="/bin/cp -ru {SRC_PATH} {NEXT}"; } $GLOBALS["COMMANDLINE_MOUNTED_PATH"]=$mount_path; writelogs(date('m-d H:i:s')." "."[TASK $ID]: OK !",__FUNCTION__,__FILE__,__LINE__); if($GLOBALS["ONLY_TESTS"]){writelogs(date('m-d H:i:s')." "."<H2>{success}</H2>",__FUNCTION__,__FILE__,__LINE__);} return true; }else{ backup_events($ID,"initialization","ERROR, (usb) $mount_path/$md5 permission denied"); exec("umount -l $mount_path"); } }
function tasks_rows() { $sql = new mysql(); $sock = new sockets(); $tpl = new templates(); $backup = new backup_protocols(); $cron = new cron_macros(); $storages["usb"] = "{usb_external_drive}"; $storages["smb"] = "{remote_smb_server}"; $storages["rsync"] = "{remote_rsync_server}"; $storages["automount"] = "{automount_ressource}"; $storages["local"] = "{local_directory}"; $storages["ssh"] = "{remote_ssh_service}"; $MyPage = CurrentPageName(); $q = new mysql(); $search = '%'; $table = "backup_schedules"; $page = 1; if ($q->COUNT_ROWS($table, "artica_backup") == 0) { json_error_show("No task..."); } if (isset($_POST["sortname"])) { if ($_POST["sortname"] != null) { $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}"; } } if (isset($_POST['page'])) { $page = $_POST['page']; } if ($_POST["query"] != null) { $_POST["query"] = str_replace("*", "%", $_POST["query"]); $search = $_POST["query"]; $searchstring = "AND (`{$_POST["qtype"]}` LIKE '{$search}')"; $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE 1 {$searchstring}"; $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup")); if (!$q->ok) { json_error_show($q->mysql_error); } $total = $ligne["TCOUNT"]; } else { $total = $q->COUNT_ROWS($table, "artica_backup"); } if (isset($_POST['rp'])) { $rp = $_POST['rp']; } $pageStart = ($page - 1) * $rp; $limitSql = "LIMIT {$pageStart}, {$rp}"; $sql = "SELECT * FROM `{$table}` WHERE 1 {$searchstring} {$ORDER} {$limitSql}"; writelogs($sql, __FUNCTION__, __FILE__, __LINE__); $data = array(); $data['page'] = $page; $data['total'] = $total; $data['rows'] = array(); $results = $q->QUERY_SQL($sql, "artica_backup"); if (!$q->ok) { json_error_show($q->mysql_error); } $fontsize = 14; while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $ressources = unserialize(base64_decode($ligne["datasbackup"])); $sources = count($ressources) - 1 + FOLDER_BACKUPED_NUMBER($ligne["ID"]) . " {sources}"; $sources = "<a href=\"javascript:Loadjs('backup.sources.tasks.php?ID={$ligne["ID"]}')\" style='text-decoration:underline;font-size:{$fontsize}px'>{$sources}</a>"; $run = imgsimple("run-24.png", "{run_task}", "BACKUP_TASK_RUN({$ligne["ID"]})"); if ($ligne["pid"] > 5) { $array_pid = unserialize(base64_decode($sock->getFrameWork("cmd.php?procstat={$ligne["pid"]}"))); if ($array_pid["since"] != null) { $run = imgsimple("ajax-menus-loader.gif", "{running}: {since} {$array_pid["since"]}", ""); } } $sql = "SELECT SUM(size) as tsize FROM backup_storages WHERE taskid={$ligne["ID"]}"; $ligneSize = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup")); $sizeStorages = FormatBytes($ligneSize["tsize"]); $divStart = "<span style='font-size:{$fontsize}px'>"; $divStop = "</span>"; $data['rows'][] = array('id' => $ligne["ID"], 'cell' => array("{$divStart}{$ligne["ID"]}{$divStop}", imgsimple("events-24.png", "{events}", "TASK_EVENTS_DETAILS({$ligne["ID"]})"), $run, imgsimple("eclaire-24.png", "{BACKUP_TASK_TEST}", "BACKUP_TASK_TEST({$ligne["ID"]})"), "<a href=\"javascript:BACKUP_TASK_MODIFY_RESSOURCES('{$ligne["ID"]}')\" style='text-decoration:underline;font-size:{$fontsize}px'>" . $tpl->_ENGINE_parse_body($storages[$ligne["resource_type"]]) . "</a>", "<a href=\"javascript:BACKUP_TASK_SHOW_CONTAINERS('{$ligne["ID"]}')\" style='text-decoration:underline;font-size:{$fontsize}px'>" . $backup->extractFirsRessource($ligne["pattern"]) . "</a> ({$sizeStorages})", "{$divStart}" . $tpl->_ENGINE_parse_body($cron->cron_human($ligne["schedule"])) . "{$divStop}", "{$divStart}" . $tpl->_ENGINE_parse_body($sources) . "{$divStop}", imgsimple("delete-24.png", "{delete}", "DeleteBackupTask({$ligne["ID"]})"))); } echo json_encode($data); }