The current time is 13:18:19
You are connected to phpmount.sourceforge.net

Online Code




* libclass.php
* libheader.php



libclass.php
<?
//
// phpMount - A PHP mount Interface
// http://phpmount.sourceforge.net/
//
// This program 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 2
// 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, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//
//



// Read the configuration file
include_once($HTTP_SERVER_VARS["DOCUMENT_ROOT"]."/phpmount.conf");








// Class phpMountConfig
//
// Koen Van Impe     -   cudeso.be
// phpMount              13/5/2003

// Public Methods

// Public Properties
//        copytoGroup
//        copytoTempBaseDir   (copy in a temp-directory)

class phpMountConfig
{
 var 
$_copytoGroup;
 var 
$_copytoTempBaseDir;
 var 
$intUseCopyToDir;

 function 
phpMountConfig($strCopytoGroup,$intUseCopyToDir,$strCopytoTempBaseDir)
  {
   
$this->copytoGroup $strCopytoGroup;
   
$this->copytoTempBaseDir $strCopytoTempBaseDir;
   
$this->copytoUseDir $intUseCopyToDir;
  }
}





// Class MountDevice
//
// Koen Van Impe     -   cudeso.be
// phpMount              10/5/2003


// Public Methods
//     MountDevice($intid,$strName,$strDevice,$strMountPoint,$strType,$strCopyTo,$clsBaseConfig)        Constructor
//     refresh
//     getStatus
//     setStatus
//     copyAll

// Public properties
//     id
//     name
//     device
//     mountpoint
//     type
//     copyto
//     filesystem
//     size
//     free
//     lastaction
//     icon
//     localtransferpath

class MountDevice
{
 
// user defined
 
var $id;
 var 
$name;
 var 
$device;
 var 
$mountpoint;
 var 
$type;
 var 
$copyto;
 var 
$config;
 var 
$localtransferpath;

 
// generated
 
var $filesystem;
 var 
$size;
 var 
$free;
 var 
$lastaction;
 var 
$icon;


 var 
$_mount_error_returncode = array (=> 'succes'
                                 
=> 'incorrect invocation or permissions'
                                 
=> 'system error (out of memory, cannot fork, no more loop devices)'
                                 
=> 'internal mount bug or missing nfs support in mount'
                                 
=> 'user interrupt'
                                
16 => 'problems writing or locking /etc/mtab'
                                
32 => 'mount failure'
                                
64 => 'some mount succeeded'
                            
);

 var 
$_copytoTempBaseDir "";
 var 
$_copytoGroup "";

 
// Constructor-function
 
function MountDevice($intid,$strName,$strDevice,$strMountPoint,$strType,$strCopyTo,$strLocalTransferPath,$clsBaseConfig)
  {
   
$unknown "** unknown **";

   
$this->config $clsBaseConfig;

   
// local transferpath is given by the user and should be at least 1 char, otherwise we default to nothing
   // if there's no value we won't return a link in the device-content
   
if (strlen(trim($strLocalTransferPath)) > 0)
     
$this->localtransferpath trim($strLocalTransferPath);
   else
     
$this->localtransferpath "";

   
// copyto is given by the user and should be at least 1 char, otherwise we default to "/tmp"
   
if (strlen(trim($strCopyTo)) > 0)
     
$this->copyto trim($strCopyTo);
   else
     
$this->copyto "/tmp";

   
// ID is given by the calling user (ex. record-id or array-id)
   
if ((is_numeric($intid)) && ($intid 0))
     
$this->id $intid;
   else
     
$this->id = -1;

   
// name is given by the user and should be at least 1 char, otherwise we default to unknown
   
if (strlen(trim($strName)) > 0)
     
$this->name trim($strName);
   else
     
$this->name $unknown;

   
// Device is the hardware-device and is given by the calling user
   
if (strlen(trim($strDevice)) > 0)
     
$this->device trim($strDevice);
   else
     
$this->device $unknown;

   
// mountpoint is the mountpoint and is given by the calling user
   
if (strlen(trim($strMountPoint)) > 0)
     
$this->mountpoint trim($strMountPoint);
   else
     
$this->mountpoint $unknown;

   
$this->lastaction "";

   
// If this object is mounted we get the size, free space and filesystem
   
if ($this->getStatus() == "mount")
    {
     
$this->size $this->_getDeviceInfo("SIZE");
     
$this->free $this->_getDeviceInfo("FREE");
     
$this->filesystem $this->_getDeviceInfo("FILESYSTEM");
    }
   else
   
// It is not mounted, go back to the defaults
    
{
     
$this->size $unknown;
     
$this->free $unknown;
     
$this->filesystem $unknown;
    }

   
// Type is a user-defined string and is given by the calling user
   
if (strlen(trim($strType)) > 0)
     
$this->type =$strType;
   else
    {
     
// check if we can define the type ourself
     
if (trim($this->filesystem) == "smbfs")
       
$this->type "smb";
     elseif ((
trim($this->mountpoint) == "/mnt/cdrom") || (trim($this->mountpoint) == "/mnt/cdrom1"))
       
$this->type "cd";
     else
       
$this->type $unknown;
    }


   
$this->_copytoTempBaseDir $clsBaseConfig->copytoTempBaseDir;
   
$this->_copytoGroup $clsBaseConfig->copytoGroup;

   
$this->icon $this->_getIcon();
  }

  
// Refresh all stats on a device
  
function refresh()
   {
    
$this->icon $this->_getIcon();
    
// If this object is mounted we get the size, free space and filesystem
    
if ($this->getStatus() == "mount")
     {
      
$this->size $this->_getDeviceInfo("SIZE");
      
$this->free $this->_getDeviceInfo("FREE");
      
$this->filesystem $this->_getDeviceInfo("FILESYSTEM");
     }
    else
    
// It is not mounted, go back to the defaults
     
{
      
$this->size $unknown;
      
$this->free $unknown;
      
$this->filesystem $unknown;
     }
   }


  
// Get the current status (mount/umount)
  // No variables because we only allow the device/mountpoint attached to this class
  
function getStatus()
   {
    if (
$this->_status($this->device,$this->mountpoint))
       return 
"mount";
    else
       return 
"umount";
   }

  
// Set the new status
  
function setStatus($strNewStatus)
   {
    if (
strtoupper(trim($strNewStatus)) == "MOUNT")
     {
      
$this->lastaction "[mount::<strong>".$this->name."</strong>] - ".$this->device." on ".$this->mountpoint;
      return 
$this->_my_mount();
     }
    elseif (
strtoupper(trim($strNewStatus)) == "UMOUNT")
     {
      
$this->lastaction "[unmount::<strong>".$this->name."</strong>] - ".$this->device." from ".$this->mountpoint;
      return 
$this->_my_umount();
     }
    else
      return 
"Unknown status";
   }

