<?
    
//BACKUPSERVER ADMINISTRATION CODE
    
echo "<font face='Lucida Console' size='1'>Backup Server IP Address: ";
    
$ipx    getenv("SERVER_ADDR") ? getenv("SERVER_ADDR") : 0;
    echo 
"<b>";
    echo      !
$ipx "UNKNOWN" $ipx;
    echo 
"</b></font><br>";
    
$restartvar $_REQUEST['restart'] ;
    
$ipvar $_REQUEST['ipchange'] ;
    
$subnetchangevar $_REQUEST['subnetchange'] ;
    
$remoteipvar $_REQUEST['remoteip'] ;
    
$remotehostnamevar $_REQUEST['remotehostname'] ;
    
$remotesharevar $_REQUEST['remoteshare'] ;
    
$remoteusernamevar $_REQUEST['remoteusername'] ;
    
$remotepasswordvar $_REQUEST['remotepassword'] ;
    
$currentbackupsvar shell_exec('mount | sed \'/smbfs/!d\'');
    
exec("df -k | grep -v procfs |grep -v Filesystem|grep -v @|grep -v \"devfs\"|awk '{print $1\",\"$3\",\"$4\",\"$6\",\"$5}'>/tmp/df.tmp");
    
$datos file("/tmp/df.tmp");
    
