[DOMAINID] Prefix

Discussion in 'Tips/Tricks/Mods' started by oilyflutesalad, Dec 28, 2009.

  1. oilyflutesalad

    oilyflutesalad New Member

    I wanted to include the ID of the parent domain in FTP accounts, so after a bit of firebug magic and a quick look through relevant files, I've modified the source to add the keyword DOMAINID.

    Example Usage:
    Code:
    c[CLIENTID]d[DOMAINID]_
    Will result in something like "c3d12_default" if an FTP account with name "default" was added. Without the domain ID prefix, a client would get a duplicate error if they tried to create a "default" FTP account for each domain, even though it would make sense to be able to create them. Now they can have default accounts for every domain in their account.

    Open tools.inc.php for editing. I'm using Ubuntu Server 9.10. The path to your ISPConfig directory may be different on your distro.
    Code:
    vi /var/www/ispconfig/sites/tools.inc.php
    Go down to the replacePrefix function. Add ,'DOMAINID' to the $keywordlist array, then add a new case under the two existing ones:
    Code:
    [...]
            // Array containing keys to search
            $keywordlist=array('CLIENTNAME','CLIENTID','DOMAINID');
    [...]
                                    case 'CLIENTID':
                                            $name=str_replace('['.$keyword.']', getClientID($dataRecord),$name);
                                    break;
                                    case 'DOMAINID':
                                            $name=str_replace('['.$keyword.']', $dataRecord['parent_domain_id'],$name);
                                    break;
    [...]
    
    And that's it! Save the file and you're done. To change your prefixes, go into ISPConfig then on the System tab, click "Interface Config" in the system menu.
     
  2. moglia

    moglia New Member

    I will try test and implement.

    Thanks 4 contrib.
     
  3. BorderAmigos

    BorderAmigos New Member

    FEATURE REQUEST !!! Can this be included in the next release of ISPConfig 3. It's useful and it would be nice not to have to re-do the edit after updating. Thanks.
     
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    If you like to request a feature, plaese post it as feature request in the bugtracker and vote for it there.
     
  5. xxfog

    xxfog Member

    Hi oily..

    did you already set this into bugtracker.ispconfig.org?

    I would like to vote for it ther!

    If so, please send the direkt link in this post.
    If not - will you? ;-)
     
  6. moglia

    moglia New Member

    Complement

    [DOMAINNAME] is interessant too.

    Prefix and Sufix implementation to create ftp account for example.

    USERNAME_[DOMAINNAME] or USERNAME@[DOMAINNAME]

    Examples:
    [email protected]
    user_domain.com
     
  7. radim_h

    radim_h Member HowtoForge Supporter

    yes [DOMAINNAME] will be great
     
  8. ppnl.com

    ppnl.com New Member

    To adapt ispconfig and use DOMAINNAME, DOMAINID, DOMAINNAMESHORT as prefix for database in order to allow moving databases between clients!

    My prefix for database name and database user is:
    [DOMAINNAMESHORT][DOMAINID]_

    Here DOMAINNAMESHORT will be the first 5 characters of the domain name, and the DOMAINID will be added to make it unique, however not a full list of databases with ONLY numbers!

    e.g. for domain.com the database prefix will be domai12_

    And because it's based on DOMAIN it allows to move to another client.

    INSTRUCTIONS (on own risk)

    To support DOMAINID, DOMAINNAME and DOMAINNAMESHORT as prefix modfiy the file /usr/local/ispconfig/interface/web/sites/tools.inc.php and modify replacePrefix and add also a new function getDomainName :

    Code:
    function replacePrefix($name, $dataRecord) {
      // No input -> no possible output -> go out!
      if ($name=="") return "";
      
      // Array containing keys to search
      $keywordlist=array('CLIENTNAME','CLIENTID','DOMAINID','DOMAINNAME','DOMAINNAMESHORT');
      
      // Try to match the key within the string
      foreach ($keywordlist as $keyword) {
        if (substr_count($name, '['.$keyword.']') > 0) {
          switch ($keyword) {
            case 'CLIENTNAME':
              $name=str_replace('['.$keyword.']', getClientName($dataRecord),$name);
            break;
            case 'CLIENTID':
              $name=str_replace('['.$keyword.']', getClientID($dataRecord),$name);
            break;
            case 'DOMAINID':
              $name=str_replace('['.$keyword.']', $dataRecord['parent_domain_id'],$name);
            break;
            case 'DOMAINNAME':
              $name=str_replace('['.$keyword.']', getDomainName($dataRecord['parent_domain_id']),$name);
            break;
            case 'DOMAINNAMESHORT':
              $name=str_replace('['.$keyword.']', substr(getDomainName($dataRecord['parent_domain_id']),0,5),$name);
            break;
          }
        }
      }
      return $name;
    }
    
    function getDomainName($domain_id) {
      global $app;
      $tmp = $app->db->queryOneRecord("SELECT domain FROM web_domain WHERE domain_id = " . $domain_id);
    
      return $tmp['domain'];
    }

    To show the dropdown with domains in the database edit form, modify web/sites/templates/database_edit.htm and add between client_group_id and type around line 39:
    (copied from ftp_user_edit.htm)

    Code:
    <div class="ctrlHolder">
        <label for="parent_domain_id">{tmpl_var name='parent_domain_id_txt'}</label>
        <select name="parent_domain_id" id="parent_domain_id" class="selectInput">
                                           {tmpl_var name='parent_domain_id'}
        </select>
      </div>
    To define the domain dropdown in the form modify /usr/local/ispconfig/interface/web/sites/form/database.tform.php and add between server_id and type around line 72:
    (copied from ftp_user.tform.php)
    Code:
    'parent_domain_id' => array (
                            'datatype'      => 'INTEGER',
                            'formtype'      => 'SELECT',
                            'default'       => '',
                            'datasource'    => array (      'type'  => 'SQL', 'querystring' => "SELECT domain_id,domain FROM web_domain WHERE type = 'vhost' AND {AUTHSQL} ORDER BY domain",'keyfield'=> 'domain_id','valuefield'=> 'domain'
                                                     ),
                            'value'         => ''
    ),
    Add to the table web_database the field parent_domain_id after server_id with INT unsigned default 0.
     

Share This Page