  function 
deleteAll($strDeleteType)
   {
    if (
strtoupper(trim($strDeleteType)) == "DEVICE")
      return 
$this->_delete($this->mountpoint);
    else
      return 
$this->_delete($this->copyto);
   }

  function 
copyAll($strCopyType)
   {
    if (
strtoupper(trim($strCopyType)) == "DEVICE")
      return 
$this->_copy($this->mountpoint,$this->copyto,"from ");
    else
      return 
$this->_copy($this->copyto,$this->mountpoint,"to ");
   }

  
// PRIVATE
  // delete
  
function _delete($strLocation)
   {
    
$strResult "";
    if (
strlen(trim($strLocation)) > 0)
     {
      if (
substr($strLocation,strlen($strLocation) - 1,1) == "/")
        
$strPath $strLocation;
      else
        
$strPath $strLocation."/";

      
$shellcmd "rm -rf ".$strPath."* ";
      
system($shellcmd,$mysyscall);
      if (
$mysyscall == 0)
        
$strResult "[delete::<strong>".$strPath."</strong>]<br>";
      else
        
$strResult "[delete::<strong>".$strPath."</strong>] - failed to delete files<br>".
                                
"shellcommand issued : ".$shellcmd;
     }
    return 
$strResult;
   }

  
// PRIVATE
  // copy
  
function _copy($strCopySource,$strCopyDst,$strCopyAction)
   {
    
$strResult "";
    if (
$this->getStatus() == "mount")
     {
      if (
substr($strCopyDst,strlen($strCopyDst) - 1,1) == "/")
        
$strPath $strCopyDst;
      else
        
$strPath $strCopyDst."/";
      if (
$clsBaseConfig->copytoUseDir == 1)
       {
        
// first we make a subdir as a destination for the copy
        
$tempFileName $this->_copytoTempBaseDir."-".date("Ymd");
        
$tempIndex 1;
        
$blnDirExist true;
        while(
$blnDirExist)
         {
          
$tempDir $strPath.$tempFileName."-".$tempIndex;
          if (
file_exists($tempDir))
           
$tempIndex++;
          else
           {
            
$blnDirExist false;
            break;
           }
         }

        
$resmkdir = @mkdir($tempDir);
       }
      else
       {
        
$tempDir $strPath;
        
$resmkdir true;
       }

      if (
$resmkdir)
       {
        
$shellcmd "cp -R ".$strCopySource."/* ".$tempDir;
        
system($shellcmd,$mysyscall);
        if (
$mysyscall == 0)
         {
          
$shellcmd "chgrp -R ".$this->_copytoGroup." ".$tempDir;
          
system($shellcmd,$mysyscall);
          if (
$mysyscall == 0)
            
$strResult .= "[copy::<strong>".$this->name."</strong>] - all to ".$tempDir."<br>";
          else
            
$strResult .= "Unable to copy all ".$strCopyAction.$this->name."<br>".
                              
"returned error : unable to change group-membership on directory ".$tempDir."<br>";
         }
        else
          
$strResult .= "Unable to copy all ".$strCopyAction.$this->name."<br>".
                              
"returned error : unable to copy files to directory ".$tempDir."<br>";

       }
      else
        
$strResult .= "Unable to copy all ".$strCopyAction.$this->name."<br>".
                                
"returned error : unable to create directory ".$tempDir."<br>";
     }
    else
     
$strResult .= "Unable to copy all ".$this->name."<br>".
                           
"returned error : device not mounted<br>";
     return 
$strResult;
   }



  
// PRIVATE
  // what icon do we need to show?
  
function _getIcon()
   {
    if (
$this->getStatus() == "mount")
      
$icon_postfix "mount.gif";
    else
      
$icon_postfix "umount.gif";

    if (
$this->type == "smb")
      return 
"smb".$icon_postfix;
    elseif (
$this->type == "cd")
      return 
"cd".$icon_postfix;
    elseif (
$this->type == "memstick")
      return 
$icon_postfix;
    else
      return 
$icon_postfix;
   }


  
// PRIVATE
  // get the current status, returns true/false
  
function _status($strDev,$strMount)
   {
    
$mylocalSysInfo = new sysinfo();
    
$localfilesystems $mylocalSysInfo->filesystems();
    
$tempresult false;
    foreach (
$localfilesystems as $fsitem)
     {
      if ((
$fsitem['disk'] == $strDev) && ($fsitem['mount'] == $strMount))
       {
        
$tempresult true;
        break;
       }
     }
    return 
$tempresult;
   }

  
// PRIVATE
  // get some kind of info from the device
  
function _getDeviceInfo($strTypeInfo)
   {
    
$mylocalSysInfo = new sysinfo();
    
$localfilesystems $mylocalSysInfo->filesystems();
    
$tempresult false;
    
$strTypeInfo strtoupper(trim($strTypeInfo));
    foreach (
$localfilesystems as $fsitem)
     {
      if ((
$fsitem['disk'] == $this->device) && ($fsitem['mount'] == $this->mountpoint))
       {
        if (
$strTypeInfo == "SIZE")
          
$tempresult $fsitem["size"];
        elseif (
$strTypeInfo == "FREE")
          
$tempresult $fsitem["free"];
        elseif (
$strTypeInfo "FILESYSTEM")
          
$tempresult $fsitem["fstype"];
        else
          
$tempresult "";
        break;
       }
     }
    return 
$tempresult;
   }

  
// PRIVATE
  // Set the new umount status
  
function _my_umount()
   {
    
system("umount ".$this->mountpoint,$mysyscall);
    if (!(
$mysyscall == 64 || $mysyscall == 0))
      return 
$this->_mount_error_returncode[$mysyscall];
    else
      return 
"";
   }

  
// PRIVATE
  // Set the new mount status
  
function _my_mount()
   {
    
system("mount ".$this->device,$mysyscall);
    if (!(
$mysyscall == 64 || $mysyscall == 0))
      return 
$this->_mount_error_returncode[$mysyscall];
    else
      return 
"";
   }

}