unlink("/tmp/df.tmp");
    for (
$x=0;$x<sizeof($datos);$x++)
{
    list(
$device,$used,$remain,$mountpoint,$porcentaje) = split(",",$datos[$x]);
    
$total = ($used $remain);
    
$ajuste = ($remain/$total);

if (
$_POST['restart'])
{
    
shell_exec('/usr/local/bin/sudo /sbin/'.$restartvar.' -r +1');
}
 
if (
$_POST['remotehostname'])
{
    
shell_exec('echo ['.$remotehostnamevar.':'.$remoteusernamevar.'] >> /etc/nsmb.conf');
    
shell_exec('echo password='.$remotepasswordvar.' >> /etc/nsmb.conf'); 
    
shell_exec('echo //'.$remoteusernamevar.'@'.$remotehostnamevar.'/'.$remotesharevar.' /mnt/'.$remotesharevar.' smbfs rw,-N 0 0 >> /etc/fstab');
    echo 
"<script>document.location.href='".$_POST['page']."'</script>";
}

if (
$_POST['remoteshare'])
{
    
shell_exec('/usr/local/bin/sudo mkdir /mnt/'.$remotesharevar.'');
    
shell_exec('/usr/local/bin/sudo mount_smbfs -I '.$remoteipvar.' //'.$remoteusernamevar.'@'.$remotehostnamevar.'/'.$remotesharevar.' /mnt/'.$remotesharevar.'');
    echo 
"<script>document.location.href='".$_POST['page']."'</script>";
}
    
if (
$_POST['ipchange'])  
{
    
shell_exec('/usr/local/bin/sudo ifconfig lnc0 inet '.$ipvar.' netmask '.$subnetchangevar.'');
    echo  
"<br><br><font face='Lucida Console' size='1'>The new IP address for the Backup Server is: </font>";
    echo  
"<font face='Lucida Console' size='1' color='red'>IP: $ipvar Subnet: $subnetchangevar</font>";
    echo  
"<br><font face='Lucida Console' size='1'>Your Backup Server can now be accessed at the following location: <a href='http://$ipvar/admin.php'>http://$ipvar/admin.php</a></font>";
} else { 
//display form           
?>
<form name="change" action="<? $_SERVER['PHP_SELF']; ?>" method="post">
<br>
<table width="560" border="1">
<tr><td><br><b><font face='Lucida Console' size='2'>Server Administration</font></b></td></tr>
 <tr>
      <td><font face='Lucida Console' size='1'>Enter New IP Address</font>:   </td>
      <td align="left"><input name="ipchange" type="text" size="12" style="border: #000000 1px 
solid" value=""><font face='Lucida Console' size='1'> Netmask</font>:<input name="subnetchange" type="text" size="12" style="border: #000000 1px solid" value=""> <input type="image" name="submit" src="submit.gif" width="53" height="16"></td>
 </tr>
 <tr>
      <td><font face='Lucida Console' size='1'>Type "shutdown" to restart</font>:   </td>
      <td align="left"><input name="restart" type="text" size="6" style="border: #000000 1px
solid" value=""> <input type="image" name="submit" src="submit.gif" width="53" height="16"></td>
 </tr>
 <tr>
      <td colspan="2" align="left">
     <font face='Lucida Console' size='1' color='red'>NOTE:</font> <font face='Lucida Console' size='1'>Please close this window after clicking "submit". The server will reboot 1 minute after pressing "submit"</font>
 </tr>
<tr><td></td></tr>
<tr><td><br><b><font face='Lucida Console' size='2'>Create Connection</font></b></td></tr>
 <tr>
       <td><font face='Lucida Console' size='1'>IP of server to be backed up</font>:   </td>
       <td align="left"><input name="remoteip" type="text" size="12" style="border: #000000 1px solid" value=""></td>
 </tr>
 <tr>
       <td><font face='Lucida Console' size='1'>Hostname of server to be backed up</font>:   </td>
       <td align="left"><input name="remotehostname" type="text" size="12" style="border: #000000 1px solid" value=""><font face='Lucida Console' size='1' color='red'> CAPITAL LETTERS</font></td>
 </tr>
 <tr>
       <td><font face='Lucida Console' size='1'>Sharename to be backed up</font>:   </td>
       <td align="left"><input name="remoteshare" type="text" size="12" style="border: #000000 1px solid" value=""></td>
 </tr>
 <tr>
       <td><font face='Lucida Console' size='1'>Remote Username</font>:   </td>
       <td align="left"><input name="remoteusername" type="text" size="12" style="border: #000000 1px solid" value=""><font face='Lucida Console' size='1' color='red'> CAPITAL LETTERS</font>
 </tr>
 <tr>
       <td><font face='Lucida Console' size='1'>Remote Password</font>:   </td>                 
       <td align="left"><input name="remotepassword" type="text" size="12" style="border: #000000 1px solid" value=""> <input type="image" name="submit" src="submit.gif" width="53" height="16"></td>
 </tr> 
  </table>
<br>
<table width="560" border="1">
<td><br><b><font face='Lucida Console' size='2'>Server Disk Usage</font></b></td>
</table>
<table width="560" border="1">
<tr>
             <td width="100"><font face='Lucida Console' size='1'>Disk</font></td>
             <td width="100"><font face='Lucida Console' size='1'>Used Mb.</font></td>
             <td width="100"><font face='Lucida Console' size='1'>Avail Mb.</font></td>
             <td width="100"><font face='Lucida Console' size='1'>Mount Point</font></td>
             <td></td>
                <td><font face='Lucida Console' size='1'>Used</font></td>
            </tr>
<tr>
             <td width="100" align="left"><font face='Lucida Console' size='1'><?=$device;?>  </font></td>
             <td width="100" align="left"><font face='Lucida Console' size='1'><?=number_format(($used/1024),2);?>  </font></td>
             <td width="100" align="left"><font face='Lucida Console' size='1'><?=number_format(($remain/1024),2);?>  </font></td>
             <td width="100" align="left"><font face='Lucida Console' size='1'><?=$mountpoint;?>  </font></td>
                <td><table width="150" height="15" border="0" align="center" cellpadding="0" cellspacing="0" background="bar_back.jpg">
                     <tr>     
                     <td width="150" height="15" align="right"><img src="bar.gif" border="1" width="<?=(150 $ajuste);?>" height="13"></td>
                     </tr>
                    </table>
                </td>
                <td> <font face='Lucida Console' size='1'><?=$porcentaje;?></font></td>
            </tr>
</table>
<br>
<table width="560"  border="1">
      <tr>
        <td><br><b><font face='Lucida Console' size='2'>Current Backup Connections</font></b></td>
      </tr>
</table>
<?
exec
("df -k | sed 's/\/\///g' |grep -v procfs|grep -v /dev |grep -v Filesystem|grep -v \"devfs\"|awk '{print $1\",\"$3\",\"$4\",\"$6\",\"$5}'>/tmp/dfremote.tmp
"
);
exec("df -k | sed 's/\/\///g' |grep -v procfs|grep -v /dev |grep -v Filesystem|grep -v \"devfs\"|awk '{print $1}'>/tmp/dfremote2.tmp");
exec("awk -F/ '{print $2}' /tmp/dfremote2.tmp > /tmp/dfremote3.tmp");
$dataremote file("/tmp/dfremote.tmp");
$dataremote2 file("/tmp/dfremote3.tmp");
unlink("/tmp/dfremote.tmp");
unlink("/tmp/dfremote2.tmp");
unlink("/tmp/dfremote3.tmp");
for (
$x=0;$x<sizeof($dataremote);$x++)
{
     list(
$remotedevice) = split(",",$dataremote[$x]);
     list(
$removedevice2) = split(",",$dataremote2[$x]);

        
?>
<table border="1" width="560">
         <tr>
             <td width="300"><font face='Lucida Console' size='1'><?=$remotedevice;?></font></td>
             <td width="300"><font face='Lucida Console' size='1'><?=$removedevice2;?></font></td>
        </tr>
</table>
        <?
    
}
?>
<table width="560"  border="1">
      <tr>
        <td><br><b><font face='Lucida Console' size='2'><a href="snapshots/" target="cwindow">View Backups</a></font></b></td>
      </tr>
    </table>
</form>
<?
}
}
 
// end else
?>