Current File : //root/panel/modules/backupwizard/code/controller.ext.php |
<?php
/**
* @copyright 2014-2015 Sentora Project (http://www.sentora.org/)
* Sentora is a GPL fork of the ZPanel Project whose original header follows:
*
* ZPanel - A Cross-Platform Open-Source Web Hosting Control panel.
*
* @package ZPanel
* @version $Id$
* @author Bobby Allen - ballen@bobbyallen.me
* @copyright (c) 2008-2014 ZPanel Group - http://www.zpanelcp.com/
* @license http://opensource.org/licenses/gpl-3.0.html GNU Public License v3
*
* This program (ZPanel) is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
class module_controller extends ctrl_module
{
static $deleteok;
static $backupok;
static $filenotexist;
static $tryagain;
static $service_port;
static $address;
static $socket;
static function ListBackUps($userid)
{
$currentuser = ctrl_users::GetUserDetail($userid);
$userid = $currentuser['userid'];
$username = $currentuser['username'];
$res = array();
$dirFiles = array();
$backupdir = ctrl_options::GetSystemOption('hosted_dir') . $username . "/";
if ($handle = opendir($backupdir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && stristr($file, "_") && substr($file, -4) == ".zip") {
$dirFiles[] = $file;
}
}
}
closedir($handle);
if (!fs_director::CheckForEmptyValue($dirFiles)) {
sort($dirFiles);
foreach ($dirFiles as $file) {
$filesize = fs_director::ShowHumanFileSize(filesize($backupdir . $file));
$filedate = date("F d Y H:i:s", filemtime($backupdir . $file));
array_push($res, array('backupfile' => substr($file, 0, -4),
'created' => $filedate,
'filesize' => $filesize));
}
}
self::array_sort_by_column($res, 'created');
return $res;
}
static function array_sort_by_column(&$arr, $col, $dir = SORT_ASC)
{
$sort_col = array();
foreach ($arr as $key => $row) {
$sort_col[$key] = $row[$col];
}
array_multisort($sort_col, $dir, $arr);
}
static function CheckHasData($userid)
{
$currentuser = ctrl_users::GetUserDetail($userid);
$datafolder = ctrl_options::GetSystemOption('hosted_dir') . $currentuser['username'] . "/public_html/";
$dirFiles = array();
if ($handle = opendir($datafolder)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$dirFiles[] = $file;
}
}
}
closedir($handle);
if (!fs_director::CheckForEmptyValue($dirFiles)) {
return true;
}
return false;
}
static function ExecuteBackup($userid, $download = 0)
{
global $zdbh;
global $controller;
$currentuser = ctrl_users::GetUserDetail($userid);
runtime_hook::Execute('OnBeforeCreateBackup');
runtime_hook::Execute('OnAfterCreateBackup');
}
static function gethelpicon()
{
global $zdbh;
global $controller;
$temp=$controller->GetControllerRequest('URL','module') ;
$val = '/assets/one.txt';
$val1 = '/modules/';
$name=file_get_contents("modules/$temp/assets/helpicon.txt");
return $name;
}
static function readfile_chunked($filename)
{
$chunksize = 1 * (1024 * 1024);
$buffer = '';
$handle = fopen($filename, 'rb');
if ($handle === false) {
return false;
}
while (!feof($handle)) {
$buffer = fread($handle, $chunksize);
print $buffer;
}
return fclose($handle);
}
static function ExecuteDeleteBackup($username, $file)
{
runtime_hook::Execute('OnBeforeDeleteBackup');
$backup_file_to_delete = ctrl_options::GetSystemOption('hosted_dir') . $username . "/" . $file . ".zip";
unlink($backup_file_to_delete);
runtime_hook::Execute('OnAfterDeleteBackup');
}
static function ExecuteCreateBackupDirectory($username)
{
$backupdir = ctrl_options::GetSystemOption('hosted_dir') . $username . "/";
if (!is_dir($backupdir)) {
fs_director::CreateDirectory($backupdir);
}
}
static function CheckPurgeDate()
{
if (strtolower(ctrl_options::GetSystemOption('purge_bu')) == "true") {
return ctrl_options::GetSystemOption('purge_date');
} else {
return false;
}
}
static function doBackup()
{
global $zdbh;
global $controller;
$userid = $controller->GetControllerRequest('FORM', 'inBackUp');
$download = $controller->GetControllerRequest('FORM', 'inDownLoad');
self::ExecuteBackup($userid, $download);
self::$backupok = true;
}
static function doDeleteBackup()
{
global $zdbh;
global $controller;
runtime_csfr::Protect();
$currentuser = ctrl_users::GetUserDetail();
$userid = $currentuser['userid'];
$username = $currentuser['username'];
$files = self::ListBackUps($userid);
//print_r($_POST);
foreach ($files as $file) {
if (!fs_director::CheckForEmptyValue($controller->GetControllerRequest('FORM', 'inDelete_' . $file['backupfile'] . '')) ||
!fs_director::CheckForEmptyValue($controller->GetControllerRequest('FORM', 'inDelete_' . $file['backupfile'] . '_x')) ||
!fs_director::CheckForEmptyValue($controller->GetControllerRequest('FORM', 'inDelete_' . $file['backupfile'] . '_y'))) {
self::ExecuteDeleteBackup($username, $file['backupfile']);
self::$deleteok = true;
}
}
}
static function GetHasData()
{
global $controller;
$currentuser = ctrl_users::GetUserDetail();
return self::CheckHasData($currentuser['userid']);
}
static function GetBackUpList()
{
global $controller;
$currentuser = ctrl_users::GetUserDetail();
return self::ListBackUps($currentuser['userid']);
}
static function GetFileLocation()
{
global $controller;
$currentuser = ctrl_users::GetUserDetail();
$filelocation = $currentuser['username'] . "/";
return $filelocation;
}
static function getUserID()
{
global $controller;
$currentuser = ctrl_users::GetUserDetail();
$userid = $currentuser['userid'];
return $userid;
}
static function GetDiskAllowed()
{
global $controller;
if (strtolower(ctrl_options::GetSystemOption('disk_bu')) == "true")
return true;
return false;
}
static function GetPurgeDate()
{
return self::CheckPurgeDate();
}
static function getCreateBackupDirectory()
{
$currentuser = ctrl_users::GetUserDetail();
if (self::ExecuteCreateBackupDirectory($currentuser['username']))
return true;
return false;
}
static function GetBUOption($name)
{
global $zdbh;
// $result = $zdbh->query("SELECT bus_value_tx FROM x_backup_settings WHERE bus_name_vc = '$name'")->Fetch();
$sql = $zdbh->prepare("SELECT bus_value_tx FROM x_backup_settings WHERE bus_name_vc = :name");
$sql->bindParam(':name', $name);
$sql->execute();
$result = $sql->fetch();
if ($result) {
return $result['bus_value_tx'];
} else {
return false;
}
}
static function getResult()
{
if (!fs_director::CheckForEmptyValue(self::$tryagain)) {
return ui_sysmessage::shout(ui_language::translate("<strong>Error:</strong> Please try again Later. Server service not available."), "Error");
}
if (!fs_director::CheckForEmptyValue(self::$filenotexist)) {
return ui_sysmessage::shout("There was an error saving your backup!", "zannounceerror");
}
if (!fs_director::CheckForEmptyValue(self::$deleteok)) {
return ui_sysmessage::shout("Backup deleted successfully!", "zannounceok");
}
if (!fs_director::CheckForEmptyValue(self::$backupok)) {
return ui_sysmessage::shout("Backup completed successfully!", "zannounceok");
}
return;
}
////////////////////////Backup_Started///////////////////////////////////////////////////////////////////////////////
////////////////////////Full_backup_Started//////////////////////////////////////////////////////////////////////
//To run the Fullbackup process
static function dofullbacku()
{
$line='';
$currentuser = ctrl_users::GetUserDetail();
$username= $currentuser['username'];
$service_port = 4444 ;
$address = gethostbyname('localhost');
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false)
{
// echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
self::$tryagain=true;
return false;
}
// echo "Attempting to connect to '$address' on port '$service_port'...";
$result = socket_connect($socket, $address, $service_port);
if ($result === false)
{
//echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
self::$tryagain=true;
return false;
}
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec" => 1, "usec" =>0));
//$backupname = "Full".$username. "_" . date("M-d-Y_hms", time());
$in="command fullbackup $username";
$out = '';
socket_write($socket, $in, strlen($in));
$output = "" ;
socket_close($socket);
exit;
return true ;
}
//To show the backup is completed or its in process
static function dothefilecont()
{
$currentuser = ctrl_users::GetUserDetail();
$username= $currentuser['username'];
$temp= file_get_contents("/backup/$username.full.txt");
$arra=explode(';',$temp);
$tempc= file_get_contents("/backup/current_full_$username");
//echo count($arra);
if($arra[0]==1)
{
echo "backup is under process ";
}
else if($arra[0]==0)
{
echo "The recent backup file has been created with the file"." ".":".$tempc;
}
else{ echo ""; }
exit;
}
///To get the backup log
static function dofullprog()
{
$currentuser = ctrl_users::GetUserDetail();
$username= $currentuser['username'];
echo $temp= "<pre>".file_get_contents("/backup/home_bk_$username.log")."</pre>";exit;
return $temp;
}
//////////////////////////////////Full_backup_completed/////////////////////////////////////////////////////
//////////////////////////////////Home_backup_Started///////////////////////////////////////////////////////
//To run the Homebackup process
static function dohomedirbk()
{
$line='';
$currentuser = ctrl_users::GetUserDetail();
$username= $currentuser['username'];
$service_port = 4444 ;
$address = gethostbyname('localhost');
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
// echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
self::$tryagain=true;
return false;
}
// echo "Attempting to connect to '$address' on port '$service_port'...";
$result = socket_connect($socket, $address, $service_port);
if ($result === false) {
// echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
self::$tryagain=true;
return false;
}
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec" => 1, "usec" =>0));
//$backupname = "Full".$username. "_" . date("M-d-Y_hms", time());
$in="command homebk $username";
$out = '';
socket_write($socket, $in, strlen($in));
$output = "" ;
socket_close($socket);
exit;
return true ;
}
//To show the backup is completed or its in process
static function dohomefilecont()
{
$currentuser = ctrl_users::GetUserDetail();
$username= $currentuser['username'];
$temp= file_get_contents("/backup/$username.home.txt");
$tempd= file_get_contents("/backup/current_home_$username");
$arra=explode(';',$temp);
if($arra[0]==1)
{
echo "backup is under process ";
}
else if($arra[0]==0)
{
echo "The recent backup file has been created with the file"." ".":".$tempd;
}
else{echo "";}
exit;
}
///To get the backup log
static function dohomeprog()
{
$currentuser = ctrl_users::GetUserDetail();
$username= $currentuser['username'];
echo $temp = "<pre>".file_get_contents("/backup/full_bk_$username.log")."</pre>";exit;
return $temp;
}
/////////////////////////////Home_Backup_Complted/////////////////////////////////////////////////////////////////////
/////////////////////////////Mysql_Backup_Started/////////////////////////////////////////////////////////////////////
//To run the Mysql backup process
static function domysqlbk()
{
$line='';
$currentuser = ctrl_users::GetUserDetail();
$username= $currentuser['username'];
$service_port = 4444 ;
$address = gethostbyname('localhost');
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
// echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
self::$tryagain=true;
return false;
}
// echo "Attempting to connect to '$address' on port '$service_port'...";
$result = socket_connect($socket, $address, $service_port);
if ($result === false) {
// echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
self::$tryagain=true;
return false;
}
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec" => 1, "usec" =>0));
//$backupname = "Full".$username. "_" . date("M-d-Y_hms", time());
$in="command mysqllbk $username";
$out = '';
socket_write($socket, $in, strlen($in));
$output = "" ;
socket_close($socket);
exit;
return true ;
}
//To show the backup is completed or its in process
static function domysqlfilecont()
{
$currentuser = ctrl_users::GetUserDetail();
$username= $currentuser['username'];
$temp= file_get_contents("/backup/$username.mysql.txt");
$tempe= file_get_contents("/backup/current_mysql_$username");
$arra=explode(';',$temp);
if($arra[0]==1)
{
echo "backup is under process";
}
else if($arra[0]==0)
{
echo "The recent backup file has beeen created with the file"." ".":".$tempe;
}
else{echo "";}
exit;
}
///To get the backup log
static function domysqlprog()
{
$currentuser = ctrl_users::GetUserDetail();
$username= $currentuser['username'];
echo $temp= "<pre>".file_get_contents("/backup/mysql_bk_$username.log")."</pre>";exit;
return $temp;
}
////////////////////////////Mysql_Backup_Complted//////////////////////////////////////////////////////
/////////////////////////////Mail_Backup_Started///////////////////////////////////////////////////////
//To run the mailbackup process
static function domailbuk()
{
$line='';
$currentuser = ctrl_users::GetUserDetail();
$username= $currentuser['username'];
$service_port = 4444 ;
$address = gethostbyname('localhost');
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
// echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
self::$tryagain=true;
return false;
}
// echo "Attempting to connect to '$address' on port '$service_port'...";
$result = socket_connect($socket, $address, $service_port);
if ($result === false) {
// echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
self::$tryagain=true;
return false;
}
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec" => 1, "usec" =>0));
//$backupname = "Full".$username. "_" . date("M-d-Y_hms", time());
$in="command mailbackup $username";
$out = '';
socket_write($socket, $in, strlen($in));
$output = "" ;
socket_close($socket);
exit;
return true ;
}
//To show the backup is completed or its in process
static function domailfilecont()
{
$currentuser = ctrl_users::GetUserDetail();
$username= $currentuser['username'];
$temp= file_get_contents("/backup/$username.mail.txt");
$tempf= file_get_contents("/backup/current_mail_$username");
$arra=explode(';',$temp);
if($arra[0]==1)
{
echo "backup is under process";
}
else if($arra[0]==0)
{
echo "The recent backup file has beeen created with the file"." ".":".$tempf;
}
else{echo "";}
exit;
}
///To get the backup log
static function domailprog()
{
$currentuser = ctrl_users::GetUserDetail();
$username= $currentuser['username'];
echo $temp= "<pre>".file_get_contents("/backup/mail_bk_$username.log")."</pre>";exit;
return $temp;
}
/////////////////////////////Mail_Backup_Comlpted/////////////////////////////////////////////////////////////////
//////////////////////////////Backup_Complted//////////////////////////////////////////////////////////////////////
/////////////////////////////////Restore_started////////////////////////////////////////////////////////////////////
/////////////////////////////////Full_Restore_Started////////////////////////////////////////////////////////////////
//To call the fullrestore functionality
static function dofullresto()
{
global $zdbh;
global $controller;
$formvars = $controller->GetAllControllerRequests('FORM');
$filename = $formvars['value'];
$line='';
$currentuser = ctrl_users::GetUserDetail();
$username= $currentuser['username'];
$service_port = 4444 ;
$address = gethostbyname('localhost');
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
// echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
self::$tryagain=true;
return false;
}
// echo "Attempting to connect to '$address' on port '$service_port'...";
$result = socket_connect($socket, $address, $service_port);
if ($result === false) {
// echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
self::$tryagain=true;
return false;
}
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec" => 1, "usec" =>0));
//$backupname = "Full".$username. "_" . date("M-d-Y_hms", time());
$in="command fullrestore $username $filename";
$out = '';
socket_write($socket, $in, strlen($in));
$output = "" ;
socket_close($socket);
echo "success" ;
exit;
}
//To display the backup files
static function getnfiles()
{
$currentuser = ctrl_users::GetUserDetail();
$username= $currentuser['username'];
$d_path ="/backup/$username/";
$f_path = $d_path."*.zip";
$count_d = strlen($d_path);
//echo $f_path ;
if(is_dir($d_path))
{
$dis_p ="<table ><tr><td>Name of the file</td><td>options</td></tr>";
$files = glob($f_path);
//print_r($files); exit;
foreach ($files as $filess)
{
$file_name= substr($filess,$count_d);
if( strpos( $file_name, 'Full_' ) === 0 )
{
$dis_p .="<tr><td>".$file_name."</td><td><input type='button' id='fr' value='Restore' class='delete btn btn-danger' onclick=\"fullres('".$file_name."'); fullprogrestore('".$file_name."');\"></td></tr>";
}
}
$dis_p .="</table>";
return $dis_p;
}
}
//Displays the process is completed or still under process
static function dofullrestoreshow()
{
global $zdbh;
global $controller;
$formvars = $controller->GetAllControllerRequests('FORM');
$filename = $formvars['value'];
$currentuser = ctrl_users::GetUserDetail();
$username = $currentuser['username'];
//$temp = file_get_contents("/backup/$username.fullrestore.txt");
$temp = file_get_contents("/backup/$username.full.txt");
//$tempf= file_get_contents("/backup/current_mail_$username");
//echo $temp."/backup/$username.fullrestore.txt \n";
$arra = explode(';',$temp);
//print_r($arra); exit;
if($arra[0]==1)
{
echo "Restore is under process";
}
else if($arra[0]==0)
{
echo "The recent restore has been finished successfully(if any)";
}
else{ echo "";}
exit;
}
//To get the log
static function dofullresproglog()
{
$currentuser = ctrl_users::GetUserDetail();
$username= $currentuser['username'];
echo $temp= "<pre>".file_get_contents("/backup/full_res_$username.log")."</pre>";exit;
return $temp;
}
////////////////////////FullRestore Complted////////////////////////////////////////////////////////
///////////////////////mail Restore Started//////////////////////////////////////////////////////////
//To call the mailrestore functionality
static function domailresto()
{
global $zdbh;
global $controller;
$formvars = $controller->GetAllControllerRequests('FORM');
$filename=$formvars['value'];
$line='';
$currentuser = ctrl_users::GetUserDetail();
$username= $currentuser['username'];
$service_port = 4444 ;
$address = gethostbyname('localhost');
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
// echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
self::$tryagain=true;
return false;
}
// echo "Attempting to connect to '$address' on port '$service_port'...";
$result = socket_connect($socket, $address, $service_port);
if ($result === false) {
// echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
self::$tryagain=true;
return false;
}
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec" => 1, "usec" =>0));
//$backupname = "Full".$username. "_" . date("M-d-Y_hms", time());
$in="command mailrestore $username $filename";
$out = '';
socket_write($socket, $in, strlen($in));
$output = "" ;
socket_close($socket);
exit;
return true ;
}
//To display the backup files
static function getmailfiles()
{
$currentuser = ctrl_users::GetUserDetail();
$username= $currentuser['username'];
$d_path ="/backup/$username/";
$f_path = $d_path."*.zip";
$count_d = strlen($d_path);
if(is_dir($d_path))
{
$dis_p ="<table ><tr><td>Name of the file</td><td>options</td></tr>";
$files = glob($f_path);
foreach ($files as $filess)
{
$file_name= substr($filess,$count_d);
if( strpos( $file_name, 'Mail_' ) === 0 )
{
$dis_p .="<tr><td>".$file_name."</td><td><input type='button' value='restore' class='delete btn btn-danger' onclick=\"mailres('".$file_name."');mailprogrestore('".$file_name."');\"></td></tr>";
}
}
$dis_p .="</table>";
return $dis_p;
}
}
//Displays the process is completed or still under process
static function domailrestoreshow()
{
global $zdbh;
global $controller;
$formvars = $controller->GetAllControllerRequests('FORM');
$filename=$formvars['value'];
$currentuser = ctrl_users::GetUserDetail();
$username= $currentuser['username'];
$temp= file_get_contents("/backup/$username.mailrestore.txt");
//$tempf= file_get_contents("/backup/current_mail_$username");
$arra=explode(';',$temp);
if($arra[0]==1)
{
echo "Restore is under process";
}
else if($arra[0]==0)
{
echo "The recent restore has been finished successfully(if any)";
}
else{ echo "nothing found on the status";}
exit;
}
//To get the log
static function domailresproglog()
{
$currentuser = ctrl_users::GetUserDetail();
$username= $currentuser['username'];
echo $temp= "<pre>".file_get_contents("/backup/mail_res_$username.log")."</pre>";exit;
return $temp;
}
//////////////////////////////////////////Mail restore Completed/////////////////////////////////////////////////////////
//////////////////////////////////////////Mysql Restore Started////////////////////////////////////////////////////////
//To call the mysqlrestore functionality
static function domysqlresto()
{
global $zdbh;
global $controller;
$formvars = $controller->GetAllControllerRequests('FORM');
$filename=$formvars['value'];
$line='';
$currentuser = ctrl_users::GetUserDetail();
$username= $currentuser['username'];
$service_port = 4444 ;
$address = gethostbyname('localhost');
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
// echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
self::$tryagain=true;
return false;
}
// echo "Attempting to connect to '$address' on port '$service_port'...";
$result = socket_connect($socket, $address, $service_port);
if ($result === false) {
// echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
self::$tryagain=true;
return false;
}
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec" => 1, "usec" =>0));
//$backupname = "Full".$username. "_" . date("M-d-Y_hms", time());
$in="command mysqlrestore $username $filename";
$out = '';
socket_write($socket, $in, strlen($in));
$output = "" ;
socket_close($socket);
exit;
return true ;
}
//To display the backup files
static function getmysqlfiles()
{
$currentuser = ctrl_users::GetUserDetail();
$username= $currentuser['username'];
$d_path ="/backup/$username/";
$f_path = $d_path."*.zip";
$count_d = strlen($d_path);
if(is_dir($d_path))
{
$dis_p ="<table ><tr><td>Name of the file</td><td>options</td></tr>";
$files = glob($f_path);
foreach ($files as $filess)
{
$file_name= substr($filess,$count_d);
if( strpos( $file_name, 'MySQL_' ) === 0 )
{
$dis_p .="<tr><td>".$file_name."</td><td><input type='button' value='restore' class='delete btn btn-danger' onclick=\"mysqlres('".$file_name."');mysqlprogrestore('".$file_name."');\"></td></tr>";
}
}
$dis_p .="</table>";
return $dis_p;
}
}
//Displays the process is completed or still under process
static function domysqlrestoreshow()
{
global $zdbh;
global $controller;
$formvars = $controller->GetAllControllerRequests('FORM');
$filename=$formvars['value'];
$currentuser = ctrl_users::GetUserDetail();
$username= $currentuser['username'];
$temp= file_get_contents("/backup/$username.mysqlrestore.txt");
//$tempf= file_get_contents("/backup/current_mail_$username");
$arra=explode(';',$temp);
if($arra[0]==1)
{
echo "Restore is under process";
}
else if($arra[0]==0)
{
echo "The recent restore has been finished successfully(if any)";
}
else{ echo "nothing found on the status";}
exit;
}
//To get the log
static function domysqlresproglog()
{
$currentuser = ctrl_users::GetUserDetail();
$username= $currentuser['username'];
echo $temp= "<pre>".file_get_contents("/backup/mysql_res_$username.log")."</pre>";exit;
return $temp;
}
////////////////////////////////Mysql restore Completed/////////////////////////////////////////////////////////////////
////////////////////////////////Home_Restore_Started///////////////////////////////////////////////////////////////////
//To call the homerestore functionality
static function dohomeresto()
{
global $zdbh;
global $controller;
$formvars = $controller->GetAllControllerRequests('FORM');
$filename=$formvars['value'];
$line='';
$currentuser = ctrl_users::GetUserDetail();
$username= $currentuser['username'];
$service_port = 4444 ;
$address = gethostbyname('localhost');
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
// echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
self::$tryagain=true;
return false;
}
// echo "Attempting to connect to '$address' on port '$service_port'...";
$result = socket_connect($socket, $address, $service_port);
if ($result === false) {
// echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
self::$tryagain=true;
return false;
}
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec" => 1, "usec" =>0));
//$backupname = "Full".$username. "_" . date("M-d-Y_hms", time());
$in="command homerestore $username $filename";
$out = '';
socket_write($socket, $in, strlen($in));
$output = "" ;
socket_close($socket);
exit;
return true ;
}
//To display the backup files
static function gethomefiles()
{
$currentuser = ctrl_users::GetUserDetail();
$username= $currentuser['username'];
$d_path ="/backup/$username/";
$f_path = $d_path."*.zip";
$count_d = strlen($d_path);
if(is_dir($d_path))
{
$dis_p ="<table ><tr><td>Name of the file</td><td>options</td></tr>";
$files = glob($f_path);
foreach ($files as $filess)
{
$file_name= substr($filess,$count_d);
if( strpos( $file_name, 'home_' ) === 0 )
{
$dis_p .="<tr><td>".$file_name."</td><td><input type='button' value='restore' class='delete btn btn-danger' onclick=\"homeres('".$file_name."');homeprogrestore('".$file_name."');\" ></td></tr>";
}
}
$dis_p .="</table>";
return $dis_p;
}
}
//Displays the process is completed or still under process
static function dohomerestoreshow()
{
global $zdbh;
global $controller;
$formvars = $controller->GetAllControllerRequests('FORM');
$filename=$formvars['value'];
$currentuser = ctrl_users::GetUserDetail();
$username= $currentuser['username'];
$temp= file_get_contents("/backup/$username.homerestore.txt");
//$tempf= file_get_contents("/backup/current_mail_$username");
$arra=explode(';',$temp);
if($arra[0]==1)
{
echo "Restore is under process";
}
else if($arra[0]==0)
{
echo "The recent restore has been finished successfully(if any)";
}
else{ echo "";}
exit;
}
//To get the log
static function dohomeresproglog()
{
$currentuser = ctrl_users::GetUserDetail();
$username= $currentuser['username'];
echo $temp= "<pre>".file_get_contents("/backup/home_res_$username.log")."</pre>";exit;
return $temp;
}
/////////////////////////////Home_restore_Comlpted////////////////////////////////////////////////////////////
static function getRestoreFolder(){
$line='';
$currentuser = ctrl_users::GetUserDetail();
$username= $currentuser['username'];
$homedir = ctrl_options::GetSystemOption('hosted_dir') . $username;
$backupdir = $homedir . "/";
$dircontents = scandir($backupdir);
// list the contents
$line='<ul class="ListedFiles">';
foreach ($dircontents as $file) {
$extension=substr($file,-7);
if($file!="." && $file!=".." && $extension==".tar.gz" )
$line.='<li> <input type="radio" name="restorefilename" value="'.$file.'" onchange="restorefilechange(this.value)">'.$file.'<br/></li>';
}
$line.='</ul>';
return $line;
}
}