// Class phpFile_Folder
//
// Koen Van Impe     -   cudeso.be
// phpMount              10/5/2003


// Public Methods
//     phpFile_Folder($strName,$strType,$strLink,$strSize,$strDate)           Constructor

// Public properties
//     name
//     size
//     date
//     type
//     link

class phpFile_Folder
{
 var 
$name;
 var 
$link;
 var 
$type;
 var 
$date;
 var 
$size;
 function 
phpFile_Folder($strName,$strType,$strLink,$strSize,$strDate)
  {
   
$this->name $strName;
   
$this->size $strSize;
   
$this->date $strDate;
   
$this->type $strType;
   
$this->link $strLink;
  }
}







// Class phpFolder
//
// Koen Van Impe     -   cudeso.be
// phpMount              10/5/2003


// Public Methods
//     phpFolder($strPrefix,$strPostfix,$strRootDir,$strTypeOfDir)            Constructor
//     getSortLink($_GET)
//     getList($_GET)
//     getTypeOfDir
//
//
// Public properties
//     startdir
//     currentdir
//     sortmethod
//     sort_byname
//     sort_bysize
//     sort_bydate
//     sort_bydir
//     par_currentdir
//     par_sortmethod
//     linkprefix
//     linkpostfix
//     files
//     file_content

class phpFolder
{
 var 
$startdir;
 var 
$currentdir;
 var 
$sortmethod;

 var 
$sort_byname "name";
 var 
$sort_bysize "size";
 var 
$sort_bydate "date";
 var 
$sort_bydir "dir";

 var 
$par_currentdir "";
 var 
$par_sortmethod "";

 var 
$linkprefix;
 var 
$linkpostfix;

 var 
$files = array();
 var 
$file_content "";

 var 
$_icon_folder "/images/FolderClosed.gif";
 var 
$_icon_root "/images/FolderOpened.gif";
 var 
$_icon_file "/images/file.gif";

 var 
$_typeofdir;
 var 
$_localtransferpath;
 
//
 // Constructor
 
function phpFolder($strPrefix,$strPostfix,$strRootDir,$strTypeOfDir,$strlocaltransferpath)
  {
   
$this->linkprefix $strPrefix;
   
$this->linkpostfix $strPostfix;
   
$this->startdir $strRootDir;

   if (
strlen(trim($strlocaltransferpath)) > 0)
     
$this->_localtransferpath trim($strlocaltransferpath);
   else
     
$this->_localtransferpath "";

   if (
strlen(trim($strTypeOfDir)) > 0)
     
$this->_typeofdir trim($strTypeOfDir);
   else
     
$this->_typeofdir "device";


  if (
$this->_typeofdir == "device")
   {
    
$this->par_currentdir "currentdir";
    
$this->par_sortmethod "sortmethod";
   }
  else
   {
    
$this->par_currentdir "transfercurrentdir";
    
$this->par_sortmethod "transfersortmethod";
   }
 }
 
//
 // Get the link for the top-caption that holds all the sort-methods
 
function getSortLink($strGet)
  {
   
$this->_readGetArray($strGet);

   if (
$this->sortmethod == $this->sort_byname)
     
$strResult .= $this->_buildLink("sortby-bold",$this->currentdir,$this->sort_byname,"by name").whitespace(15,1);
   else
     
$strResult .= $this->_buildLink("sortby",$this->currentdir,$this->sort_byname,"by name").whitespace(15,1);

   if (
$this->sortmethod == $this->sort_bydir)
     
$strResult .= $this->_buildLink("sortby-bold",$this->currentdir,$this->sort_bydir,"by directory/file").whitespace(15,1);
   else
     
$strResult .= $this->_buildLink("sortby",$this->currentdir,$this->sort_bydir,"by directory/file").whitespace(15,1);

   if (empty(
$strResult))
     
$strResult "&nbsp;";
   return 
$strResult;
  }

