function bar_process($vars) { global $barNlc, $barEcho; $barNlc = md5(__DIR__ . date('Ymd')); $barEcho = false; if (!function_exists('bar_vars')) { require dirname(__FILE__) . '/bar.php'; } $query = mysql_query("SELECT * FROM `mod_bar` where `status` = 'backingup'"); if (mysql_num_rows($query)) { while ($m = mysql_fetch_assoc($query)) { bar_message('check message'); if (strstr($vars['message'], '_' . $m['username'] . '.tar.gz') && strstr($vars['message'], 'backup-') && strstr($vars['message'], 'pkgacct')) { bar_message("Backup confirmation for " . $m['username'] . ': ' . $vars['message'], 'report'); if ($m['to'] > 0) { $result = bar_restore($m['id'], $m['from'], $m['to'], bar_vars()); if ($result['result'] == 1) { bar_message('Restore successful for ' . $m['username'] . ': ' . $result['output'], 'report'); } else { bar_message('Restore failed for ' . $m['username'] . ': ' . $result['output'], 'report'); } } else { bar_message('Backup completed for ' . $m['username'] . ': ' . $vars['message'], 'report'); bar_updatestatus($m['username'], 'completed'); } } } } return true; }
function bar_rename($ftp_server, $ftp_user_name, $ftp_user_pass, $username, $rdir) { // set up basic connection if ($conn_id = ftp_connect($ftp_server)) { // login with username and password if ($login_result = @ftp_login($conn_id, $ftp_user_name, $ftp_user_pass)) { // get contents of the current directory $files = ftp_nlist($conn_id, $rdir); // output $contents $maxTime = ''; foreach ($files as $file) { if (strstr($file, '.tar.gz') && strstr($file, 'backup-') && strstr($file, $username)) { $tmp = explode('_', $file); $tmp[0] = str_replace('backup-', '', $tmp[0]); list($MM, $dd, $yyyy) = explode('.', $tmp[0]); list($hh, $mm, $ss) = explode('-', $tmp[1]); $time = strtotime($yyyy . '-' . $MM . '-' . $dd . ' ' . $hh . ':' . $mm . ':' . $ss); if ($time > $maxTime) { $maxTime = $time; $backup = $file; } } } } else { bar_message('Login failed to ' . $ftp_server, 'error'); ftp_close($conn_id); return false; } if ($backup) { // try to rename $old_file to $new_file if (ftp_rename($conn_id, $rdir . $backup, $rdir . $username . '.tar.gz')) { bar_message("Successfully renamed {$rdir}{$backup} to {$rdir}{$username}.tar.gz"); ftp_close($conn_id); return true; } else { bar_message("There was a problem while renaming {$rdir}{$backup} to {$rdir}{$username}.tar.gz"); bar_updatestatus($username, 'restorefail'); ftp_close($conn_id); return false; } } else { bar_message("No backup file found for user {$username}"); bar_updatestatus($username, 'restorefail'); ftp_close($conn_id); return false; } // close the connection ftp_close($conn_id); } else { bar_message("Can't connect to FTP server at {$ftp_server}"); return false; } }