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 30th May 2009, 06:16
Croydon Croydon is offline
ISPConfig Developer
 
Join Date: Jul 2007
Location: Koblenz, Germany
Posts: 756
Thanks: 16
Thanked 215 Times in 166 Posts
 
Default MySQL remote access limitation

Hi again,

this time i wanted to extend the way a client can set up remote access to his databases so he can limit remote access to one or more ip addresses.

I made the following changes to ispc.


1. Update the ispc database
Code:
ALTER TABLE `web_database` ADD `test` TEXT NOT NULL AFTER `remote_ips` ;
2. Add a new validation class (interface/lib/classes/validate_database.inc.php)
PHP Code:
<?php

class validate_database {
    
    
/*
        Validator function to check if a given list of ips is ok.
    */
    
function valid_ip_list($field_name$field_value$validator) {
        global 
$app;
        
    if(
$_POST["remote_access"] == "y") {
        if(
trim($field_value) == "") return;
        
        
$values split(","$field_value);
        foreach(
$values as $cur_value) {
            
$cur_value trim($cur_value);
            
            
$valid true;
            if(
preg_match("/^[0-9]{1,3}(\.)[0-9]{1,3}(\.)[0-9]{1,3}(\.)[0-9]{1,3}$/"$cur_value)) {
                
$groups explode("."$cur_value);
                foreach(
$groups as $group){
                  if(
$group<OR $group>255)
                  
$valid=false;
                }
            } else {
                
$valid false;
            }
            
            if(
$valid == false) {
                
$errmsg $validator['errmsg'];
                if(isset(
$app->tform->wordbook[$errmsg])) {
                    return 
$app->tform->wordbook[$errmsg]."<br>\r\n";
                } else {
                    return 
$errmsg."<br>\r\n";
                }
            }
        }
    }
  }    
    
}
3. change tform file (interface/web/sites/form/database.tform.php)
PHP Code:
        'active' => array (
            
'datatype'    => 'VARCHAR',
            
'formtype'    => 'CHECKBOX',
            
'default'    => 'y',
            
'value'        => array(=> 'n',=> 'y')
        ),
    
### insert this
    
'remote_ips' => array (
      
'datatype'  => 'TEXT',
      
'formtype'  => 'TEXT',
      
'validators'  => array (  => array (  'type' => 'CUSTOM',
                                              
'class' => 'validate_database',
                                              
'function' => 'valid_ip_list',
                                              
'errmsg' => 'database_remote_error_ips'),
                             ),
      
'default' => '',
      
'value'   => '',
      
'width'   => '60'
    
),
    
### end insert
    ##################################
    # ENDE Datatable fields
    ##################################
    


4. change lang file (interface/web/sites/lib/lang/en_database.lng)
PHP Code:
$wb["remote_access_txt"] = 'Remote Access';
###insert this
$wb["remote_ips_txt"] = 'Remote Access IPs (separate by , and leave blank for <i>any</i>)';
$wb["database_remote_error_ips"] = 'At least one of the entered ip addresses is invalid.';
###end insert
$wb["client_txt"] = 'Client'

5. alter template file (interface/web/sites/templates/database_edit.htm)
insert this
HTML Code:
      <div class="ctrlHolder">
        <label for="remote_ips">{tmpl_var name='remote_ips_txt'}</label>
        <input name="remote_ips" id="remote_ips" value="{tmpl_var name='remote_ips'}" size="60" type="text" class="textInput formLengthHalf" />
      </div>
directly after

HTML Code:
      <div class="ctrlHolder">
        <p class="label">{tmpl_var name='remote_access_txt'}</p>
          <div class="multiField">
            {tmpl_var name='remote_access'}
          </div>
      </div>

6. apply the attached patch to the "server/plugins-available/mysql_clientdb_plugin.inc.php" or use the attached and modified version.
patching is done (at least on debian linux) with
Code:
patch /path/to/ispc/server/plugins-available/mysql_clientdb_plugin.inc.php /path/to/patchfile/mysql_clientdb_plugin.inc.php.patch

Now you are done (hopefully).
When enabling remote access to a database you can now limit the ip addresses that can access the database by entering a comma separated list of ips into the new field.
Attached Files
File Type: zip patch.zip (1.7 KB, 217 views)
File Type: zip modified.zip (3.0 KB, 209 views)

Last edited by Croydon; 30th May 2009 at 06:17. Reason: Information added
Reply With Quote
The Following 2 Users Say Thank You to Croydon For This Useful Post:
falko (31st May 2009), till (31st May 2009)
Sponsored Links
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
Management/system config/settings & /server/settings not working!! dactor Installation/Configuration 9 6th February 2008 09:11
ERROR: The PHP binary coming with ISPConfig does not work properly on your system! qvindesland Installation/Configuration 22 21st May 2007 16:05
Support Ticket and MySQL Remote Access Question lewis_saint Installation/Configuration 3 20th May 2007 23:56
Can't Remote Access mysql 4.1 dedibox Installation/Configuration 2 24th August 2006 10:32
Questions in regards to ISP-Server Setup - Ubuntu 5.10 "Breezy Badger" rbrantley HOWTO-Related Questions 16 10th April 2006 18:26


All times are GMT +2. The time now is 13:47.


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