 function 
getTypeOfDir()
  {
   if (
$this->_typeofdir == "device")
     return 
"device";
   else
    {
     if (
strlen(trim($this->_localtransferpath)) > 0)
       return 
"<a class='dir-typeofdir' href='file:".$this->_localtransferpath."' target='_blank'>transfer ".
                
"<img src='/images/smalldetails.gif' hspace='5' border='0' alt='' align='middle' ></a>";
     else
       return 
"transfer";
    }
  }

 
//
 // get the directory content and return a string
 
function getList($strGet)
  {
   
$strResultList "";
   
$this->_readGetArray($strGet);
   
$this->_getFiles();
   
$this->_sortFiles();

   
$strResultList .= "<table border='0' cellpadding='0'>";

   if (!(
$this->currentdir == $this->startdir))
    
$strResultList .= "<tr>".
                       
"<td colspan='4' class='dir-content2'>".
                         
$this->_buildLink('dir',$this->_getParentDir($this->currentdir),$this->sortmethod,"..",$this->_icon_root).
                       
"</td>".
                      
"</tr>";
   else
    
$strResultList .= "<tr>".
                       
"<td colspan='4' class='dir-content2'>".
                         
"&nbsp;".
                       
"</td>".
                      
"</tr>";
   if (
sizeof($this->files) > 0)
    {
       foreach (
$this->files as $myFile)
        {
         if (
$myFile->type == "dir")
          {
           
$strIcon =  $this->_icon_folder;
           
$strSize =  "&nbsp;";
           
$strLink $this->_buildLink('dir',$myFile->link,$this->sortmethod,$myFile->name,$strIcon);
          }
         elseif (
$myfile->type == "file")
          {
           
$strIcon $this->_icon_file;
           
$strSize =  number_format(($myFile->size 1024),0,',','.')." kB";
           
$strLink $this->_buildLink('dir',$myFile->link,$this->sortmethod,$myFile->name,$strIcon);
          }
         else
          {
           
$strIcon $this->_icon_file;
           
$strSize =  number_format(($myFile->size 1024),0,',','.')." kB";
           
$strLink $this->_buildLink('dir',$myFile->link,$this->sortmethod,$myFile->name,$strIcon);
          }



         
$strResultList .= "<tr>".
                            
"<td class='dir-content2'>".
                              
"&nbsp;".
                              
"</td>".
                            
"<td class='dir-content2'>".$strLink."</td>".
                            
"<td class='dir-content3'>".$strSize."</td>".
                            
"<td class='dir-content3'>".date("d/m/Y  G:H",$myFile->date)."</td>".
                          
"</tr>";
        }
    }
   else
    {
     
$strResultList .= "<tr>".
                         
"<td colspan='4' class='dir-content2'>".
                           
$this->file_content.
                         
"</td>".
                       
"</tr>";
    }
   
$strResultList .= "</table>";

   return 
$strResultList;
  }


 
// PRIVATE
 // get the parent-directory
 
function _getParentDir($folder)
  {
   
$temp explode("/",$folder);

   if (
sizeof($temp) > 0)
    {
     
// first element will be empty as it starts with "/"
     
if (empty($temp[0]))
      
array_shift($temp);
     
array_pop($temp);
     
$folder $temp[0];
     for (
$i=1;$i <= sizeof($temp) -1;$i++)
      {
       if (!empty(
$temp[$i]))
         
$folder .= "/".$temp[$i];
      }
     if (
strpos($folder,"/") != 1)
      
$folder "/".$folder;
     if (
$folder == "/")
      
$folder "";
    }
   return 
$folder;
  }


 
// PRIVATE
 // get all files in the files-array
 
function _getFiles()
  {
   if (
is_dir($this->currentdir))
    {
       
$filehandle opendir($this->currentdir);
       if (
$filehandle)
        {
         while (
false !== ($filename readdir($filehandle)) )
          {
           if (
$filename != "." && $filename != "..")
            {
             if (
is_dir($this->currentdir."/".$filename))
              {
               if (
substr($this->currentdir,strlen($this->currentdir) - 1) == "/")
                 
$link $this->currentdir.$filename;
               else
                 
$link $this->currentdir."/".$filename;
               
$myphpFile_Folder = new phpFile_Folder($filename,"dir",$link,filesize($link),filemtime($link));
               
$this->files[] = $myphpFile_Folder;
               unset(
$myphpFile_Folder);
              }
             else
              {
               
$link $this->currentdir."/".$filename;

               
$myphpFile_Folder = new phpFile_Folder($filename,"file",$link,filesize($link),filemtime($link));
               
$this->files[] = $myphpFile_Folder;
               unset(
$myphpFile_Folder);
              }
           }
         }
         
closedir($filehandle);
        }
       return 
true;
    }
   else
       
// this is not a directory but a file
    
{
     
$this->file_content nl2br(file_get_contents($this->currentdir));
     return 
false;
    }
  }

 
// PRIVATE
 // read the query-string
 
function _readGetArray($strGet)
  {
   if (isset(
$strGet[$this->par_currentdir]) && !(empty($strGet[$this->par_currentdir])))
    {
     
$this->currentdir $strGet[$this->par_currentdir];
    }
   else
     
$this->currentdir $this->startdir;

   if (isset(
$strGet[$this->par_sortmethod]) && !(empty($strGet[$this->par_sortmethod])))
    {
     
$this->sortmethod $strGet[$this->par_sortmethod];
    }
   else
     
$this->sortmethod $this->sort_bydir;

  }


 
// PRIVATE
 // build the href-link for a file or directory
 
function _buildLink($strCSSClass,$strCurrentDir,$strSortType,$strCaption,$strImage "")
  {
   if (empty(
$strImage))
     
$strLinkCaption $strCaption;
   else
     
$strLinkCaption "<img src='".$strImage."' alt='' border='0' hspace='5' align='top' >".
                       
$strCaption;

   return 
"<a class='".$strCSSClass."' href='".$this->linkprefix."?".
              
$this->par_currentdir."=".$strCurrentDir."&".
              
$this->par_sortmethod."=".$strSortType."&".
              
$this->linkpostfix."'>".
          
$strLinkCaption.
          
"</a>";
  }

 
// PRIVATE
 // sort all the files
 
function _sortFiles()
  {
   
// If there are no files we don't need to sort anything
   
if (sizeof($this->files) > 0)
    {
     if (
$this->sortmethod == $this->sort_bydir)
      {
       
$file_arr = array();
       
$dir_arr = array();
       foreach (
$this->files as $file)
        {
         
// seperate dir from files
         
if ($file->type == "dir")
           
$dir_arr[sizeof($dir_arr) + 1] = $file;
         else
           
$file_arr[sizeof($file_arr) + 1] = $file;
        }
       
$this->_bubblesort($dir_arr,"name");
       
$this->_bubblesort($file_arr,"name");

       
$this->files array_merge($dir_arr,$file_arr);

      }
    }
  }


 
// PRIVATE
 // Bubblesort
 
function _bubblesort(&$array_obj,$property)
    {
    
#  passed an array of objects and the name of the variable to sort
    #  array is by reference
    # We don't use the built-in sort of php because sorting objects doesn't seem to work
     
for($i sizeof($array_obj); $i >= 1$i--)
      {
       for(
$j 1$j $i$j++)
        {
         if(
strtoupper($array_obj[$j-1]->$property) > strtoupper($array_obj[$j]->$property))
          {
           
$t $array_obj[$j-1];
           
$array_obj[$j-1] = $array_obj[$j];
           
$array_obj[$j] = $t;
          }
        }
      }
    }
}






