Location: PHPKode > projects > web-cp - Web Hosting Control Panel > webcp/web/server/backup.phps
<?  /*
	// File:	backup.phps
	// Purpose:	backups
	// Author:	Peter Drake <hide@address.com>
	*/
	
// If data is set (i.e the submit button has been hit)
if (isset($data) && $userdata['type'] != 'demo') {
	switch ($action) {
		case 'create':
			if (is_array($data)) {
				// remove spaces and slashes.
				while (list($key, $val) = each($data))
					$data[$key] = trim(stripslashes($val));
		
				// If a command is sent to create a backup then go ahead
				if ($data['createbackup'] == "yes") {
					$domainlist = implode($domains, "_");
					$error = createBackup($domainlist, $data['scheduled'], $data['recurrance'], $data['immediate'], $data['database'], $data['files'], $data['email'], $data['ftplocal'], $data['ftpremote'], $data['ftpserver'], $data['username'], $data['password'], $data['directory']);
				
		
				// If an error is encountered then display message else display success
				if ($error) {
					echo "<br>&nbsp;&nbsp;• ".implode("<br>\n&nbsp;&nbsp;• ",$error)."<br>\n<br>";
				} else {
					unset($data);
					unset($domains);
					echo "<br><div align='center'><b>".$T['Backup Started for']."</b></div><br>\n";
				}
				}
		
			}
			break;
		case 'delete':

			if (is_array($backups)) {
				// remove spaces and slashes.
				while (list($key, $val) = each($data))
					$data[$key] = trim(stripslashes($val));
		
				// If a command is sent to delete a backup then go ahead
				if ($data['deletebackup'] == "yes") {
					$error = deleteBackup("sched", $backups);
				
		
				// If an error is encountered then display message else display success
				if ($error) {
					echo "<br>&nbsp;&nbsp;• ".implode("<br>\n&nbsp;&nbsp;• ",$error)."<br>\n<br>";
				} else {
					unset($data);
					unset($backups);
					echo "<br><div align='center'><b>".$T['Selected Backups Deleted']."</b></div><br>\n";
				}
				}
		
			}
			break;
		case 'deletelocal':
			if (is_array($backups)) {
		
				// If a command is sent to delete a backup then go ahead
				if ($data['deletebackup'] == "yes") {
					$error = deleteBackup("local", $backups);
				
		
				// If an error is encountered then display message else display success
				if ($error) {
					echo "<br>&nbsp;&nbsp;• ".implode("<br>\n&nbsp;&nbsp;• ",$error)."<br>\n<br>";
				} else {
					unset($data);
					unset($backups);
					echo "<br><div align='center'><b>".$T['Selected Backups Deleted']."</b></div><br>\n";
				}
				}
		
			}
			break;
		case 'restore':
			if (is_array($backups)) {
		
				// If a command is sent to restore a backup then go ahead
				if ($data['restorebackup'] == "yes") {
					$error = restoreBackup("local", $backups);
		
				// If an error is encountered then display message else display success
				if ($error) {
					echo "<br>&nbsp;&nbsp;• ".implode("<br>\n&nbsp;&nbsp;• ",$error)."<br>\n<br>";
				} else {
					unset($data);
					unset($backups);
					echo "<br><div align='center'><b>".$T['Selected Backups Restored']."</b></div><br>\n";
				}
				}
		
			}
			break;
		case 'upload':
			$filename = $HTTP_POST_FILES['backupfile']['name'];
			$error = is_uploaded_file($backupfile);
			copy($backupfile, $cfg['webdir']."/".$domain."/_backups/".$filename);
			if (!$error) {
				echo "<br>&nbsp;&nbsp;• ".$error."<br>\n<br>";
			} else {
				unset($backupfile);
				unset($domain);
				echo "<br><div align='center'><b>".$T['Selected Backup Uploaded']."</b></div><br>\n";
			}
			break;
	}
} elseif (isset($data) && $userdata['type'] == 'demo') {
	echo "<center>".$T['err']['demo user']."</center>";
}
?>
<table align=center cellpadding=0 cellspacing=0 width=500 class="tblbg">
	<tr class="tbltop">
		<td colspan=3><b>&nbsp;<? echo $T['Backup Functions']; ?>&nbsp;</b></td>
	</tr>
	<tr class="row1">
		<td width=110 align=right><b><a href='<?=$current_url;?>&ss=add'><?=$T['Create Backup'];?></a>&nbsp;</td><td align=left colspan=2><? echo $T['Create Backup Description']; ?></td>
	</tr>
	<tr class="row2">
		<td width=110 align=right><b><a href='<?=$current_url;?>&ss=del'><?=$T['Delete Backup'];?></a>&nbsp;</td><td align=left colspan=2><? echo $T['Delete Backup Description']; ?></td>
	</tr>
	<tr class="row1">
		<td width=110 align=right><b><a href='<?=$current_url;?>&ss=res'><?=$T['Restore Backup'];?></a>&nbsp;</td><td align=left colspan=2><? echo $T['Restore Backup Description']; ?></td>
	</tr>
