Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > ISPConfig 3 > Developers' Forum

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 29th May 2009, 16:40
Croydon Croydon is offline
ISPConfig Developer
 
Join Date: Jul 2007
Location: Koblenz, Germany
Posts: 922
Thanks: 16
Thanked 258 Times in 206 Posts
Default FTP-User directory change for customers

I needed customers to be able to create ftp accounts with special home directories inside the web-dir.
As an administrator is able to set the dir to whatever he likes (e.g. /etc) i made a set of changes to some files.

Maybe this is useful for some of you (and maybe it is good enough to be integrated into some of the next releases).


So here are the changes:

server/modules-available/web_module.inc.php
PHP Code:
    $app->modules->registerTableHook('web_domain','web_module','process');
// ADDED
$app->modules->registerTableHook('ftp_user','web_module','process');
// END ADDED
$app->modules->registerTableHook('shell_user','web_module','process'); 
new file: server/plugins-available/ftpuser_base_plugin.inc.php
(remember to set a symlink to server/plugins-enabled/ directory!)
PHP Code:
<?php

/*
Copyright (c) 2007, Till Brehm, projektfarm Gmbh
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
    * Neither the name of ISPConfig nor the names of its contributors
      may be used to endorse or promote products derived from this software without
      specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

class ftpuser_base_plugin {
    
    var 
$plugin_name 'ftpuser_base_plugin';
    var 
$class_name 'ftpuser_base_plugin';
    
    
//* This function is called during ispconfig installation to determine
    //  if a symlink shall be created for this plugin.
    
function onInstall() {
        global 
$conf;
        
        if(
$conf['services']['web'] == true) {
            return 
true;
        } else {
            return 
false;
        }
        
    }
    
        
    
/*
         This function is called when the plugin is loaded
    */
    
    
function onLoad() {
        global 
$app;
        
        
/*
        Register for the events
        */
        
        
$app->plugins->registerEvent('ftp_user_insert',$this->plugin_name,'insert');
        
$app->plugins->registerEvent('ftp_user_update',$this->plugin_name,'update');
        
$app->plugins->registerEvent('ftp_user_delete',$this->plugin_name,'delete');

        
    }
    
    
    function 
insert($event_name,$data) {
        global 
$app$conf;
        
    if(!
is_dir($data['new']['dir'])) {
      
$app->log("FTP User directory '".$data['new']['dir']."' does not exist. Creating it now.",LOGLEVEL_DEBUG);
      
      
$web $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".intval($data['new']['parent_domain_id']));
      
      
exec('mkdir -p '.escapeshellcmd($data['new']['dir']));
      
exec('chown '.escapeshellcmd($web["system_user"]).':'.escapeshellcmd($web['system_group']).' '.$data['new']['dir']);
      
      
$app->log("Added ftpuser_dir: ".$data['new']['dir'],LOGLEVEL_DEBUG);
    }
    
    }
    
    function 
update($event_name,$data) {
        global 
$app$conf;
        
    if(!
is_dir($data['new']['dir'])) {
      
$app->log("FTP User directory '".$data['new']['dir']."' does not exist. Creating it now.",LOGLEVEL_DEBUG);
      
      
$web $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".intval($data['new']['parent_domain_id']));
      
      
exec('mkdir -p '.escapeshellcmd($data['new']['dir']));
      
exec('chown '.escapeshellcmd($web["system_user"]).':'.escapeshellcmd($web['system_group']).' '.$data['new']['dir']);
      
      
$app->log("Added ftpuser_dir: ".$data['new']['dir'],LOGLEVEL_DEBUG);
    }
    }
    
    function 
delete($event_name,$data) {
        global 
$app$conf;
        
    
$app->log("Ftpuser:".$data['new']['username']." deleted.",LOGLEVEL_DEBUG);
        
    }
    
    
    

// end class

?>

new file: interface/web/sites/templates/ftp_user_advanced_client.htm
HTML Code:
<h2><tmpl_var name="list_head_txt"></h2>
<p><tmpl_var name="list_desc_txt"></p>

<div class="panel panel_ftp_user">

  <div class="pnl_formsarea">
    <fieldset class="inlineLabels">
      <div class="ctrlHolder">
      	<label for="dir">{tmpl_var name='dir_txt'}</label>
        <input name="dir" id="dir" value="{tmpl_var name='dir'}" size="30" maxlength="255" type="text" class="textInput" />
			</div>
    </fieldset>

    <input type="hidden" name="id" value="{tmpl_var name='id'}">

    <div class="buttonHolder buttons">
      <button class="positive iconstxt icoPositive" type="button" value="{tmpl_var name='btn_save_txt'}" onClick="submitForm('pageForm','sites/ftp_user_edit.php');"><span>{tmpl_var name='btn_save_txt'}</span></button>
      <button class="negative iconstxt icoNegative" type="button" value="{tmpl_var name='btn_cancel_txt'}" onClick="loadContent('sites/ftp_user_list.php');"><span>{tmpl_var name='btn_cancel_txt'}</span></button>
    </div>
  </div>
  
</div>
new language entry in "interface/web/sites/lib/lang/en_ftp_user.lng"
PHP Code:
$wb['directory_error_notinweb'] = 'Directory not inside of web root directory.'
in "interface/web/sites/form/ftp_user.tform.php" add the following code near the bottom (else block for the "if is admin" check)