//
// phpSysInfo - A PHP System Information Script
// http://phpsysinfo.sourceforge.net/
//
// The class 'sysinfo' is a stripped-down version of the class
// used in phpSysInfo
//

class sysinfo
{
    function 
filesystems ()
    {
        
$df execute_program('df''-kP');
        
$mounts split("\n"$df);
        
$fstype = array();

        if (
$fd fopen('/proc/mounts''r')) {
            while (
$buf fgets($fd4096)) {
                list(
$dev$mpoint$type) = preg_split('/\s+/'trim($buf), 4);
                
$fstype[$mpoint] = $type;
                
$fsdev[$dev] = $type;
            }
            
fclose($fd);
        }

        for (
$i 1$i sizeof($mounts); $i++) {
            
$ar_buf preg_split('/\s+/'$mounts[$i], 6);

            
$results[$i 1] = array();

            
$results[$i 1]['disk'] = $ar_buf[0];
            
$results[$i 1]['size'] = $ar_buf[1];
            
$results[$i 1]['used'] = $ar_buf[2];
            
$results[$i 1]['free'] = $ar_buf[3];
            
$results[$i 1]['percent'] = round(($results[$i 1]['used'] * 100) / $results[$i 1]['size']) . '%';
            
$results[$i 1]['mount'] = $ar_buf[5];
            (
$fstype[$ar_buf[5]]) ? $results[$i 1]['fstype'] = $fstype[$ar_buf[5]] : $results[$i 1]['fstype'] = $fsdev[$ar_buf[0]];
        }
        return 
$results;
    }
}       
// End of class



?>






libheader.php
<?
//
// phpMount
//
// This program 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 2
// 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, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//
//
session_start();


$phpMountVersion "0.0.1 - alpha - 2";



/***************************************************************************************************/
// Function: strip_query_action
// Paramaters: $strBaseURL
// Purpose: strip of possible 'action' from url
// Date: 12/5/2003 - Koen Van Impe
function strip_query_action($strBaseURL)
 {
  
$p strpos($strBaseURL,"&action=");
  if (!(
$p === false))               // we have an action
   
{
    
$leftURL substr($strBaseURL,0,$p);
    
$p2 strpos(substr($strBaseURL,$p 1),"&");
    if (!(
$p2 === false))
      
$rightURL substr(substr($strBaseURL,$p 1),$p2 1);
    else
      
$rightURL "";
    
$strBaseURL $leftURL.$rightURL;
   }
  return 
$strBaseURL;
 }




/***************************************************************************************************/
// Function: print_panel_device
// Paramaters: $strBaseURL
// Purpose: Print the buttons on top of each detail-page
// Date: 11/5/2003 - Koen Van Impe
function print_panel_device($strBaseURL)
 {
  
$strBaseURL strip_query_action($strBaseURL);
  echo 
"<table border='0' cellpadding='0' cellspacing='0'>".
        
"<tr><td>".whitespace(20,1)."</td><td class='dir-action'>".
         
"<table border='0' cellpadding='3' cellspacing='0' >".
          
"<tr>".
           
"<td class='dir-action'>".
             
"<a href='".$strBaseURL."' class='dir-action'>".
               
"<img src='/images/bigrefresh.gif' vspace='5' alt='' border='0'><br>refresh</a>".
           
"</td>".
           
"<td class='dir-action'>".
             
whitespace(40,1).
           
"</td>".
           
"<td class='dir-action'>".
             
"<a href='".$strBaseURL."&action=copy' class='dir-action'>".
               
"<img src='/images/bigcopy.gif' vspace='5' alt='' border='0'><br>copy <strong>from</strong> device<br>to transfer</a>".
           
"</td>".
           
"<td class='dir-action'>".
             
whitespace(40,1).
           
"</td>".
           
"<td class='dir-action'>".
             
"<a href='".$strBaseURL."&action=transfercopy' class='dir-action'>".
               
"<img src='/images/bigcopytransfer.gif' vspace='5' alt='' border='0'><br>copy <strong>to</strong> device<br>from transfer</a>".
           
"</td>".
           
"<td class='dir-action'>".
             
whitespace(40,1).
           
"</td>".
           
"<td class='dir-action'>".
             
"<a href='".$strBaseURL."&action=deleteall' class='dir-action'>".
               
"<img src='/images/bigdelete.gif' vspace='5' alt='' border='0'><br>delete all on <strong>device</strong></a>".
           
"</td>".
           
"<td class='dir-action'>".
             
whitespace(40,1).
           
"</td>".
           
"<td class='dir-action'>".
             
"<a href='".$strBaseURL."&action=transferdeleteall' class='dir-action'>".
               
"<img src='/images/bigdeletetransfer.gif' vspace='5' alt='' border='0'><br>delete all on <strong>transfer</strong></a>".
           
"</td>".

          
"</tr>".
         
"</table>".
        
"</td></tr>".
       
"</table>";
 }



