Changeset 402
- Timestamp:
- 03/07/07 23:51:40
(2 years ago)
- Author:
- kilburn
- Message:
- GUI:
- improved and extended the ftp abstraction util (vfs)
- revamped (now working) custom error page management using the new vfs
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r395 |
r402 |
|
| 408 | 408 | |
|---|
| 409 | 409 | // Check for $ftp_vhome existance |
|---|
| 410 | | // Create a virtual filesystem |
|---|
| 411 | | $vfs = new vfs($dmn_name); |
|---|
| 412 | | $vfs->setDb($sql); |
|---|
| 413 | | // Open it, so it can be used |
|---|
| 414 | | $res = $vfs->open(); |
|---|
| 415 | | if ( !$res ) { |
|---|
| 416 | | set_page_message( tr('Can not open directory !<br>Please contact your administrator !')); |
|---|
| 417 | | return; |
|---|
| 418 | | } |
|---|
| | 410 | // Create a virtual filesystem (it's important to use =&!) |
|---|
| | 411 | $vfs =& new vfs($dmn_name, $sql); |
|---|
| 419 | 412 | // Check for directory existance |
|---|
| 420 | 413 | $res = $vfs->exists($ftp_vhome); |
|---|
| 421 | | // We're done, just close |
|---|
| 422 | | $vfs->close(); |
|---|
| 423 | 414 | |
|---|
| 424 | 415 | if ( !$res ) { |
|---|
| 425 | | set_page_message(clean_input($_POST['other_dir'])." ".tr('do not exist')); |
|---|
| | 416 | set_page_message($ftp_vhome." ".tr('do not exist')); |
|---|
| 426 | 417 | return; |
|---|
| 427 | 418 | } |
|---|
| r323 |
r402 |
|
| 16 | 16 | // ------------------------------------------------------------------------------- |
|---|
| 17 | 17 | |
|---|
| | 18 | require '../include/vfs.php'; |
|---|
| | 19 | include '../include/vhcs-lib.php'; |
|---|
| 18 | 20 | |
|---|
| 19 | 21 | function gen_error_page_data(&$tpl, &$sql, $user_id, $eid) |
|---|
| 20 | 22 | { |
|---|
| 21 | | $query = <<<SQL_QUERY |
|---|
| 22 | | select |
|---|
| 23 | | error_401, |
|---|
| 24 | | error_403, |
|---|
| 25 | | error_404, |
|---|
| 26 | | error_500 |
|---|
| 27 | | from |
|---|
| 28 | | error_pages |
|---|
| 29 | | where |
|---|
| 30 | | user_id = ? |
|---|
| 31 | | SQL_QUERY; |
|---|
| 32 | | |
|---|
| 33 | | $rs = exec_query($sql, $query, array($user_id)); |
|---|
| | 23 | $domain = $_SESSION['user_logged']; |
|---|
| 34 | 24 | |
|---|
| 35 | | $error_401 = stripslashes($rs -> fields['error_401']); |
|---|
| 36 | | $error_403 = stripslashes($rs -> fields['error_403']); |
|---|
| 37 | | $error_404 = stripslashes($rs -> fields['error_404']); |
|---|
| 38 | | $error_500 = stripslashes($rs -> fields['error_500']); |
|---|
| 39 | | |
|---|
| 40 | | |
|---|
| 41 | | $error_standard_content = <<<RIC |
|---|
| 42 | | <html> |
|---|
| 43 | | <head> |
|---|
| 44 | | <title>VHCS ERROR {EID}</title> |
|---|
| 45 | | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
|---|
| 46 | | <link href="/vhcs2/themes/modern_blue/css/vhcs.css" rel="stylesheet" type="text/css"> |
|---|
| 47 | | </head> |
|---|
| 48 | | <body text="#000000"> |
|---|
| 49 | | <table width="100%" height="99%" border="00" cellpadding="0" cellspacing="0" bgcolor="#334163"> |
|---|
| 50 | | <tr> |
|---|
| 51 | | <td height="551"><table width="100%" border="00" cellpadding="0" cellspacing="0"> |
|---|
| 52 | | <tr bgcolor="#334163"> |
|---|
| 53 | | |
|---|
| 54 | | <td> </td> |
|---|
| 55 | | <td align="right"> </td> |
|---|
| 56 | | </tr> |
|---|
| 57 | | <tr> |
|---|
| 58 | | <td width="1" background="/vhcs2/themes/modern_blue/images/login/content_background.gif"><img src="/vhcs2/themes/modern_blue/images/login/content_background.gif" width="1" height="348"></td> |
|---|
| 59 | | <td height="348" align="center" background="/vhcs2/themes/modern_blue/images/login/content_background.gif"> |
|---|
| 60 | | <table width="600" height="200" border="00" cellpadding="1" cellspacing="3" bgcolor="#FF0000"> |
|---|
| 61 | | |
|---|
| 62 | | <tr> |
|---|
| 63 | | <td align="center" bgcolor="#FFFFFF"></strong> |
|---|
| 64 | | <h2><font color="#FF0000">Error {EID}!</font></h2> |
|---|
| 65 | | <br/> |
|---|
| 66 | | <b>{EID_STATUS}</b><br> |
|---|
| 67 | | |
|---|
| 68 | | </td> |
|---|
| 69 | | </tr> |
|---|
| 70 | | |
|---|
| 71 | | </table> |
|---|
| 72 | | </td> |
|---|
| 73 | | </tr> |
|---|
| 74 | | <tr> |
|---|
| 75 | | <td width="1" height="2" background="/vhcs2/themes/modern_blue/images/login/content_down.gif"><img src="/vhcs2/themes/modern_blue/images/login/content_down.gif" width="2" height="2"></td> |
|---|
| 76 | | <td height="2" background="/vhcs2/themes/modern_blue/images/login/content_down.gif"><img src="/vhcs2/themes/modern_blue/images/login/content_down.gif" width="2" height="2"></td> |
|---|
| 77 | | </tr> |
|---|
| 78 | | <tr> |
|---|
| 79 | | <td width="1" bgcolor="#334163"> </td> |
|---|
| 80 | | |
|---|
| 81 | | <td bgcolor="#334163"><a href="http://www.vhcs.net" target="_blank"><img src="/vhcs2/themes/modern_blue/images/login/vhcs_logo.gif" alt="VHCS - Virtual Hosting Control System - Control Panel" width="68" height="60" border="0"></a></td> |
|---|
| 82 | | </tr> |
|---|
| 83 | | </table></td> |
|---|
| 84 | | </tr> |
|---|
| 85 | | </table> |
|---|
| 86 | | </body> |
|---|
| 87 | | </html> |
|---|
| 88 | | |
|---|
| 89 | | RIC; |
|---|
| 90 | | |
|---|
| 91 | | |
|---|
| 92 | | |
|---|
| 93 | | if ($eid==401 && $error_401 != ''){ |
|---|
| 94 | | $tpl -> assign( |
|---|
| 95 | | array( |
|---|
| 96 | | 'ERROR' => $error_401, |
|---|
| 97 | | |
|---|
| 98 | | ) |
|---|
| 99 | | ); |
|---|
| | 25 | // Check if we already have an error page |
|---|
| | 26 | $vfs =& new vfs( $domain, $sql); |
|---|
| | 27 | $error = $vfs->get('/errors/' . $eid . '/index.php'); |
|---|
| | 28 | if (false !== $error) { |
|---|
| | 29 | // We already have an error page, return it |
|---|
| | 30 | $tpl->assign( array('ERROR'=>$error) ); |
|---|
| | 31 | return; |
|---|
| 100 | 32 | } |
|---|
| 101 | | elseif ($eid==403 && $error_403 != ''){ |
|---|
| 102 | | $tpl -> assign( |
|---|
| 103 | | array( |
|---|
| 104 | | 'ERROR' => $error_403, |
|---|
| 105 | | |
|---|
| 106 | | ) |
|---|
| 107 | | ); |
|---|
| 108 | | } |
|---|
| 109 | | elseif ($eid==404 && $error_404 != ''){ |
|---|
| 110 | | $tpl -> assign( |
|---|
| 111 | | array( |
|---|
| 112 | | 'ERROR' => $error_404, |
|---|
| 113 | | |
|---|
| 114 | | ) |
|---|
| 115 | | ); |
|---|
| 116 | | } |
|---|
| 117 | | elseif ($eid==500 && $error_500 != ''){ |
|---|
| 118 | | $tpl -> assign( |
|---|
| 119 | | array( |
|---|
| 120 | | 'ERROR' => $error_500, |
|---|
| 121 | | |
|---|
| 122 | | ) |
|---|
| 123 | | ); |
|---|
| 124 | | } |
|---|
| 125 | | |
|---|
| 126 | | else { |
|---|
| 127 | | switch ($eid){ |
|---|
| 128 | | case 401: |
|---|
| 129 | | $eid_status= "Unauthorized !"; |
|---|
| 130 | | break; |
|---|
| 131 | | case 403: |
|---|
| 132 | | $eid_status = "Forbidden !"; |
|---|
| 133 | | break; |
|---|
| 134 | | case 404: |
|---|
| 135 | | $eid_status = "File not found !"; |
|---|
| 136 | | break; |
|---|
| 137 | | case 500: |
|---|
| 138 | | $eid_status = "Internal server error !"; |
|---|
| 139 | | break; |
|---|
| 140 | | } |
|---|
| 141 | | |
|---|
| 142 | | $tpl -> assign( |
|---|
| 143 | | array( |
|---|
| 144 | | 'ERROR' => $error_standard_content, |
|---|
| 145 | | 'EID_STATUS' => $eid_status |
|---|
| 146 | | |
|---|
| 147 | | ) |
|---|
| 148 | | ); |
|---|
| 149 | | } |
|---|
| 150 | | |
|---|
| 151 | | |
|---|
| | 33 | |
|---|
| | 34 | // No error info :'( |
|---|
| | 35 | $tpl->assign( array('ERROR'=> '') ); |
|---|
| 152 | 36 | } |
|---|
| 153 | 37 | |
|---|
| … | … | |
| 205 | 89 | } |
|---|
| 206 | 90 | else{ |
|---|
| 207 | | $eid = $_GET['eid']; |
|---|
| | 91 | $eid = intval($_GET['eid']); |
|---|
| 208 | 92 | } |
|---|
| 209 | 93 | |
|---|
| r323 |
r402 |
|
| 16 | 16 | // ------------------------------------------------------------------------------- |
|---|
| 17 | 17 | |
|---|
| | 18 | require '../include/vfs.php'; |
|---|
| 18 | 19 | |
|---|
| 19 | 20 | function write_error_page(&$sql, &$user_id, &$eid) |
|---|
| 20 | 21 | { |
|---|
| 21 | | $error = $_POST['error']; |
|---|
| 22 | | $eid = "error_".$_POST['eid']; |
|---|
| 23 | | |
|---|
| 24 | | // let's check if exist error table for this looser |
|---|
| 25 | | |
|---|
| 26 | | $query = <<<SQL_QUERY |
|---|
| 27 | | select |
|---|
| 28 | | user_id |
|---|
| 29 | | from |
|---|
| 30 | | error_pages |
|---|
| 31 | | where |
|---|
| 32 | | user_id = ? |
|---|
| 33 | | SQL_QUERY; |
|---|
| 34 | | |
|---|
| 35 | | $rs = exec_query($sql, $query, array($user_id)); |
|---|
| 36 | | |
|---|
| 37 | | if ($rs -> RecordCount() == 0) { |
|---|
| 38 | | /// oooo noooo we dont have error table ... i can't believe it ... |
|---|
| 39 | | |
|---|
| 40 | | $query = <<<SQL_QUERY |
|---|
| 41 | | insert into error_pages |
|---|
| 42 | | (user_id, error_401, error_403, error_404, error_500) |
|---|
| 43 | | values |
|---|
| 44 | | (?, '', '', '', '') |
|---|
| 45 | | SQL_QUERY; |
|---|
| 46 | | |
|---|
| 47 | | $rs = exec_query($sql, $query, array($user_id)); |
|---|
| 48 | | |
|---|
| 49 | | } |
|---|
| 50 | | |
|---|
| 51 | | check_for_lock_file(); |
|---|
| 52 | | |
|---|
| 53 | | $query = <<<SQL_QUERY |
|---|
| 54 | | update |
|---|
| 55 | | error_pages |
|---|
| 56 | | set |
|---|
| 57 | | $eid = ? |
|---|
| 58 | | where |
|---|
| 59 | | user_id = ? |
|---|
| 60 | | SQL_QUERY; |
|---|
| 61 | | |
|---|
| 62 | | $rs = exec_query($sql, $query, array($error, $user_id)); |
|---|
| 63 | | |
|---|
| 64 | | // now save the file |
|---|
| 65 | | // error num (dir) = $eid |
|---|
| 66 | | // error text = $error |
|---|
| 67 | | list($temp_dmn_id, |
|---|
| 68 | | $temp_dmn_name, |
|---|
| 69 | | $temp_dmn_gid, |
|---|
| 70 | | $temp_dmn_uid, |
|---|
| 71 | | $temp_dmn_created_id, |
|---|
| 72 | | $temp_dmn_created, |
|---|
| 73 | | $temp_dmn_last_modified, |
|---|
| 74 | | $temp_dmn_mailacc_limit, |
|---|
| 75 | | $temp_dmn_ftpacc_limit, |
|---|
| 76 | | $temp_dmn_traff_limit, |
|---|
| 77 | | $temp_dmn_sqld_limit, |
|---|
| 78 | | $temp_dmn_sqlu_limit, |
|---|
| 79 | | $temp_dmn_status, |
|---|
| 80 | | $temp_dmn_als_limit, |
|---|
| 81 | | $temp_dmn_subd_limit, |
|---|
| 82 | | $temp_dmn_ip_id, |
|---|
| 83 | | $temp_dmn_disk_limit, |
|---|
| 84 | | $temp_dmn_disk_usage, |
|---|
| 85 | | $temp_dmn_php, |
|---|
| 86 | | $temp_dmn_cgi) = get_domain_default_props($sql, $_SESSION['user_id']); |
|---|
| 87 | | |
|---|
| 88 | | switch($eid) { |
|---|
| 89 | | case 'error_401': |
|---|
| 90 | | $e_dir = '401'; |
|---|
| 91 | | break; |
|---|
| 92 | | case 'error_403': |
|---|
| 93 | | $e_dir = '403'; |
|---|
| 94 | | break; |
|---|
| 95 | | case 'error_404': |
|---|
| 96 | | $e_dir = '404'; |
|---|
| 97 | | break; |
|---|
| 98 | | case 'error_500': |
|---|
| 99 | | $e_dir = '500'; |
|---|
| 100 | | break; |
|---|
| 101 | | } |
|---|
| 102 | | |
|---|
| 103 | | global $cfg; |
|---|
| 104 | | @$file = fopen($cfg['FTP_HOMEDIR'].'/'.$temp_dmn_name.'/errors/'.$e_dir.'/index.php','w'); |
|---|
| 105 | | if (!$file) { |
|---|
| 106 | | /* cannot open file for writing */ |
|---|
| 107 | | $error_saving = 1; |
|---|
| 108 | | session_register("error_saving"); |
|---|
| 109 | | } else { |
|---|
| 110 | | $content = stripslashes($error); |
|---|
| 111 | | fputs($file,$content); |
|---|
| 112 | | $saved = 1; |
|---|
| 113 | | session_register("saved"); |
|---|
| 114 | | } |
|---|
| | 22 | $error = $_POST['error']; |
|---|
| | 23 | $file = '/errors/' . $eid . '/index.php'; |
|---|
| | 24 | $vfs =& new vfs($_SESSION['user_logged'], $sql); |
|---|
| | 25 | return $vfs->put($file, $error); |
|---|
| 115 | 26 | } |
|---|
| 116 | 27 | |
|---|
| 117 | 28 | |
|---|
| 118 | | function update_error_page(&$sql, $user_id) |
|---|
| 119 | | { |
|---|
| 120 | | if (isset($_POST['uaction']) && $_POST['uaction'] === 'updt_error') { |
|---|
| 121 | | if ($_POST['eid']==401 or $_POST['eid']==403 or $_POST['eid']==404 or $_POST['eid']==500) { |
|---|
| 122 | | write_error_page($sql, $_SESSION['user_id'], $_POST['eid']); |
|---|
| 123 | | set_page_message(tr('Custom error page was updated!')); |
|---|
| 124 | | } else { |
|---|
| 125 | | set_page_message(tr('System error - custom error page was NOT updated!')); |
|---|
| 126 | | } |
|---|
| 127 | | } |
|---|
| | 29 | function update_error_page(&$sql, $user_id) { |
|---|
| | 30 | if (isset($_POST['uaction']) && $_POST['uaction'] === 'updt_error') { |
|---|
| | 31 | $eid = intval($_POST['eid']); |
|---|
| | 32 | if ( in_array($eid, array(401,402,403,404,500) ) |
|---|
| | 33 | && write_error_page($sql, $_SESSION['user_id'], $eid) ) { |
|---|
| | 34 | set_page_message(tr('Custom error page was updated!')); |
|---|
| | 35 | } else { |
|---|
| | 36 | set_page_message(tr('System error - custom error page was NOT updated!')); |
|---|
| | 37 | } |
|---|
| | 38 | } |
|---|
| 128 | 39 | } |
|---|
| 129 | 40 | |
|---|
| r395 |
r402 |
|
| 45 | 45 | |
|---|
| 46 | 46 | // Create the virtual file system and open it so it can be used |
|---|
| 47 | | $vfs = new vfs($domain); |
|---|
| 48 | | $vfs->setDb($sql); |
|---|
| 49 | | $vfs->open(); |
|---|
| | 47 | $vfs =& new vfs($domain,$sql); |
|---|
| 50 | 48 | |
|---|
| 51 | 49 | // Get the directory listing |
|---|
| … | … | |
| 100 | 98 | $tpl->parse('DIR_ITEM' , '.dir_item'); |
|---|
| 101 | 99 | } |
|---|
| 102 | | |
|---|
| 103 | | // We're done, close the virtual file system |
|---|
| 104 | | $vfs->close(); |
|---|
| 105 | 100 | } |
|---|
| 106 | 101 | // functions end |
|---|
| r396 |
r402 |
|
| 78 | 78 | $domain = $_SESSION['user_logged']; |
|---|
| 79 | 79 | // We need to use the virtual file system |
|---|
| 80 | | $vfs = new vfs($domain); |
|---|
| 81 | | $vfs->setDb($sql); |
|---|
| 82 | | $res = $vfs->open(); |
|---|
| 83 | | if (!$res) { |
|---|
| 84 | | set_page_message(tr("Couldn't retrieve directory listing")); |
|---|
| 85 | | } |
|---|
| | 80 | $vfs =& new vfs($domain, $sql); |
|---|
| 86 | 81 | $res = $vfs->exists($path); |
|---|
| 87 | | $vfs->close(); |
|---|
| 88 | 82 | if (!$res) { |
|---|
| 89 | 83 | set_page_message($path.tr(" doesn't exist")); |
|---|
| r395 |
r402 |
|
| 27 | 27 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|---|
| 28 | 28 | */ |
|---|
| 29 | | define('VFS_TYPE_DIR', 'd'); |
|---|
| 30 | | define('VFS_TYPE_LINK','l'); |
|---|
| 31 | | define('VFS_TYPE_FILE','-'); |
|---|
| | 29 | |
|---|
| | 30 | /* |
|---|
| | 31 | * This should be class constants, but we're php4 compatible |
|---|
| | 32 | */ |
|---|
| | 33 | |
|---|
| | 34 | /* |
|---|
| | 35 | * File types definition |
|---|
| | 36 | */ |
|---|
| | 37 | define('VFS_TYPE_DIR', 'd'); |
|---|
| | 38 | define('VFS_TYPE_LINK', 'l'); |
|---|
| | 39 | define('VFS_TYPE_FILE', '-'); |
|---|
| | 40 | |
|---|
| | 41 | /* |
|---|
| | 42 | * Temporary directory |
|---|
| | 43 | */ |
|---|
| | 44 | define('VFS_TMP_DIR', '/var/www/vhcs2/gui/phptmp'); |
|---|
| | 45 | |
|---|
| | 46 | /* |
|---|
| | 47 | * Possible VFS Transfer modes |
|---|
| | 48 | */ |
|---|
| | 49 | define('VFS_ASCII', FTP_ASCII); |
|---|
| | 50 | define('VFS_BINARY', FTP_BINARY); |
|---|
| 32 | 51 | |
|---|
| 33 | 52 | /** |
|---|
| … | … | |
| 78 | 97 | * |
|---|
| 79 | 98 | * Creates a new Virtual File System object for the |
|---|
| 80 | | * specified domain |
|---|
| | 99 | * specified domain. |
|---|
| 81 | 100 | * |
|---|
| 82 | 101 | * Warning! $domain parameter is not sanitized, so this is |
|---|
| 83 | | * left as work for the caller |
|---|
| 84 | | * |
|---|
| 85 | | * @param string $domain |
|---|
| | 102 | * left as work for the caller. |
|---|
| | 103 | * |
|---|
| | 104 | * @param string $domain Domain name of the new VFS. |
|---|
| | 105 | * @param resource $db Adodb database resource. |
|---|
| 86 | 106 | * @return vfs |
|---|
| 87 | 107 | */ |
|---|
| 88 | | function vfs($domain) { |
|---|
| 89 | | $this->_domain = $domain; |
|---|
| | 108 | function vfs($domain, &$db) { |
|---|
| | 109 | // Sort of php4 destructor |
|---|
| | 110 | register_shutdown_function(array(&$this, "__destruct")); |
|---|
| | 111 | return $this->__construct($domain, $db); |
|---|
| 90 | 112 | } |
|---|
| 91 | 113 | |
|---|
| … | … | |
| 93 | 115 | * PHP5 constructor |
|---|
| 94 | 116 | * |
|---|
| 95 | | * @param string $domain |
|---|
| 96 | | */ |
|---|
| 97 | | function __construct($domain) { |
|---|
| 98 | | $this->vfs($domain); |
|---|
| | 117 | * @param string $domain Domain name of the new VFS. |
|---|
| | 118 | * @param resource $db Adodb database resource. |
|---|
| | 119 | * @return vfs |
|---|
| | 120 | */ |
|---|
| | 121 | function __construct($domain, &$db) { |
|---|
| | 122 | $this->_domain = $domain; |
|---|
| | 123 | $this->_db =& $db; |
|---|
| | 124 | } |
|---|
| | 125 | |
|---|
| | 126 | /** |
|---|
| | 127 | * Destructor, ensure that we logout and remove the |
|---|
| | 128 | * temporary user |
|---|
| | 129 | */ |
|---|
| | 130 | function __destruct() { |
|---|
| | 131 | $this->close(); |
|---|
| 99 | 132 | } |
|---|
| 100 | 133 | |
|---|
| … | … | |
| 103 | 136 | * |
|---|
| 104 | 137 | * The system uses a "global" $sql variable to store the DB |
|---|
| 105 | | * handler, but we're a "black box" ;) |
|---|
| 106 | | * |
|---|
| 107 | | * @param resource $db |
|---|
| | 138 | * handler, but we're a "black box" ;). |
|---|
| | 139 | * |
|---|
| | 140 | * @param resource $db Adodb database resource. |
|---|
| 108 | 141 | */ |
|---|
| 109 | 142 | function setDb(&$db) { |
|---|
| … | … | |
| 114 | 147 | * Create a temporary FTP user |
|---|
| 115 | 148 | * |
|---|
| 116 | | * @return boolean Returns TRUE on succes or FALSE on failure |
|---|
| | 149 | * @return boolean Returns TRUE on succes or FALSE on failure. |
|---|
| 117 | 150 | */ |
|---|
| 118 | 151 | function _createTmpUser() { |
|---|
| | 152 | |
|---|
| 119 | 153 | // Get domain data |
|---|
| 120 | | $query = <<<SQL_QUERY |
|---|
| 121 | | select domain_uid AS uid,domain_gid AS gid |
|---|
| 122 | | from domain |
|---|
| 123 | | where domain_name = ? |
|---|
| 124 | | SQL_QUERY; |
|---|
| | 154 | $query = 'select domain_uid, domain_gid |
|---|
| | 155 | from domain |
|---|
| | 156 | where domain_name = ?'; |
|---|
| 125 | 157 | $rs = exec_query($this->_db, $query, array($this->_domain)); |
|---|
| 126 | 158 | if ( !$rs ) { |
|---|
| … | … | |
| 141 | 173 | SQL_QUERY; |
|---|
| 142 | 174 | $rs = exec_query($this->_db, $query, array( |
|---|
| 143 | | $user, $passwd, $rs->fields['uid'], $rs->fields['gid'], |
|---|
| | 175 | $user, $passwd, $rs->fields['domain_uid'], $rs->fields['domain_gid'], |
|---|
| 144 | 176 | '/bin/bash', '/var/www/virtual/' . $this->_domain |
|---|
| 145 | 177 | )); |
|---|
| … | … | |
| 156 | 188 | * Removes the temporary FTP user |
|---|
| 157 | 189 | * |
|---|
| 158 | | * @return TRUE on succes or FALSE on failure |
|---|
| | 190 | * @return Returns TRUE on succes or FALSE on failure. |
|---|
| 159 | 191 | */ |
|---|
| 160 | 192 | function _removeTmpUser() { |
|---|
| … | … | |
| 171 | 203 | * Open the virtual file system |
|---|
| 172 | 204 | * |
|---|
| 173 | | * @return boolean TRUE on succes or FALSE on failure |
|---|
| | 205 | * @return boolean Returns TRUE on succes or FALSE on failure. |
|---|
| 174 | 206 | */ |
|---|
| 175 | 207 | function open() { |
|---|
| | 208 | // Check if we're already open |
|---|
| | 209 | if ( $this->_handle ) { |
|---|
| | 210 | return true; |
|---|
| | 211 | } |
|---|
| | 212 | |
|---|
| 176 | 213 | // Check if we have a valid vhcs database |
|---|
| 177 | 214 | if ( !$this->_db ) { |
|---|
| 178 | 215 | return false; |
|---|
| 179 | 216 | } |
|---|
| | 217 | |
|---|
| 180 | 218 | |
|---|
| 181 | 219 | // Create the temporary ftp account |
|---|
| … | … | |
| 222 | 260 | * |
|---|
| 223 | 261 | * Get the directory listing of a specified dir, |
|---|
| 224 | | * either in short (default) or long mode |
|---|
| 225 | | * |
|---|
| 226 | | * @param string $dirname Full (virtual) directory path |
|---|
| 227 | | * @param boolean $long If FALSE only the filenames ar resturned, |
|---|
| 228 | | * If TRUE each entry is an array of file |
|---|
| 229 | | * properties |
|---|
| 230 | | * @return array Array of directory entries or FALSE on error |
|---|
| | 262 | * either in short (default) or long mode. |
|---|
| | 263 | * |
|---|
| | 264 | * @param string $dirname VFS directory path. |
|---|
| | 265 | * @return array Returns an array of directory entries or FALSE on error. |
|---|
| 231 | 266 | */ |
|---|
| 232 | 267 | function ls($dirname) { |
|---|
| | 268 | // Ensure that we're open |
|---|
| | 269 | if ( !$this->open() ) { |
|---|
| | 270 | return false; |
|---|
| | 271 | } |
|---|
| | 272 | |
|---|
| 233 | 273 | // Path is always relative to the root vfs |
|---|
| 234 | 274 | if (substr($dirname,0,1) != '/') { |
|---|
| 235 | 275 | $dirname = '/' . $dirname; |
|---|
| 236 | | } |
|---|
| 237 | | |
|---|
| 238 | | // Check for connection |
|---|
| 239 | | if ( !$this->_handle ) { |
|---|
| 240 | | return false; |
|---|
| 241 | 276 | } |
|---|
| 242 | 277 | |
|---|
| … | … | |
| 270 | 305 | * Checks for file existance |
|---|
| 271 | 306 | * |
|---|
| 272 | | * @param string $file Full (virtual) path to the file |
|---|
| 273 | | * @param int $type Type of the file to match (see constants) |
|---|
| 274 | | * @return boolean TRUE if file exists or FALSE if it doesn't exist |
|---|
| | 307 | * @param string $file VFS file path. |
|---|
| | 308 | * @param int $type Type of the file to match. Must be either VFS_TYPE_DIR, |
|---|
| | 309 | * VFS_TYPE_LINK or VFS_TYPE_FILE. |
|---|
| | 310 | * @return boolean Returns TRUE if file exists or FALSE if it doesn't exist. |
|---|
| 275 | 311 | */ |
|---|
| 276 | 312 | function exists($file, $type=null) { |
|---|
| | 313 | // Ensure that we're open |
|---|
| | 314 | if ( false === $this->open() ) { |
|---|
| | 315 | return false; |
|---|
| | 316 | } |
|---|
| | 317 | |
|---|
| | 318 | // Actually get the listing |
|---|
| 277 | 319 | $dirname = dirname($file); |
|---|
| 278 | 320 | $list = $this->ls($dirname); |
|---|
| … | … | |
| 299 | 341 | } |
|---|
| 300 | 342 | |
|---|
| | 343 | /** |
|---|
| | 344 | * Retrieves a file from the virtual file system |
|---|
| | 345 | * |
|---|
| | 346 | * @param string $file VFS file path. |
|---|
| | 347 | * @param int VFS transfer mode. Must be either VFS_ASCII or VFS_BINARY. |
|---|
| | 348 | * @return boolean Returns TRUE on succes or FALSE on failure. |
|---|
| | 349 | */ |
|---|
| | 350 | function get($file, $mode=VFS_ASCII) { |
|---|
| | 351 | // Ensure that we're open |
|---|
| | 352 | if ( !$this->open() ) { |
|---|
| | 353 | return false; |
|---|
| | 354 | } |
|---|
| | 355 | |
|---|
| | 356 | // Get a temporary file name |
|---|
| | 357 | $tmp = tempnam(VFS_TMP_DIR, 'vfs_'); |
|---|
| | 358 | // Get the actual file |
|---|
| | 359 | $res = ftp_get( $this->_handle, $tmp, $file, $mode); |
|---|
| | 360 | if ( false === $res ) { |
|---|
| | 361 | return false; |
|---|
| | 362 | } |
|---|
| | 363 | |
|---|
| | 364 | // Retrieve file contents |
|---|
| | 365 | $res = file_get_contents($tmp); |
|---|
| | 366 | |
|---|
| | 367 | // Delete temporary file |
|---|
| | 368 | unlink($tmp); |
|---|
| | 369 | |
|---|
| | 370 | return $res; |
|---|
| | 371 | } |
|---|
| | 372 | |
|---|
| | 373 | /** |
|---|
| | 374 | * Stores a file inside the virtual file system |
|---|
| | 375 | * |
|---|
| | 376 | * @param string $file VFS file path. |
|---|
| | 377 | * @param string $content File contents. |
|---|
| | 378 | * @param int VFS transfer mode. Must be either VFS_ASCII or VFS_BINARY. |
|---|
| | 379 | * @return boolean Returns TRUE on success or FALSE on failure. |
|---|
| | 380 | */ |
|---|
| | 381 | function put($file, $content, $mode=VFS_ASCII) { |
|---|
| | 382 | var_export($this);die(); |
|---|
| | 383 | // Ensure that we're open |
|---|
| | 384 | if ( !$this->open() ) { |
|---|
| | 385 | return false; |
|---|
| | 386 | } |
|---|
| | 387 | |
|---|
| | 388 | // Get a temporary file name |
|---|
| | 389 | $tmp = tempnam(VFS_TMP_DIR, 'vfs_'); |
|---|
| | 390 | |
|---|
| | 391 | // Save temporary file |
|---|
| | 392 | $res = file_put_contents($tmp, $content); |
|---|
| | 393 | if ( false === $res ) { |
|---|
| | 394 | return false; |
|---|
| | 395 | } |
|---|
| | 396 | |
|---|
| | 397 | // Upload it |
|---|
| | 398 | $res = ftp_put( $this->_handle, $file, $tmp, $mode); |
|---|
| | 399 | if ( !$res ) { |
|---|
| | 400 | return false; |
|---|
| | 401 | } |
|---|
| | 402 | |
|---|
| | 403 | // Remove temp file |
|---|
| | 404 | unlink($tmp); |
|---|
| | 405 | |
|---|
| | 406 | return true; |
|---|
| | 407 | } |
|---|
| | 408 | |
|---|
| 301 | 409 | } |
|---|
| 302 | 410 | |
|---|
| | 411 | /** |
|---|
| | 412 | * Make sure we have needed file_put_contents() functionality |
|---|
| | 413 | */ |
|---|
| | 414 | if (!function_exists('file_put_contents')) { |
|---|
| | 415 | function file_put_contents($filename, $content) |
|---|
| | 416 | { |
|---|
| | 417 | // Make sure that we have a string to write |
|---|
| | 418 | if (!is_scalar($content)) { |
|---|
| | 419 | user_error('file_put_contents() The 2nd parameter should be a string', |
|---|
| | 420 | E_USER_WARNING); |
|---|
| | 421 | return false; |
|---|
| | 422 | } |
|---|
| | 423 | |
|---|
| | 424 | // Get the data size |
|---|
| | 425 | $length = strlen($content); |
|---|
| | 426 | |
|---|
| | 427 | // Open the file for writing |
|---|
| | 428 | if (($fh = @fopen($filename, 'wb')) === false) { |
|---|
| | 429 | user_error('file_put_contents() failed to open stream: Permission denied', |
|---|
| | 430 | E_USER_WARNING); |
|---|
| | 431 | return false; |
|---|
| | 432 | } |
|---|
| | 433 | |
|---|
| | 434 | // Write to the file |
|---|
| | 435 | $bytes = 0; |
|---|
| | 436 | if (($bytes = @fwrite($fh, $content)) === false) { |
|---|
| | 437 | $errormsg = sprintf('file_put_contents() Failed to write %d bytes to %s', |
|---|
| | 438 | $length, |
|---|
| | 439 | $filename); |
|---|
| | 440 | user_error($errormsg, E_USER_WARNING); |
|---|
| | 441 | return false; |
|---|
| | 442 | } |
|---|
| | 443 | |
|---|
| | 444 | // Close the handle |
|---|
| | 445 | @fclose($fh); |
|---|
| | 446 | |
|---|
| | 447 | // Check all the data was written |
|---|
| | 448 | if ($bytes != $length) { |
|---|
| | 449 | $errormsg = sprintf('file_put_contents() Only %d of %d bytes written, possibly out of free disk space.', |
|---|
| | 450 | $bytes, |
|---|
| | 451 | $length); |
|---|
| | 452 | user_error($errormsg, E_USER_WARNING); |
|---|
| | 453 | return false; |
|---|
| | 454 | } |
|---|
| | 455 | |
|---|
| | 456 | // Return length |
|---|
| | 457 | return $bytes; |
|---|
| | 458 | } |
|---|
| | 459 | } |
|---|
| | 460 | |
|---|
| | 461 | |
|---|
| 303 | 462 | ?> |
|---|
| r371 |
r402 |
|
| 48 | 48 | <tr> |
|---|
| 49 | 49 | <td><table width="100%" cellspacing="7"> |
|---|
| | 50 | <!-- BDP: page_message --> |
|---|
| | 51 | <tr> |
|---|
| | 52 | <td colspan="3" nowrap class="title"><font color="#FF0000">{MESSAGE}</font></td> |
|---|
| | 53 | </tr> |
|---|
| | 54 | <!-- EDP: page_message --> |
|---|
| 50 | 55 | <tr> |
|---|
| 51 | 56 | <td width="25"> </td> |
|---|
| r396 |
r402 |
|
| 50 | 50 | </tr> |
|---|
| 51 | 51 | <tr> |
|---|
| 52 | | <td valign="top"><form name="add_user_group" method="post" action="puser_uadd.php"><table width="100%" cellpadding="5" cellspacing="5"> |
|---|
| | 52 | <td valign="top"> |
|---|
| | 53 | <form name="add_user_group" method="post" action="puser_uadd.php"> |
|---|
| | 54 | <table width="100%" cellpadding="5" cellspacing="5"> |
|---|
| 53 | 55 | <!-- BDP: page_message --> |
|---|
| 54 | 56 | <tr> |
|---|
|