PHP Code:
.......
} else {

$form["tabs"]['advanced'] = array (
    
'title'     => "Options",
    
'width'     => 100,
    
'template'  => "templates/ftp_user_advanced_client.htm",
    
'fields'    => array (
    
##################################
    # Begin Datatable fields
    ##################################
        
'dir' => array (
            
'datatype'  => 'VARCHAR',
            
'formtype'  => 'TEXT',
            
'validators'    => array (  => array (    'type'  => 'NOTEMPTY',
                                                        
'errmsg'=> 'directory_error_empty'),
                                        
=> array (    'type'  => 'CUSTOM',
                                                        
'class' => 'validate_ftpuser',
                                                        
'function' => 'ftp_dir',
                                                        
'errmsg' => 'directory_error_notinweb'),
                                    ),
            
'default'   => '',
            
'value'     => '',
            
'width'     => '30',
            
'maxlength' => '255'
        
),
    
##################################
    # ENDE Datatable fields
    ##################################
    
)
);



create a new validation class file "interface/lib/classes/validate_ftpuser.inc.php"
PHP Code:
<?php

/*
Copyright (c) 2007, Till Brehm, projektfarm Gmbh
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
    * Neither the name of ISPConfig nor the names of its contributors
      may be used to endorse or promote products derived from this software without
      specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

class validate_ftpuser {
    
    
/*
        Validator function to check if a given dir is ok.
    */
    
function ftp_dir($field_name$field_value$validator) {
        global 
$app;
        
        if(
$app->tform->primary_id == 0) {
            
$errmsg $validator['errmsg'];
            if(isset(
$app->tform->wordbook[$errmsg])) {
                return 
$app->tform->wordbook[$errmsg]."<br>\r\n";
            } else {
                return 
$errmsg."<br>\r\n";
            }
        }
        
        
        
$ftp_data $app->db->queryOneRecord("SELECT parent_domain_id FROM ftp_user WHERE ftp_user_id = '".$app->db->quote($app->tform->primary_id)."'");
        if(!
$ftp_data["parent_domain_id"]) {
            
$errmsg $validator['errmsg'];
            if(isset(
$app->tform->wordbook[$errmsg])) {
                return 
$app->tform->wordbook[$errmsg]."<br>\r\n";
            } else {
                return 
$errmsg."<br>\r\n";
            }
        }
        
        
$domain_data $app->db->queryOneRecord("SELECT domain_id, document_root FROM web_domain WHERE domain_id = '".$app->db->quote($ftp_data["parent_domain_id"])."'");
        if(!
$domain_data["domain_id"]) {
            
$errmsg $validator['errmsg'];
            if(isset(
$app->tform->wordbook[$errmsg])) {
                return 
$app->tform->wordbook[$errmsg]."<br>\r\n";
            } else {
                return 
$errmsg."<br>\r\n";
            }
        }
        
        
$doc_root $domain_data["document_root"];
        
$is_ok false;
        if(
$doc_root == $field_value$is_ok true;
        
        
$doc_root .= "/";
        if(
substr($field_value0strlen($doc_root)) == $doc_root$is_ok true;
        
        if(
$is_ok == false) {
            
$errmsg $validator['errmsg'];
            if(isset(
$app->tform->wordbook[$errmsg])) {
                return 
$app->tform->wordbook[$errmsg]."<br>\r\n";
            } else {
                return 
$errmsg."<br>\r\n";
            }
        }
    }
    
    
    
    
}

this should be all.

Note, that changing the server module and adding the server plugin is optional. It is only for automatically creating the new ftp dir if it doesnt exist.
Reply With Quote
The Following 4 Users Say Thank You to Croydon For This Useful Post:
cf3d (15th July 2009), cpcortez (19th July 2009), falko (30th May 2009), till (31st May 2009)
Sponsored Links
  #2  
Old 15th July 2009, 19:33
cf3d cf3d is offline
Junior Member
 
Join Date: Feb 2009
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Fantastic!!!!!
Reply With Quote
  #3  
Old 15th July 2009, 22:48
cf3d cf3d is offline
Junior Member
 
Join Date: Feb 2009
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default

This is a great "plugin" if I can call it that.

I was wondering if this could be do. It's kinda hard for me to explain so just tell me if I sound stupid. lol.

I would like for the root path to be set to something like this:

/var/www/clients/client1/web1/web/

and have it hidden to where the user only sees a blank line and all they have to enter is the folder name. This would ensure that they do not try to go above the root.
Reply With Quote
  #4  
Old 4th August 2009, 10:33
Edek7 Edek7 is offline
Junior Member
 
Join Date: Jul 2009
Posts: 21
Thanks: 1
Thanked 1 Time in 1 Post
 
Default

Quote:
Originally Posted by cf3d View Post
This is a great "plugin" if I can call it that.

I was wondering if this could be do. It's kinda hard for me to explain so just tell me if I sound stupid. lol.

I would like for the root path to be set to something like this:

/var/www/clients/client1/web1/web/

and have it hidden to where the user only sees a blank line and all they have to enter is the folder name. This would ensure that they do not try to go above the root.
That is simple to do:

go to /usr/local/ispconfig/interface/web/sites/ftp_user_edit.php and add the following code:

$dir="{$dir}/web"

after two lines in code that are :

$dir = $web["document_root"];

From this time you don`t have to manually add /web
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ftp is very slow and asks for user/passwd continuously chico58 Installation/Configuration 7 8th October 2008 12:43
Error during installation on Debian 3, AMD64 processor nikola021 Installation/Configuration 1 6th October 2006 09:16
ISPConfig faiture glt50 Installation/Configuration 16 6th July 2006 01:58
Debian install error jf1976 Installation/Configuration 25 19th January 2006 22:31
ISP install problems Debian sarge 3.1 lerra Installation/Configuration 1 5th January 2006 16:37


All times are GMT +2. The time now is 08:30.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.