/***************************************************************************************************/
// Function: print_title
// Paramaters: $strTitle
// Purpose: Print the title on each page
// Date: 8/5/2003 - Koen Van Impe
function print_title($strTitle)
{
 if (
strlen(trim($strTitle)) > 0)
  {
   echo 
"<h1 class='pagetitle'>".$strTitle."</h1>";
  }
}


/***************************************************************************************************/
// Function: print_panel_footer
// Paramaters: /
// Purpose: Print the footer-panel
// Date: 8/5/2003 - Koen Van Impe
function print_panel_footer($urlThisPage)
{
 
$urlThisPage strip_query_action($urlThisPage);
 echo 
"<br>";

 echo 
"<table border='0' cellpadding='0' cellspacing='0'>".
       
"<tr>".
        
"<td class='panel-footer'>".
          
"<a href='".$urlThisPage."' class='panel-footer'><img src='/images/reload.gif' border='0' align='middle' hspace='5'><br>refresh</a>".
        
"</td>".
       
"</tr>".
      
"</table>";
}



/***************************************************************************************************/
// Function: print_device_statuslist
// Paramaters: /
// Purpose: Print the last messages
// Date: 8/5/2003 - Koen Van Impe
function print_device_statuslist($strTekst)
{
 if (
strlen(trim($strTekst)) > 0)
     echo 
"<table border='0' cellpadding='0' cellspacing='0'><tr><td class='shellwindow'>".
          
$strTekst."</td></tr></table>";
}



/***************************************************************************************************/
// Function: print_device_list
// Paramaters: /
// Purpose: Print the status
// Date: 8/5/2003 - Koen Van Impe
function print_device_list($phpMountDevice,$urlThisPage,$intKey "ALL")
{
 
// We can only mount/unmount from the main-page
 
if (strtoupper(trim($urlThisPage)) == "/INDEX.PHP")
  
$blnActionCell true;
 else
  
$blnActionCell false;

 echo 
"<table border='0' cellpadding='0' cellspacing='10' width='100%'>".
        
"<tr><td class='device-container'>";

 echo 
"<table border='0' cellpadding='3' cellspacing='0' width='100%'>";

 echo 
"<tr>".
        
"<td class='device-header'>description</td>".
        
"<td class='device-header'>device</td>".
        
"<td class='device-header'>mountpoint</td>".
        
"<td class='device-header'>fs</td>".
        
"<td class='device-header'>status</td>".
        
"<td class='device-header-right'>action</td>".
      
"</tr>";
 
$blnRowCount true;

 if (
$intKey == "ALL")
  {
   foreach(
$phpMountDevice as $device)
    {
     if (
$blnRowCount)
      
$strExtraClass "";
     else
      
$strExtraClass "-alt";
     
$blnRowCount = !($blnRowCount);
     
print_device_list_details($device,$blnActionCell,$strExtraClass);
    }
  }
 else
  
print_device_list_details($phpMountDevice[$intKey],$blnActionCell);

 echo 
"</table>";

 echo   
"</td></tr>".
      
"</table>";
}



/***************************************************************************************************/
// Function:   print_device_list_details
// Paramaters: $device
//             $strExtraClass
// Purpose: print details for one device
// Date: 3/5/2003 - Koen Van Impe
function print_device_list_details($device,$blnActionCell,$strExtraClass "")
{
   echo 
"<tr>".
         
"<td class='device".$strExtraClass."-name'>".
           
"<a class='device-name' href='details.php?devid=".$device->id."'>".$device->name."</a></td>".
         
"<td class='device".$strExtraClass."-data1'>".$device->device."</td>".
         
"<td class='device".$strExtraClass."-data1'>".$device->mountpoint."</td>".
         
"<td class='device".$strExtraClass."-status'>".$device->filesystem."</td>";

   if (
$device->getStatus() == "mount")
    {
     
$strActie "<a href='index.php?action=umount&devid=".$device->id."'><img src='/images/close.gif' alt='unmount' border='0'></a>";
     
$strCopy "<a href='index.php?action=copy&devid=".$device->id."'>".
                    
"<img src='/images/copy.gif' alt='Copy All from device to transfer' border='0'></a>";
     
$strCopyTransfer "<a href='index.php?action=transfercopy&devid=".$device->id."'>".
                    
"<img src='/images/copytransfer.gif' alt='Copy All from transfer to device' border='0'></a>";

     
$strDetail "<a href='details.php?devid=".$device->id."'><img src='/images/details.gif' alt='details' border='0'></a>";
     
$strExtraInfo "<font class='info'>size</font> <strong>".number_format($device->size,0,',','.')." kB</strong>".
                     
whitespace(15,1).
                     
"<font class='info'>free space</font> <strong>".number_format($device->free,0,',','.')." kB</strong>".
                     
whitespace(15,1).
                     
return_bar($device->size,$device->free);
    }
   else
    {
     
$strActie "<a href='index.php?action=mount&devid=".$device->id."'><img src='/images/open.gif' alt='mount' border='0'></a>";
     
$strDetail "<img src='/images/pixel.gif' alt='' width='22' height='22' border='0'>";
     
$strCopy "<img src='/images/pixel.gif' alt='' width='22' height='22' border='0'>";
     
$strCopyTransfer "<img src='/images/pixel.gif' alt='' width='22' height='22' border='0'>";
     
$strExtraInfo "&nbsp;";
    }
   
$strPrint "<img src='/images/".$device->icon."' alt='' border='0'>";
   echo  
"<td class='device".$strExtraClass."-status'>".$strPrint."</td>";
   if (
$blnActionCell)
     echo 
"<td class='device".$strExtraClass."-actie'>".$strDetail.whitespace(20,1).$strCopy.whitespace(20,1).
                                               
$strCopyTransfer.whitespace(20,1).$strActie."</td>";
   else
     echo 
"<td class='device".$strExtraClass."-actie'><img src='/images/details.gif' alt='details' border='0'></td>";
   echo 
"</tr>";

   echo 
"<tr>".
          
"<td colspan='6' class='device".$strExtraClass."-extrainfo'>".$strExtraInfo."</td>".
        
"</tr>";
}