</table>
<br>
<?
switch ($ss) {
	case "add":
?>
<form action="<?=$current_url;?>" method="post" name="webcp" onSubmit="submitonce(this);">
<input type="hidden" name="action" value="create">
<input type="hidden" name="ss" value="add">
<input type=hidden name="data[createbackup]" value="yes">
<table align=center cellpadding=0 cellspacing=0 width=500 class="tblbg">
	<tr class="tbltop">
		<td colspan=3><b>&nbsp;<? echo $T['Select Type']; ?>&nbsp;</b></td>
	</tr>
	<tr class="row1">
		<td width=30 align=center><input type=checkbox name=data[scheduled] <? if ($data['scheduled'] == "on") { echo "checked"; }?>></td><td align=left width=100><b><? echo $T['Scheduled']; ?></b></td><td>
			<select name=data[recurrance]>
			<option value=''>Please Select</option>
			<option value='1'<? if ($data['recurrance'] == "1") { echo "selected"; }?>><?=$T["Daily"];?></option>
			<option value='2'<? if ($data['recurrance'] == "2") { echo "selected"; }?>><?=$T["Weekly"];?></option>
			<option value='3'<? if ($data['recurrance'] == "3") { echo "selected"; }?>><?=$T["Monthly"];?></option>
			</select>
		</td>
	</tr>
	<tr class="row2">
		<td width=30 align=center><input type=checkbox name=data[immediate] <? if ($data['immediate'] == "on") { echo "checked"; }?>></td><td align=left><b><? echo $T['Immediate']; ?></b></td><td><? echo $T['Backup Immediate']; ?></td>
	</tr>
</table>
<br>
<table align=center cellpadding=0 cellspacing=0 width=500 class="tblbg">
	<tr class="tbltop">
		<td colspan=3><b>&nbsp;<? echo $T['Select Web Sites']; ?>&nbsp;</b></td>
	</tr>
	<? 
	
	$sql_query = "SELECT * FROM domains WHERE type='domain' AND action != 'remove' ORDER BY priority,domain";
	$dbp = mysql_query($sql_query);
	
	$curclass = "row2";
	
	for($i=0;$row=mysql_fetch_array($dbp);$i++) { 
		if ($curclass == "row2") { 
			$curclass = "row1"; 
		} else {
			$curclass = "row2";
		}
	
	?>
	<tr class="<? echo $curclass; ?>">
		<td width=30 align=center><input type=checkbox name=domains[] value='<? echo $row["domain"]; ?>' <? if (is_array($domains) && in_array($row["domain"], $domains)) { echo "checked"; }?>></td><td align=left colspan=2><b><? echo $row["domain"]; ?></b></td>
	</tr>
	<?} ?>
</table>
<br>
<table align=center cellpadding=0 cellspacing=0 width=500 class="tblbg">
	<tr class="tbltop">
		<td colspan=3><b>&nbsp;<? echo $T['Select Contents']; ?>&nbsp;</b></td>
	</tr>
	<tr class="row1">
		<td width=30 align=center><input type=checkbox name=data[files] <? if ($data['files'] == "on") { echo "checked"; }?>></td><td align=left><b><? echo $T['Files']; ?></b></td><td><? echo $T['Backup Files']; ?></td>
	</tr>
	<tr class="row2">
		<td width=30 align=center><input type=checkbox name=data[email] <? if ($data['email'] == "on") { echo "checked"; }?>></td><td align=left><b><? echo $T['Email']; ?></b></td><td><? echo $T['Backup Email']; ?></td>
	</tr>
	<tr class="row1">
		<td width=30 align=center><input type=checkbox name=data[database] <? if ($data['database'] == "on") { echo "checked"; }?>></td><td align=left><b><? echo $T['Databases']; ?></b></td><td><? echo $T['Backup Databases']; ?></td>
	</tr>
</table>
<br>	
<table align=center cellpadding=0 cellspacing=0 width=500 class="tblbg">
	<tr class="tbltop">
		<td colspan=3><b>&nbsp;<? echo $T['Select Location']; ?>&nbsp;</b></td>
	</tr>
	<tr class="row1">
		<td width=30 align=center><input type=checkbox name=data[ftplocal] <? if ($data['ftplocal'] == "on") { echo "checked"; }?>></td><td align=left><b><? echo $T['Local']; ?></b></td><td><? echo $T['Local Placement']; ?></td>
	</tr>
	<tr class="row2">
		<td width=30 align=center><input type=checkbox name=data[ftpremote] <? if ($data['ftpremote'] == "on") { echo "checked"; }?>></td><td align=left><b><? echo $T['Remote']; ?></b></td><td><? echo $T['Remote Placement']; ?></td>
	</tr>
	<tr class="row2">
		<td></td><td align=right><b><? echo $T['FTP Server']; ?>: </b></td><td><input type=textbox name="data[ftpserver]" value="<? echo $data['ftpserver']; ?>"></td>
	</tr>
	<tr class="row2">
		<td></td><td align=right><b><? echo $T['Username']; ?>: </b></td><td><input type=textbox name="data[username]" value="<? echo $data['username']; ?>"></td>
	</tr>
	<tr class="row2">
		<td></td><td align=right><b><? echo $T['Password']; ?>: </b></td><td><input type=password name="data[password]" value="<? echo $data['password']; ?>"></td>
	</tr>
	<tr class="row2">
		<td></td><td align=right><? echo $T['Directory']; ?>: </td><td><input type=textbox name="data[directory]" value="<? echo $data['directory']; ?>"></td>
	</tr>
</table><br>
<div align="center"><input type="submit" value="<? echo $T['Create Backup']; ?>"></div>
</form>
</div>
<?
	break;
	case "del":
	$SQL = "SELECT * FROM backups";
	$selfres = mysql_query($SQL);
?>

<form action="<?=$current_url;?>" method="post" name="webcp" onSubmit="submitonce(this);">
<input type="hidden" name="action" value="delete">
<input type="hidden" name="ss" value="del">
<input type=hidden name="data[deletebackup]" value="yes">

<table align=center cellpadding=0 cellspacing=0 width=600 class="tblbg">
	<tr class="tbltop">
		<td colspan=9><b>&nbsp;<? echo $T['Select Scheduled Backups']; ?>&nbsp;</b></td>
	</tr>
	<tr class="row2">
		<td></td><td><i><?=$T['Contents'];?></i></td><td align=center><i><?=$T['Frequency'];?></i></td><td align=center><i><?=$T['MySQL'];?></i></td><td align=center><i><?=$T['Files'];?></i></td><td align=center><i><?=$T['Email'];?></i></td><td align=center><i><?=$T['Remote'];?></i></td><td align=center><i><?=$T['Local'];?></i></td><td align=center><i><?=$T['Owner'];?></i></td>
	</tr>
<?
	$backupsFound = false;
	$curclass = "row2";
	for($i=0; $row=mysql_fetch_array($selfres); $i++) {
		$backupsFound = true;
		if ($curclass == "row2") {
			$curclass = "row1";
		} else {
			$curclass = "row2";
		}
		echo "<tr class=".$curclass."><td align=center><input type=checkbox name=backups[] value=".$row["id"]."></td><td>";
		if ($row["domain"] != "") {
			echo $row["domain"];
		} else {
			echo $T['Databases'];
		}
		echo "</td><td align=center>".$row["recurrance"]."</td><td align=center>";
		if ($row["databases"]) { echo "X"; } else { echo "-"; }
		echo "</td><td align=center>";
		if ($row["files"]) { echo "X"; } else { echo "-"; }
		echo "</td><td align=center>";
		if ($row["email"]) { echo "X"; } else { echo "-"; }
		echo "</td><td align=center>";
		if ($row["remote"]) { echo "X"; } else { echo "-"; }
		echo "</td><td align=center>";
		if ($row["local"]) { echo "X"; } else { echo "-"; }
		echo "</td><td align=center><a href='?cp=personal&url=userinfo&user=".$row["cpusername"]."'>".$row["cpusername"]."</a></td></tr>";
	}
?>
</table>
<div align="center">
<? if ($backupsFound) { ?>
<br><input type="submit" value="<? echo $T['Delete Backups']; ?>" onclick="return confirm('<?=$T['Confirm Delete Backups'];?>');">
<? } else { ?>
None Found
<? } ?>
</div>
</form>
<?
	$SQL = "SELECT domain FROM domains ORDER BY domain";
	$dres = mysql_query($SQL);
?>
<form action="<?=$current_url;?>" method="post" name="webcp" onSubmit="submitonce(this);">
<input type="hidden" name="action" value="deletelocal">
<input type="hidden" name="ss" value="del">
<input type=hidden name="data[deletebackup]" value="yes">

<table align=center cellpadding=0 cellspacing=0 width=600 class="tblbg">
	<tr class="tbltop">
		<td colspan=4><b>&nbsp;<? echo $T['Select Local Backups']; ?>&nbsp;</b></td>
	</tr>
	<tr class="row2">
		<td></td><td><i><?=$T['Contents'];?></i></td><td><i><?=$T['File Name'];?></i></td><td align=center><i><?=$T['File Size'];?></i></td>
	</tr>
<?
	
	$curclass = "row2";
	$backupsFound = false;
	$dirArray = backupDirList("/home/_backups");
	if (is_array($dirArray)) {
		for($j=0; $j<sizeOf($dirArray); $j++) {
			$backupsFound = true;
			if ($curclass == "row2") {
				$curclass = "row1";
			} else {
				$curclass = "row2";
			}
			echo "<tr class=".$curclass."><td align=center><input type=checkbox name=backups[] value='/home/_backups/".$dirArray[$j]."'></td><td>".$T['Databases']."</td><td>".$dirArray[$j]."</td><td align=center>".returnFileSize(filesize("/home/_backups/".$dirArray[$j]))."</td></tr>";
		}
	}
	for($i=0;$row=mysql_fetch_array($dres);$i++) {
		$dirArray = backupDirList("/home/".$row["domain"]."/_backups");
		if (is_array($dirArray)) {
			for($j=0; $j<sizeOf($dirArray); $j++) {
				$backupsFound = true;
				if ($curclass == "row2") {
					$curclass = "row1";
				} else {
					$curclass = "row2";
				}
				echo "<tr class=".$curclass."><td align=center><input type=checkbox name=backups[] value='/home/".$row["domain"]."/_backups/".$dirArray[$j]."'></td><td>".$row["domain"]."</td><td>".$dirArray[$j]."</td><td align=center>".returnFileSize(filesize("/home/".$row["domain"]."/_backups/".$dirArray[$j]))."</td></tr>";
			}
		}
	}
?>
</table>
<div align="center">
<? if ($backupsFound) { ?>
<br><input type="submit" value="<? echo $T['Delete Backups']; ?>" onclick="return confirm('<?=$T['Confirm Delete Backups'];?>');">
<? } else { ?>
None Found
<? } ?>
</div>
</form>
<?
	break;
	case "res":
?>

<form action="<?=$current_url;?>" method="post" name="webcp" onSubmit="submitonce(this);">
<input type="hidden" name="action" value="restore">
<input type="hidden" name="ss" value="res">
<input type=hidden name="data[restorebackup]" value="yes">
<?
	$SQL = "SELECT domain FROM domains ORDER BY domain";
	$dres = mysql_query($SQL);
?>
<table align=center cellpadding=0 cellspacing=0 width=600 class="tblbg">
	<tr class="tbltop">
		<td colspan=4><b>&nbsp;<? echo $T['Select Local Backups']; ?>&nbsp;</b></td>
	</tr>
	<tr class="row2">
		<td></td><td><i><?=$T['Contents'];?></i></td><td><i><?=$T['File Name'];?></i></td><td align=center><i><?=$T['File Size'];?></i></td>
	</tr>
<?
	
	$curclass = "row2";
	$backupsFound = false;
	for($i=0;$row=mysql_fetch_array($dres);$i++) {
		$dirArray = backupDirList("/home/".$row["domain"]."/_backups");
		if (is_array($dirArray)) {
			for($j=0; $j<sizeOf($dirArray); $j++) {
				$backupsFound = true;
				if ($curclass == "row2") {
					$curclass = "row1";
				} else {
					$curclass = "row2";
				}
				echo "<tr class=".$curclass."><td align=center><input type=checkbox name=backups[] value='/home/".$row["domain"]."/_backups/".$dirArray[$j]."'></td><td>".$row["domain"]."</td><td>".$dirArray[$j]."</td><td align=center>".returnFileSize(filesize("/home/".$row["domain"]."/_backups/".$dirArray[$j]))."</td></tr>";
			}
		}
	}
?>
</table>
<div align="center">
<? if ($backupsFound) { ?>
<br><input type="submit" value="<? echo $T['Restore Backups']; ?>" onclick="return confirm('<?=$T['Confirm Restore Backups'];?>');">
<? } else { ?>
None Found
<? } ?>
</div>
</form>
<?
$SQL = "SELECT domain FROM domains ORDER BY domain";
$dres = mysql_query($SQL);
?>
<Br>
<form action="<?=$current_url;?>" method="post" name="webcp" onSubmit="submitonce(this);" enctype="multipart/form-data">
<input type="hidden" name="action" value="upload">
<input type="hidden" name="ss" value="res">
<input type=hidden name="data[uploadbackup]" value="yes">
<table align=center cellpadding=0 cellspacing=0 width=600 class="tblbg">
	<tr class="tbltop">
		<td colspan=4><b>&nbsp;<? echo $T['Upload Remote Backups']; ?>&nbsp;</b></td>
	</tr>
	<tr class="row1">
		<td>Select a Domain: </td>
		<td>
			<select name=domain>
				<option value="">Please Select</option>
				<?
				for($i=0; $row=mysql_fetch_array($dres); $i++) {
					echo "<option value='".$row["domain"]."'>".$row["domain"]."</option>";
				}
				?>
			</select>
		</td>
	</tr>
	<tr class="row2">
		<td>Browse to Backup: </td><td><input type=file name=backupfile size=30></td>
	</tr>
</table>
<div align="center">
<br><input type="submit" value="<? echo $T['Upload Backup']; ?>">
</div>
</form>
<?
		break;
}
	
?>
Return current item: web-cp - Web Hosting Control Panel