ISPConfog net2ftp integration hack

Discussion in 'Plugins/Modules/Addons' started by ebraux, Aug 14, 2013.

  1. ebraux

    ebraux New Member

    ===== net2ftp integration in the ISPConfig interface =====

    ==== Principle ====
    The same principle of integration than for phpmyadmin will be used :
    * Added a link to net2ftp in the list of ftp users in the "user interface".
    * Use a link that points to a wrapper, that builds an url with ispc database ftp-user information, and a "template url" from global variable
    * The template url is defined in system / main config / site, and can use placeholder, corresponding to net2ftp URI parameters : "ftpserver"and "username".
    * the link can be enabled or not

    We consider that "net2ftp" can be acceded with th uri "/net2ftp".


    ==== Setting up the link in the user interface net2ftp ====

    === Principle ===
    PhpMyAdmin link is defined in the file /var/www/ispconfig/sites/templates/database_list.htm.
    Code:
    <td class="tbl_col_buttons">
        <tmpl_if name="dblist_phpmyadmin_link">
            <a class="button icons16 icoDbAdmin" href="sites/database_phpmyadmin.php?id={tmpl_var name='id'}" target="phpmyadmin"><span>{tmpl_var name='admin_txt'}</span></a>
        </tmpl_if>
        ....
    <td>
    
    This shows that the link is based on the wrapper "sites/database_phpmyadmin.php", and passes the id of the database as argument ({tmpl_var name='id'})


    The same link can be found in the file /var/www/ispconfig/sites/templates/ftp_user_list.htm
    Code:
    <td class="tbl_col_buttons">
        <tmpl_if name="webftp_link">
            <a class="button icons16 icoDbAdmin" href="{tmpl_var name='webftp_url'}" target="_blank"><span>{tmpl_var name='admin_txt'}</span></a>
        </tmpl_if>
        ....
    <td>
    
    It is already planned to be able to display a link, if the global variable "webftp_link" is enabled. But this configuration only defines a generic url, that can not be customized according to ftp-user information.
    So we need to :
    * Changing the template so that it calls a wrapper "sites/webftp_net2ftp.php"
    * Write the wrapper
    * Enable the display of the icon

    === Changing the template to invoke the wrapper: ===
    Code:
    <a class="button icons16 icoDbAdmin" href="sites/ftp_user_net2ftp.php?id={tmpl_var name='id'}" target="net2ftp"><span>{tmpl_var name='admin_txt'}</span></a> 
    

    === Wrapper : "./sites/ftp_user_net2ftp.php" ===

    It is based on that which has been done to phpmyadmin
    Code:
    <?php
    /*
    Copyright (c) 2008, Till Brehm, projektfarm Gmbh
    Copyright (c) 2013, Emmanuel Braux
    
    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.
    */
    
    
    require_once('../../lib/config.inc.php');
    require_once('../../lib/app.inc.php');
    
    //* Check permissions for module
    $app->auth->check_module_permissions('sites');
    
    /*
     *  get the id of the database (must be int!)
     */
    if (!isset($_GET['id'])){
        die ("No FTP user selected!");
    }
    $ftpUserId = $app->functions->intval($_GET['id']);
    
    /*
     * Get the data to connect to the database
     */
    $ftpUserData = $app->db->queryOneRecord("SELECT server_id, username FROM  ftp_user WHERE ftp_user_id = " . $ftpUserId);
    
    $serverId = $app->functions->intval($ftpUserData['server_id']);
    if ($serverId == 0){
        die ("No FTP-Server found!");
    }
    
    $serverData = $app->db->queryOneRecord(
        "SELECT server_name FROM server WHERE server_id = " .$serverId);
    
    $app->uses('getconf');
    $global_config = $app->getconf->get_global_config('sites');
    
    /*
     * We only redirect to the login-form, so there is no need, to check any rights
     */
    if($global_config['webftp_url'] != '') {
            $net2ftp_url = $global_config['webftp_url'];
            $net2ftp_url = str_replace(array('[SERVERNAME]', '[USERNAME]'),array($serverData['server_name'], $ftpUserData['database_name']),$net2ftp_url);
            header('Location: '.$net2ftp_url);
    } else {
            isset($_SERVER['HTTPS'])? $http = 'https' : $http = 'http';
            if($web_config['server_type'] == 'nginx') {
                    header('Location: http://' . $serverData['server_name'] . ':8081/net2ftp');
            } else {
                    header('Location: ' . $http . '://' . $serverData['server_name'] . '/net2ftp');
            }
    }
    
    exit;
    ?>
    

    ==== Adding options in the administration interface ====


    === Modification of the interface : admin/templates/system_config_sites_edit.htm ===

    * modify the field declaration 'webftp_url_txt' to add the Placeholder
    Code:
    40c46
    <                 <input name="webftp_url" id="webftp_url" value="{tmpl_var name='webftp_url'}" size="30" maxlength="255" type="text" class="textInput" />
    ---
    >                 <input name="webftp_url" id="webftp_url" value="{tmpl_var name='webftp_url'}" size="30" maxlength="255" type="text" class="textInput" />&nbsp;{tmpl_var name='webftp_url_note_txt'} <a href="javascript:void(0);" class="addPlaceholder">[SERVERNAME]</a>, <a href="javascript:void(0);" class="addPlaceholder">[USERNAME]</a>
    
    * add on the top of this statement, the check box to activate the link in the interface
    Code:
    38a39,44
    >                 <p class="label">{tmpl_var name='webftp_link_txt'}</p>
    >                 <div class="multiField">
    >                     {tmpl_var name='webftp_link'}
    >                 </div>
    >             </div>
    >             <div class="ctrlHolder">
    
    === Adding label in the language files ===
    * en : /var/www/ispconfig/admin/lib/lang/en_system_config.lng
    Code:
    cp -p /var/www/ispconfig/admin/lib/lang/en_system_config.lng /var/www/ispconfig/admin/lib/lang/en_system_config.lng.DIST
    perl -spi -e 's%\?>%\$wb\["webftp_link_txt"\] = "Link to net2ftp in FTP User list";\n\?>%' /var/www/ispconfig/admin/lib/lang/en_system_config.lng
    perl -spi -e 's%\?>%\$wb\["webftp_url_note_txt"\] = "Placeholder : ";\n\?>%' /var/www/ispconfig/admin/lib/lang/en_system_config.lng
    
    * fr : /var/www/ispconfig/admin/lib/lang/fr_system_config.lng
    Code:
    cp -p /var/www/ispconfig/admin/lib/lang/fr_system_config.lng /var/www/ispconfig/admin/lib/lang/fr_system_config.lng.DIST
    perl -spi -e 's%\?>%\$wb\["webftp_link_txt"\] = "Lien vers net2ftp dans la liste utilisateurs FTP";\n\?>%' /var/www/ispconfig/admin/lib/lang/fr_system_config.lng
    
    === Change controllers form : admin/form/system_config.tform.php ===
    * Add the controller to the check box to enable the url
    Code:
    138a139,144
    >                 'webftp_link' => array (
    >                         'datatype'      => 'VARCHAR',
    >                         'formtype'      => 'CHECKBOX',
    >                         'default'       => 'y',
    >                         'value'         => array(0 => 'n',1 => 'y')
    >                 ),
    
    * Change the regex validator of 'webftp_url'pour accept placeholder
    Code:
    143c149
    <                                                                 'regex' => '/^[0-9a-zA-Z\:\/\-\.]{0,255}$/',
    ---
    >                                                                 'regex' => '/^[0-9a-zA-Z\:\/\-\.\[\]&\?=]{0,255}$/',
    
     
  2. toyinal

    toyinal Member

    I'm able to access net2ftp from within my ispconfig panel following this steps, user's directories are displayed but nothing else works, can't browse the folders, none of the main function on net2ftp activate when I click it. But when I access my ftp server directly from net2ftp.com everything works. I know it's likely my server configuration issue, but I don't know where to begin. Any help will be app.reciated.
    Details

    Ispconfig 3.0.5
    Pureftpd
    Centos 6.5
    net2ftp version 1.0

    Does net2ftp has issues with ipv6?
     

Share This Page