<HTML>
<HEAD>
<TITLE>File Utilities</TITLE>
</HEAD>
<BODY bgcolor="#99CCCC" background="../graphics/web3.jpg">
<center>
<h2>File Utilities</h2>

<?
   //check for file to act on
   if(isset($File) && $File != ""){
      $ok = 0;
      $listfile = $uname.".dat";
    
      if($uname != "" && $pword != ""){
        if(file_exists($listfile)){
          $pass = file("ul.txt");
          $un = substr($uname,0,2);
          $pw = substr($pword,0,2);
           
          for($index = 0; $index < count($pass); $index++){
            if(ereg("^$un",$pass[$index])){
              if(ereg(":$pw",$pass[$index])){
                $ok = 1;
                break;
              }
            }
          }              
        }
      }
      else{
        print("You need to supply your username and password<p><HR><p>\n");
      }

      if(!(file_exists($File))){
        $ok = 0;
        print("Can't find $File<p><HR><p>\n");
      }
     
      if($ok){
      
        if($action == "copy"){
          if($destname != ""){
            if(file_exists($destname) && $overwrite != "on"){
              print("A file already exists by the name of $destname<br>Choose another name or else check the <i>Overwrite</i> box<p><HR><p>\n");
            }
            else {
              $size = filesize($destname);
              if(copy($File, $destname)) {
                print("$File copied to<br> $destname: size - $size perm - \n");
                printf("%o", (fileperms($destname) & 0777));
                print("<p><HR><p>\n");
              }
              else {
                print("$File could not be copied to $destname<p><HR><p>\n");
              }
            }
          }
          else {
            print("You need to supply a destination filename to which to copy $File<p><HR><p>\n");
          }
        }
        else if($action == "move") {
          if($destname != ""){
            if(file_exists($destname) && $overwrite != "on"){
              print("A file already exists by the name of $destname<br>Choose another name or else check the <i>Overwrite</i> box<p><HR><p>\n");
            }
            else {
              $size = filesize($destname);
              if(copy($File, $destname)) {
                print("$File moved to<br> $destname: size - $size perm - \n");
                printf("%o", (fileperms($destname) & 0777));
                print("<p><HR><p>\n");
                unlink($File);
              }
              else {
                print("$File could not be moved to $destname<p><HR><p>\n");
              }
            }
          }
          else {
            print("You need to supply a destination filename to which to move $File<p><HR><p>\n");
          }          
        }
        else if($action == "rename") {
          if($destname != ""){
            if(file_exists($destname) && $overwrite != "on"){
              print("A file already exists by the name of $destname<br>Choose another name or else check the <i>Overwrite</i> box<p><HR><p>\n");
            }
            else {
              $size = filesize($destname);
              if(rename($File, $destname)) {
                print("$File renamed to<br> $destname: size - $size perm - \n");
                printf("%o", (fileperms($destname) & 0777));
                print("<p><HR><p>\n");
              }
              else {
                print("$File could not be renamed to $destname<p><HR><p>\n");
              }
            }
          }
          else {
            print("You need to supply a destination filename to which to rename $File<p><HR><p>\n");
          }          
        }
        else if($action == "chmod") {
          if($mode != ""){
            if(!(file_exists($File))){
              print("Can't find $File<p><HR><p>\n");
            }
            else {
              $size = filesize($File);
              if($mode == "777"){ $setperm = 0777;}
              else if($mode == "755"){ $setperm = 0755;}
              else if($mode == "744"){ $setperm = 0744;}
              else if($mode == "711"){ $setperm = 0711;}
              else if($mode == "700"){ $setperm = 0700;}
              else if($mode == "666"){ $setperm = 0666;}
              else if($mode == "644"){ $setperm = 0644;}
              else if($mode == "600"){ $setperm = 0600;}
              else { $setperm = "755";}
              if(chmod($File, $setperm)) {
                print("$File chmodded to<br> \n");
                printf("%o", (fileperms($File) & 0777));
                print("<br>size - $size <p><HR><p>\n");
              }
              else {
                print("$File could not be chmodded<p><HR><p>\n");
              }
            }
          }
          else {
            print("You need to select an option to which to chmod $File<p><HR><p>\n");
          }          
        }        
      }
      else {
        print("You haven't specified an action to perform on $File<p><HR><p>\n");        
      }
   }
?>

<table border=2 cellpadding=8 bgcolor="#99CCCC">
<td>
<FORM ACTION="utl.php3" METHOD="post"> 
<center><INPUT NAME="File" SIZE=30 TYPE="text"> Src Filename<br>
<INPUT TYPE='text' name='destname' size=30> Dst Filename<p></center>
Choose an action for this file:<br>
<input type="radio" name="action" value="copy"> Copy <br>
<input type="radio" name="action" value="move"> Move <br>
<input type="radio" name="action" value="rename"> Rename <p>
<input type="radio" name="action" value="chmod"> Chmod<br>
<input type=radio name="mode" value="777"> 777<br>
<input type=radio name="mode" value="755"> 755<br>
<input type=radio name="mode" value="744"> 744<br>
<input type=radio name="mode" value="711"> 711<br>
<input type=radio name="mode" value="700"> 700<br>
<input type=radio name="mode" value="666"> 666<br>
<input type=radio name="mode" value="644"> 644<br>
<input type=radio name="mode" value="600"> 600
<p>
<INPUT TYPE='checkbox' name='overwrite' value='on'> Overwrite if Dst file already exists
<p>

<center><table><td>
<INPUT TYPE=TEXT SIZE=23 NAME="uname"> username<br>
<INPUT TYPE=password SIZE=23 NAME="pword"> password</td></table>
<p>
<INPUT TYPE="submit" VALUE="Submit"></center></FORM></td></table><p>
<hr size=2><a href="http://global-dialog.org/" target=_top> [ Global Dialog Home ] </a>&nbsp;&nbsp;<a href="http://global-dialog.org/mvd"> [ MVD Home ] </a>&nbsp;&nbsp;<a href="mvl.cgi?NextName=List"> [ List ] </a><hr>
<br>
</center>
</BODY>
</HTML>