/***************************************************************************************************/
// Function:   find_program
// Copied from phpSysInfo
// Find a system program.  Do path checking
function find_program ($program)
{
    
$path = array('/bin''/sbin''/usr/bin''/usr/sbin''/usr/local/bin''/usr/local/sbin');
    while (
$this_path current($path)) {
        if (
is_executable("$this_path/$program")) {
        return 
"$this_path/$program";
    }
    
next($path);
    }
    return;
}




/***************************************************************************************************/
// Function:   execute_program
// Copied from phpSysInfo
// Execute a system program. return a trim()'d result.
// does very crude pipe checking.  you need ' | ' for it to work
// ie $program = execute_program('netstat', '-anp | grep LIST');
// NOT $program = execute_program('netstat', '-anp|grep LIST');
function execute_program ($program$args '')
{
    
$buffer '';
    
$program find_program($program);

    if (!
$program) { return; }

    
// see if we've gotten a |, if we have we need to do patch checking on the cmd
    
if ($args) {
        
$args_list split(' '$args);
        for (
$i 0$i count($args_list); $i++) {
            if (
$args_list[$i] == '|') {
                
$cmd $args_list[$i+1];
                
$new_cmd find_program($cmd);
                
$args ereg_replace("\| $cmd""| $new_cmd"$args);
            }
        }
    }

    
//print "program: $program $args<br>";

    // we've finally got a good cmd line.. execute it
    
if ($fp popen("$program $args"'r')) {
        while (!
feof($fp)) {
            
$buffer .= fgets($fp4096);
        }
        return 
trim($buffer);
    }
}



/***************************************************************************************************/
// Function:   return_bar
// Paramaters: $intMax = maximum value
//             $intFree = current free value
// Purpose: print a progress bar
// Date: 3/5/2003 - Koen Van Impe
function return_bar($intMax 1,$intFree 0)
{
 if (
$intMax 0)
  {
   if (
$intMax == 0)
    
$intMax 1;
   
$intInUse $intMax $intFree;
   
$intPerc round($intInUse $intMax,5);
   
$intLength round(($intPerc 100),0);
   if (
$intPerc .80)
    {
     
$barLeft "redbar_left.gif";
     
$barMiddle "redbar_middle.gif";
     
$barRight "redbar_right.gif";
    }
   else
    {
     
$barLeft "bar_left.gif";
     
$barMiddle "bar_middle.gif";
     
$barRight "bar_right.gif";
    }
   
$strResult "<table border='0' cellpadding='0' cellspacing='0'>".
                   
"<tr><td><img src='/images/".$barLeft."' alt='' border='0'>".
                           
"<img src='/images/".$barMiddle."' alt='' border='0' width='".$intLength."' height='16'>".
                           
"<img src='/images/".$barRight."' alt='' border='0'>".
                       
"</td><td>&nbsp;".round($intPerc 100,2)."% in use</td>".
                   
"</tr>".
                 
"</table>";
  }
 return 
$strResult;
}



/***************************************************************************************************/
// Function: whitespace
// Paramaters: $intWidth = width
//             $intHeigth = height
// Purpose: Print whitespace between text
// Date: 3/5/2003 - Koen Van Impe
function whitespace($intWidth 1$intHeigth 2)
{
  return 
"<img src='/images/pixel.gif' alt='' border='0' height='".$intHeigth."' width='".$intWidth."'>";
}





/***************************************************************************************************/
// Function: print_footer
// Paramaters: $strURL = current URL
//             $strScriptName = php-scriptname
//             $strMenuSection = menusection
// Purpose: print the footer
// Date: 3/5/2003 - Koen Van Impe
function print_footer($strURL,$strScriptName,$strMenuSection 'HOME')
{
 global 
$menu_bgcolor,$page_bgcolor,$menuleft_headercolor,$menuleft_bgcolor;
 @
clearstatcache();

 echo  
"<table border='0' cellspacing='0' cellpadding='0' width='100%'>";
 echo 
"<tr>".
        
"<td class='footerphpMount'>".
             
"(c) Copyright 2003 - <a href='http://solution.cudeso.be' class='footer' target='_blank'>cudeso.be</a>".
             
whitespace(35,1).
             
"phpMount is free software".
             
whitespace(35,1).
             
"<a href='http://www.gnu.org/licenses/gpl.html' class='footer' target='_blank'>GPL</a>".
        
"</td>".
      
"</tr>";
 echo 
"</table>";

 
print_comment_in_html("End",1);
 
print_comment_in_html("Web Created by cudeso.be",1);

 echo 
"</body>".
      
"</html>";
}





