Changeset 999

Show
Ignore:
Timestamp:
02/13/08 00:08:15 (7 months ago)
Author:
rats
Message:

* Fixed #808: webmail.mydomain.tld, pma.mydomain.tld
* Fixed #864: improve the detection of the disk usage of backups so users can't abuse
* Fixed #934: Prohibit creation of default subdomains

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/CHANGELOG

    r998 r999  
    11ispCP ω 1.0.0 Changelog 
    22~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     3 
     42008-02-13 Benedikt Heintel 
     5        - CONFIGS: 
     6                * Fixed #808: webmail.mydomain.tld, pma.mydomain.tld 
     7        - ENGINE: 
     8                * Fixed #864: improve the detection of the disk usage of backups so users can't abuse 
     9        - GUI: 
     10                * Fixed #934: Prohibit creation of default subdomains 
    311 
    4122008-02-12 Christian Hernmarck 
  • trunk/configs/apache/parts/dmn_entry.tpl

    r964 r999  
    1818 
    1919    Alias /errors   {WWW_DIR}/{DMN_NAME}/errors/ 
     20 
     21    Redirect permanent /ftp             http://{BASE_SERVER_VHOST}/ftp/ 
     22    Redirect permanent /pma             http://{BASE_SERVER_VHOST}/pma/ 
     23    Redirect permanent /webmail http://{BASE_SERVER_VHOST}/webmail/ 
    2024 
    2125    ErrorDocument 401 /errors/401.html 
  • trunk/docs/Debian/INSTALL

    r996 r999  
    6363 
    64643. Install the required modules 
    65    first update your system: 
     65   First update your system: 
    6666        # apt-get update && apt-get upgrade 
    6767 
     
    9292        (when you get to the rootkithunter screen, select two time 'yes') 
    9393 
     94        Now install needed Perl modules: 
     95 
     96        # cpan 
     97        cpan> install FindBin 
     98        cpan> install Net::LibIDN 
     99        cpan> quit 
     100 
    941014. (optional) Check the ispcp.conf and adapt it to your requirements. 
    95102   An overview over the variables you can find in the FAQ on 
  • trunk/engine/quota/ispcp-dsk-quota

    r955 r999  
    44# Copyright (c) 2001-2006 by moleSoftware GmbH 
    55# http://www.molesoftware.com 
    6 # Copyright (c) 2006-2007 by isp Control Panel 
     6# Copyright (c) 2006-2008 by isp Control Panel 
    77# http://isp-control.net 
    88# 
     
    106106        my $size = 0; 
    107107 
    108         my $s = `$cmd_du --exclude="backups/*.bz2" --exclude="backups/*.gz" -s -B1 $main::cfg{APACHE_WWW_DIR}/$domain_name`; 
     108        my $s = `$cmd_du --exclude="backups/$domain_name-*.bz2" --exclude="backups/$domain_name-*.gz" -s -B1 $main::cfg{APACHE_WWW_DIR}/$domain_name`; 
    109109 
    110110        $s =~ /^(\d+)/; $size += $1; 
  • trunk/engine/setup/ispcp-update

    r996 r999  
    118118\t(2) VHCS 2.4.8 RC1 
    119119\t(3) ispCP OMEGA 1.0.0 RC2 (incl. b and c) 
     120\t(4) ispCP OMEAG 1.0.0 RC3 
    120121\t(0) abort 
    121122MSG 
     
    127128        chop($rdata); 
    128129 
    129         while ($rdata < 0 || $rdata > 3) { 
     130        while ($rdata < 0 || $rdata > 4) { 
    130131                print STDOUT "\tPlease select an item mentioned above: "; 
    131132                $rdata = readline(\*STDIN); 
     
    324325                exit_werror("SQL Update failed."); 
    325326        } 
     327 
     328        # Delete vhcs2 Database 
     329        ($rs, $rdata) = doSQL("DROP DATABASE IF EXISTS `vhcs2`;"); 
     330    if ($rs != 0) { 
     331        print STDOUT "failed!\n"; 
     332        exit_werror($rdata, $rs); 
     333    } 
    326334 
    327335    print STDOUT "\tdone\n"; 
     
    722730} 
    723731 
     732sub patch_ispcp_rc3() { 
     733        push_el(\@main::el, 'patch_ispcp_rc3()', 'Ending...'); 
     734 
     735        print STDOUT "\tNothing to do yet!\n"; 
     736 
     737        push_el(\@main::el, 'patch_ispcp_rc3()', 'Ending...'); 
     738        return 0; 
     739} 
     740 
    724741sub prepare_update { 
    725742        my ($rs, $rdata) = (undef, undef); 
     
    733750        # Abort 
    734751        if ($main::ua{'update'} eq 0) { 
    735                 exit_werror("\tScript was aborted by user"); 
     752                exit_werror("\tScript was aborted by user."); 
    736753        } 
    737754        # VHCS update 
     
    755772                return $rs if ($rs != 0); 
    756773        } 
    757         # ispCP 1.0.0 RC2 Update 
    758         elsif ($main::ua{'update'} eq 3) { 
     774        # ispCP 1.0.0 RC2/3 Update 
     775        elsif ($main::ua{'update'} gt 3) { 
    759776                stop_services("/tmp/vhcs2-backup-all.lock"); 
    760777 
     
    774791                } 
    775792 
    776                 $rs = patch_ispcp_rc2(); 
     793                # ispCP 1.0.0 RC2 
     794                if ($main::ua{'update'} eq 3) { 
     795                        $rs = patch_ispcp_rc2(); 
     796                } 
     797                # ispCP 1.0.0 RC3 
     798                elsif ($main::ua{'update'} eq 4) { 
     799                        $rs = patch_ispcp_rc3(); 
     800                } 
     801 
     802                if ($rs != 0) { 
     803                print STDOUT "\t Update failed!\n"; 
     804                        exit_werror("ispCP Update failed."); 
     805                } 
    777806                return $rs if ($rs != 0); 
    778807 
  • trunk/gui/client/add_subdomain.php

    r880 r999  
    44 * 
    55 * @copyright   2001-2006 by moleSoftware GmbH 
    6  * @copyright   2006-2007 by ispCP | http://isp-control.net 
     6 * @copyright   2006-2008 by ispCP | http://isp-control.net 
    77 * @link                http://isp-control.net 
    8  * @author              ispCP Team (2007) 
     8 * @author              ispCP Team 
    99 * 
    1010 * @license 
     
    110110        $rs_domain = exec_query($sql, $query_domain, array($domain_name)); 
    111111 
     112        # Prohibit www. mail. nsX. imap. pop. pop3. relay. smtp. ftp. pma. webmail. 
     113        if ($sub_name == "www" || $sub_name == "mail" || preg_match('/^ns[0-9]{1,3}$/i', $sub_name) || 
     114                $sub_name == "imap" || $sub_name == "pop" || $sub_name == "pop3" || 
     115                $sub_name == "relay" || $sub_name == "smtp" || $sub_name == "ftp" || 
     116                $sub_name == "pma" || $sub_name == "webmail") { 
     117                return true; 
     118        } 
     119 
    112120        if ($rs_subdomain->fields['cnt'] == 0 && $rs_domain->fields['cnt'] == 0) 
    113121                return false; 
     
    248256 
    249257                if (subdmn_exists($sql, $user_id, $domain_id, $sub_name)) { 
    250                         set_page_message(tr('Subdomain already exists!')); 
     258                        set_page_message(tr('Subdomain already exists or is not allowed!')); 
    251259                } else if (!chk_subdname($sub_name . "." . $dmn_name)) { 
    252260                        set_page_message(tr('Wrong subdomain syntax!')); 
  • trunk/gui/client/manage_domains.php

    r811 r999  
    44 * 
    55 * @copyright   2001-2006 by moleSoftware GmbH 
    6  * @copyright   2006-2007 by ispCP | http://isp-control.net 
    7  * @version     SVN: $ID$ 
     6 * @copyright   2006-2008 by ispCP | http://isp-control.net 
    87 * @link                http://isp-control.net 
    9  * @author              ispCP Team (2007) 
     8 * @author              ispCP Team 
    109 * 
    1110 * @license 
  • trunk/gui/include/vfs.php

    r766 r999  
    11<?php 
    22/** 
    3  * ispCP (OMEGA) - Virtual Hosting Control System | Omega Version 
     3 * ispCP ω (OMEGA) a Virtual Hosting Control System 
    44 * 
    5  *  @copyright  2001-2006 by moleSoftware GmbH 
    6  *  @copyright  2006-2007 by ispCP | http://isp-control.net 
    7  *  @link               http://isp-control.net 
    8  *  @author             ispCP Team (2007) 
     5 * @copyright   2006-2008 by ispCP | http://isp-control.net 
     6 * @link                http://isp-control.net 
     7 * @author              ispCP Team 
    98 * 
    10  *  @license 
    11  *  This program is free software; you can redistribute it and/or modify it under 
    12  *  the terms of the MPL General Public License as published by the Free Software 
    13  *  Foundation; either version 1.1 of the License, or (at your option) any later 
    14  *  version. 
    15  *  You should have received a copy of the MPL Mozilla Public License along with 
    16  *  this program; if not, write to the Open Source Initiative (OSI) 
    17  *  http://opensource.org | osi@opensource.org 
    18  * 
    19  **/ 
     9 * @license 
     10 *   This program is free software; you can redistribute it and/or modify it under 
     11 *   the terms of the MPL General Public License as published by the Free Software 
     12 *   Foundation; either version 1.1 of the License, or (at your option) any later 
     13 *   version. 
     14 *   You should have received a copy of the MPL Mozilla Public License along with 
     15 *   this program; if not, write to the Open Source Initiative (OSI) 
     16 *   http://opensource.org | osi@opensource.org 
     17 */ 
    2018 
    2119/* 
     
    2624 * File types definition 
    2725 */ 
    28 define('VFS_TYPE_DIR', 'd'); 
     26define('VFS_TYPE_DIR', 'd'); 
    2927define('VFS_TYPE_LINK', 'l'); 
    3028define('VFS_TYPE_FILE', '-'); 
     
    3331 * Possible VFS Transfer modes 
    3432 */ 
    35 define('VFS_ASCII', FTP_ASCII); 
     33define('VFS_ASCII', FTP_ASCII); 
    3634define('VFS_BINARY', FTP_BINARY); 
    3735 
     
    4341 */ 
    4442class vfs { 
    45  
    4643        /** 
    4744         * Domain name of this filesystem 
     
    8885         * left as work for the caller. 
    8986         * 
    90          * @param string   $domain Domain name of the new VFS. 
    91          * @param resource $db      Adodb database resource. 
     87         * @param string $domain Domain name of the new VFS. 
     88         * @param resource $db Adodb database resource. 
    9289         * @return vfs 
    9390         */ 
     
    10198         * PHP5 constructor 
    10299         * 
    103          * @param string  $domain Domain name of the new VFS. 
    104          * @param resource $db    Adodb database resource. 
     100         * @param string $domain Domain name of the new VFS. 
     101         * @param resource $db Adodb database resource. 
    105102         * @return vfs 
    106103         */ 
    107104        function __construct($domain, &$db) { 
    108             global $cfg; 
    109                 $this->_domain = $domain; 
    110                 $this->_db     =& $db; 
     105               global $cfg; 
     106                $this->_domain = $domain; 
     107                $this->_db = &$db; 
    111108 
    112109                if (!defined("VFS_TMP_DIR")) { 
    113                   define("VFS_TMP_DIR", $cfg['GUI_ROOT_DIR'] . '/phptmp'); 
     110                       define("VFS_TMP_DIR", $cfg['GUI_ROOT_DIR'] . '/phptmp'); 
    114111                } 
    115112                $_ENV['TMPDIR'] = VFS_TMP_DIR; 
     
    131128         * handler, but we're a "black box" ;). 
    132129         * 
    133          * @param resource $db Adodb database resource. 
     130         * @param resource $db Adodb database resource. 
    134131         */ 
    135132        function setDb(&$db) { 
    136                 $this->_db =& $db; 
     133                $this->_db = &$db; 
    137134        } 
    138135 
     
    143140         */ 
    144141        function _createTmpUser() { 
    145             global $cfg; 
    146  
     142                global $cfg; 
    147143                // Get domain data 
    148144                $query = 'select domain_uid, domain_gid 
     
    150146                                  where  domain_name = ?'; 
    151147                $rs = exec_query($this->_db, $query, array($this->_domain)); 
    152                 if ( !$rs ) { 
    153                         return false; 
    154                 } 
    155  
     148                if (!$rs) { 
     149                        return false; 
     150                } 
    156151                // Generate a random userid and password 
    157                 $user   = uniqid('tmp_').'@'.$this->_domain; 
    158                 $this->_passwd = uniqid('tmp_',true); 
     152                $user = uniqid('tmp_') . '@' . $this->_domain; 
     153                $this->_passwd = uniqid('tmp_', true); 
    159154                $passwd = crypt_user_ftp_pass($this->_passwd); 
    160  
    161155                // Create the temporary user 
    162156                $query = <<<SQL_QUERY 
     
    166160                    (?, ?, ?, ?, ?, ?) 
    167161SQL_QUERY; 
    168                 $rs = exec_query($this->_db, $query, array( 
    169                         $user, $passwd, $rs->fields['domain_uid'], $rs->fields['domain_gid'], 
    170                         $cfg['FTP_SHELL'], $cfg['FTP_HOMEDIR'].'/' . $this->_domain 
    171                 )); 
    172                 if ( !$rs ) { 
    173                         return false; 
    174                 } 
    175  
     162                $rs = exec_query($this->_db, $query, array($user, $passwd, $rs->fields['domain_uid'], $rs->fields['domain_gid'], 
     163                                $cfg['FTP_SHELL'], $cfg['FTP_HOMEDIR'] . '/' . $this->_domain 
     164                                )); 
     165                if (!$rs) { 
     166                        return false; 
     167                } 
    176168                // All ok 
    177                 $this->_user   = $user; 
     169                $this->_user = $user; 
    178170                return true; 
    179171        } 
     
    197189         * Open the virtual file system 
    198190         * 
    199          * @return boolean     Returns TRUE on succes or FALSE on failure. 
     191         * @return boolean Returns TRUE on succes or FALSE on failure. 
    200192         */ 
    201193        function open() { 
    202194                // Check if we're already open 
    203                 if ( is_resource($this->_handle) ) { 
     195                if (is_resource($this->_handle)) { 
    204196                        return true; 
    205197                } 
    206  
    207198                // Check if we have a valid ispcp database 
    208                 if ( !$this->_db ) { 
    209                         return false; 
    210                 } 
    211  
    212  
     199                if (!$this->_db) { 
     200                        return false; 
     201                } 
    213202                // Create the temporary ftp account 
    214203                $result = $this->_createTmpUser(); 
    215                 if ( !$result ) { 
    216                         return false; 
    217                 } 
    218  
     204                if (!$result) { 
     205                        return false; 
     206                } 
    219207                // 'localhost' for testing purposes. I have to study if a better 
    220208                // $this->_domain would work on all situations 
    221209                $this->_handle = @ftp_connect('localhost'); 
    222                 if ( !is_resource($this->_handle) ) { 
     210                if (!is_resource($this->_handle)) { 
    223211                        $this->close(); 
    224212                        return false; 
    225213                } 
    226  
    227214                // Perform actual login 
    228                 $response = @ftp_login( $this->_handle, $this->_user, $this->_passwd); 
    229                 if ( !$response ) { 
     215                $response = @ftp_login($this->_handle, $this->_user, $this->_passwd); 
     216                if (!$response) { 
    230217                        $this->close(); 
    231218                        return false; 
    232219                } 
    233  
    234220                // All went ok! :) 
    235221                return true; 
     
    238224        /** 
    239225         * Closes the virtual file system 
    240          * 
    241226         */ 
    242227        function close() { 
     
    258243         * either in short (default) or long mode. 
    259244         * 
    260          * @param string $dirname VFS directory path. 
    261          * @return array Returns an array of directory entries or FALSE on error. 
     245         * @param string $dirname VFS directory path. 
     246         * @return array Returns an array of directory entries or FALSE on error. 
    262247         */ 
    263248        function ls($dirname) { 
    264249                // Ensure that we're open 
    265                 if ( !$this->open() ) { 
    266                         return false; 
    267                 } 
    268  
     250                if (!$this->open()) { 
     251                        return false; 
     252                } 
    269253                // Path is always relative to the root vfs 
    270                 if (substr($dirname,0,1) != '/') { 
     254                if (substr($dirname, 0, 1) != '/') { 
    271255                        $dirname = '/' . $dirname; 
    272256                } 
    273  
    274257                // No security implications, the FTP server handles 
    275258                // this for us 
    276                 $list = ftp_rawlist( $this->_handle, '-a '.$dirname, false ); 
    277                 if ( !$list ) { 
     259                $list = ftp_rawlist($this->_handle, '-a ' . $dirname, false); 
     260                if (!$list) { 
    278261                        return false; 
    279262                } 
    280263                $len = count($list); 
    281                 for( $i=0; $i<$len; $i++ ) { 
    282                         $parts = preg_split("/[\s]+/",$list[$i],9); 
    283                         $list[$i] = array( 
    284                                 'perms'         => $parts[0], 
    285                                 'number'        => $parts[1], 
    286                                 'owner'         => $parts[2], 
    287                                 'group'         => $parts[3], 
    288                                 'size'          => $parts[4], 
    289                                 'month'         => $parts[5], 
    290                                 'day'           => $parts[6], 
    291                                 'time'          => $parts[7], 
    292                                 'file'          => $parts[8], 
    293                                 'type'          => substr($parts[0],0,1), 
    294                         ); 
     264                for($i = 0; $i < $len; $i++) { 
     265                        $parts = preg_split("/[\s]+/", $list[$i], 9); 
     266                        $list[$i] = array('perms' => $parts[0], 
     267                                'number' => $parts[1], 
     268                                'owner' => $parts[2], 
     269                                'group' => $parts[3], 
     270                                'size' => $parts[4], 
     271                                'month' => $parts[5], 
     272                                'day' => $parts[6], 
     273                                'time' => $parts[7], 
     274                                'file' => $parts[8], 
     275                                'type' => substr($parts[0], 0, 1), 
     276                                ); 
    295277                } 
    296278 
     
    301283         * Checks for file existance 
    302284         * 
    303          * @param string $file VFS file path. 
    304          * @param int $type Type of the file to match. Must be either VFS_TYPE_DIR, 
     285         * @param string $file VFS file path. 
     286         * @param int $type Type of the file to match. Must be either VFS_TYPE_DIR, 
    305287         *                                      VFS_TYPE_LINK or VFS_TYPE_FILE. 
    306288         * @return boolean Returns TRUE if file exists or FALSE if it doesn't exist. 
    307289         */ 
    308         function exists($file, $type=null) { 
     290        function exists($file, $type = null) { 
    309291                // Ensure that we're open 
    310                 if ( false === $this->open() ) { 
    311                         return false; 
    312                 } 
    313  
     292                if (false === $this->open()) { 
     293                        return false; 
     294                } 
    314295                // Actually get the listing 
    315296                $dirname = dirname($file); 
    316297                $list = $this->ls($dirname); 
    317                 if ( !$list ) 
    318                         return false; 
    319  
     298                if (!$list) 
     299                        return false; 
    320300                // We get filenames only from the listing 
    321301                $file = basename($file); 
    322  
    323302                // Try to match it 
    324303                foreach($list as $entry) { 
    325304                        // Skip non-matching files 
    326                         if ( $entry['file'] != $file ) { 
     305                        if ($entry['file'] != $file) { 
    327306                                continue; 
    328307                        } 
    329308                        // Check type 
    330                         if ( $type !== null && $entry['type'] != $type
     309                        if ($type !== null && $entry['type'] != $type
    331310                                return false; 
    332  
    333311                        // Matched and same type (or no type specified) 
    334312                        return true; 
     
    340318         * Retrieves a file from the virtual file system 
    341319         * 
    342          * @param string $file VFS file path. 
    343          * @param int VFS transfer mode. Must be either VFS_ASCII or VFS_BINARY. 
     320         * @param string $file VFS file path. 
     321         * @param int $ VFS transfer mode. Must be either VFS_ASCII or VFS_BINARY. 
    344322         * @return boolean Returns TRUE on succes or FALSE on failure. 
    345323         */ 
    346         function get($file, $mode=VFS_ASCII) { 
     324        function get($file, $mode = VFS_ASCII) { 
    347325                // Ensure that we're open 
    348                 if ( !$this->open() ) { 
    349                         return false; 
    350                 } 
    351  
     326                if (!$this->open()) { 
     327                        return false; 
     328                } 
    352329                // Get a temporary file name 
    353330                $tmp = tempnam(VFS_TMP_DIR, 'vfs_'); 
    354331                // Get the actual file 
    355                 $res = ftp_get( $this->_handle, $tmp, $file, $mode); 
    356                 if ( false === $res ) { 
    357                         return false; 
    358                 } 
    359  
     332                $res = ftp_get($this->_handle, $tmp, $file, $mode); 
     333                if (false === $res) { 
     334                        return false; 
     335                } 
    360336                // Retrieve file contents 
    361337                $res = file_get_contents($tmp); 
    362  
    363338                // Delete temporary file 
    364339                unlink($tmp); 
     
    372347         * @param string $file VFS file path. 
    373348         * @param string $content File contents. 
    374          * @param int VFS transfer mode. Must be either VFS_ASCII or VFS_BINARY. 
     349         * @param int $ VFS transfer mode. Must be either VFS_ASCII or VFS_BINARY. 
    375350         * @return boolean Returns TRUE on success or FALSE on failure. 
    376351         */ 
    377         function put($file, $content, $mode=VFS_ASCII) { 
    378  
     352        function put($file, $content, $mode = VFS_ASCII) { 
    379353                // Ensure that we're open 
    380                 if ( !$this->open() ) { 
    381                         return false; 
    382                 } 
    383  
     354                if (!$this->open()) { 
     355                        return false; 
     356                } 
    384357                // Get a temporary file name 
    385358                $tmp = tempnam(VFS_TMP_DIR, 'vfs_'); 
    386  
    387359                // Save temporary file 
    388360                $res = file_put_contents($tmp, $content); 
    389                 if ( false === $res ) { 
    390                         return false; 
    391                 } 
    392  
     361                if (false === $res) { 
     362                        return false; 
     363                } 
    393364                // Upload it 
    394                 $res = ftp_put( $this->_handle, $file, $tmp, $mode); 
    395                 if ( !$res ) { 
    396                         return false; 
    397                 } 
    398  
     365                $res = ftp_put($this->_handle, $file, $tmp, $mode); 
     366                if (!$res) { 
     367                        return false; 
     368                } 
    399369                // Remove temp file 
    400370                unlink($tmp); 
     
    402372                return true; 
    403373        } 
    404  
    405374} 
    406375 
     
    409378 */ 
    410379if (!function_exists('file_put_contents')) { 
    411     function file_put_contents($filename, $content) 
    412     { 
    413         // Make sure that we have a string to write 
    414         if (!is_scalar($content)) { 
    415             user_error('file_put_contents() The 2nd parameter should be a string', 
    416                 E_USER_WARNING); 
    417             return false; 
    418         } 
    419  
    420         // Get the data size 
    421         $length = strlen($content); 
    422  
    423         // Open the file for writing 
    424         if (($fh = @fopen($filename, 'wb')) === false) { 
    425             user_error('file_put_contents() failed to open stream: Permission denied', 
    426                 E_USER_WARNING); 
    427             return false; 
    428         } 
    429  
    430         // Write to the file 
    431         $bytes = 0; 
    432         if (($bytes = @fwrite($fh, $content)) === false) { 
    433             $errormsg = sprintf('file_put_contents() Failed to write %d bytes to %s', 
    434                             $length, 
    435                             $filename); 
    436             user_error($errormsg, E_USER_WARNING); 
    437             return false; 
    438         } 
    439  
    440         // Close the handle 
    441         @fclose($fh); 
    442  
    443         // Check all the data was written 
    444         if ($bytes != $length) { 
    445             $errormsg = sprintf('file_put_contents() Only %d of %d bytes written, possibly out of free disk space.', 
    446                             $bytes, 
    447                             $length); 
    448             user_error($errormsg, E_USER_WARNING); 
    449             return false; 
    450         } 
    451  
    452         // Return length 
    453         return $bytes; 
    454     } 
     380        function file_put_contents($filename, $content) { 
     381                // Make sure that we have a string to write 
     382                if (!is_scalar($content)) { 
     383                        user_error('file_put_contents() The 2nd parameter should be a string', 
     384                                E_USER_WARNING); 
     385                        return false; 
     386                } 
     387                // Get the data size 
     388                $length = strlen($content); 
     389                // Open the file for writing 
     390                if (($fh = @fopen($filename, 'wb')) === false) { 
     391                        user_error('file_put_contents() failed to open stream: Permission denied', 
     392                                E_USER_WARNING); 
     393                        return false; 
     394                } 
     395                // Write to the file 
     396                $bytes = 0; 
     397                if (($bytes = @fwrite($fh, $content)) === false) { 
     398                        $errormsg = sprintf('file_put_contents() Failed to write %d bytes to %s', 
     399                                $length, 
     400                                $filename); 
     401                        user_error($errormsg, E_USER_WARNING); 
     402                        return false; 
     403                } 
     404                // Close the handle 
     405                @fclose($fh); 
     406                // Check all the data was written 
     407                if ($bytes != $length) { 
     408                        $errormsg = sprintf('file_put_contents() Only %d of %d bytes written, possibly out of free disk space.', 
     409                                $bytes, 
     410                                $length); 
     411                        user_error($errormsg, E_USER_WARNING); 
     412                        return false; 
     413                } 
     414                // Return length 
     415                return $bytes; 
     416        } 
    455417} 
    456418 
    457  
    458419?>