/***************************************************************************************************/
// Function: print_header
// Paramaters: $strURL = current URL
//             $strMenuSection = menusection
// Purpose: print header
// Date: 3/5/2003 - Koen Van Impe
function print_header($strURL,$strMenuSection 'HOME')
{
 global 
$main_bgcolor,$page_bgcolor,$content_bgcolor,$phpMountVersion;

 
print_comment_in_html("Main",1);

 echo 
"<body>\n".
      
"<table border='0' cellpadding='0' cellspacing='0' width='100%'>\n";

 
print_comment_in_html("Menubar",1);

 echo 
"<tr>".
        
"<td colspan='2' class='menubar' align='center' valign='top' width='100%'>\n".
         
"<a class='menubar' href='index.php'>..:: Home ::..</a>".
         
whitespace(35,1).
         
"<a class='menubar' href='settings.php'>..:: Settings ::..</a>".
         
whitespace(35,1).
         
"<a class='menubar' href='log.php'>..:: Log ::..</a>".
        
"</td>".
      
"</tr>".
      
"<tr>".
        
"<td class='pagecontent' align='left'>".return_cudesologo()."</td>".
        
"<td rowspan='2' class='projectTitle'  width='100%'><img src='/images/logo.gif'></td>".
      
"</tr>".
      
"<tr>".
        
"<td class='sysinfo-container'>".
          
"<table border='0' cellpadding='0' cellspacing='0' width='100%'>".
            
"<tr><td class='sysinfo-data' nowrap>".
              
"The current time is <strong>".date("H:i:s")."</strong><br>".
              
"You are connected to <strong>".$_SERVER["HTTP_HOST"]."</strong> running <strong>phpMount</strong> ".$phpMountVersion."<br>".
            
"</td></tr>".
          
"</table>".
        
"</td>".
      
"</tr>";

 
print_comment_in_html("Body Start");
}


/***************************************************************************************************/
// Function: return_cudesologo
// Paramaters: /
// Purpose: return cudeso-logo
// Date: 3/5/2003 - Koen Van Impe
function return_cudesologo()
{
 
?>

 <script language='JavaScript' type='text/javascript'>
 <!-- hide script from old browsers
   imglogo = new Image();
   imglogo_over = new Image();
   imglogo.src = '/images/logo2.png';
   imglogo_over.src = '/images/logo2_over.png';
 //-->
 </script>

 <?
  $strHomeURL 
"/index.php";
  
$strObjName "logo";
  
$strObjImageOver "imglogo_over";
  
$strObjImage "imglogo";
  
$strImage "/images/logo2.png";

 return 
"<a href='".$strHomeURL."' onmouseover='document.".$strObjName.".src=".$strObjImageOver.".src;'".
        
" onmouseout='document.".$strObjName.".src=".$strObjImage.".src;'>\n\n".
        
"<img src='".$strImage."' name='".$strObjName."' border='0' alt='".$strAlt."' hspace='15'></a>\n";
}





/***************************************************************************************************/
// Function: print_metadata
// Paramaters: $strTitle = title
//             strDescription = description
//             $strKeywords = keywords
//             $strLanguage = language
// Purpose: print meta data on each html-page
// Date: 3/5/2003 - Koen Van Impe
function print_metadata($strTitle,$strDescription,$strKeywords,$strLanguage)
{
//<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>

<!-- phpMount -->

<!-- http://solution.cudeso.be   ..::..  contact us for all your internet-services -->


<head>
<?
 
if (strlen($strLanguage) < 1)
     
$strLanguage 'nl';

 echo 
"<title>".$strTitle."</title>\n";
 echo 
"<META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=iso-8859-1'>\n".
      
"<META HTTP-EQUIV='Content-Script-Type' CONTENT='text/javascript'>\n".
      
"<META HTTP-EQUIV='reply-to' CONTENT='info@cudeso.be'>\n".

      
"<META NAME='distribution' CONTENT='GLOBAL'>\n".
      
"<META NAME='objecttype' CONTENT='document'>\n".
      
"<META NAME='rating' CONTENT='GENERAL'>\n".
      
"<META NAME='copyright' content='Copyright (c) 2003 by Cudeso'>\n".
      
"<META NAME='Author' content='http://www.cudeso.be'>\n".
      
"<META NAME='Classification' content='Internet Services'>\n\n".
      
"<META NAME='description' CONTENT='".$strDescription."'>\n".
      
"<META NAME='keywords' CONTENT='".$strKeywords."'>\n\n".
      
"<META NAME='revisit-after' CONTENT='3 days'>\n".
      
"<META NAME='language' CONTENT='".$strLanguage."'>\n".
      
"<META HTTP-EQUIV='content-style-type' CONTENT='text/css'>\n\n";

 echo 
"<LINK REL='StyleSheet' HREF='/phpmount.css' TYPE='text/css'>\n";
 echo 
"<LINK REL='icon' HREF='/favicon.ico' type='image/x-icon'>\n";
 echo 
"</head>\n\n\n";

 
print_comment_in_html("Real Start of this page",1);
}





/***************************************************************************************************/
// Function: print_comment_in_html
// Paramaters: $strCommentString = what string to print out
//             $intSupSeperator = print seperator, 1 = yes ; 0 = no
// Purpose: print seperator-comment in HTML
// Date: 3/5/2003 - Koen Van Impe
function print_comment_in_html($strCommentString,$intSupSeperator 0)
{
 echo 
"\n\n\n\n";
 if (
$intSupSeperator == 1)
    echo 
"\n<!-- *********************************************************************** -->\n\n";
 echo 
"<!-- ".$strCommentString." -->".
      
"\n\n\n\n";
}




/***************************************************************************************************/
// Function: print_contentstop
// Paramaters: /
// Purpose: stop the content
// Date: 3/5/2003 - Koen Van Impe
function print_contentstop()
{
 
print_comment_in_html("Stop of the real content",1);
 echo 
"</td></tr></table>\n\n".
      
"</td></tr></table>";
}




/***************************************************************************************************/
// Function: print_contentstart
// Paramaters: /
// Purpose: start the content
// Date: 3/5/2003 - Koen Van Impe
function print_contentstart($intHeight 500)
{
 
print_comment_in_html("Start of the real content",1);

 if (
$intHeight == 0)
   
$strHeight "";
 else
   
$strHeight " height='".$intHeight."'";
 echo 
"<tr><td class='pagecontent2' colspan='2' align='left' valign='top' width='97%' ".$strHeight.">";
}




?>
SourceForge.net Logo

(c) Copyright 2003 - cudeso.bephpMount is free softwareGPL