Mass Adding IPv6 Addresses

Discussion in 'Tips/Tricks/Mods' started by sjau, Mar 15, 2012.

  1. sjau

    sjau Local Meanie Moderator

    As there is no way to mass-add ip addresses, I just wrote a little php script to mass-add ipv6 addresses:

    PHP:
    <?php


    // Define /16 Subnet
    define('SUB_',            '2a01:4f8:160:1234::');
    define('START_',        '1008');    // use Hex values
    define('END_',            '100F');    // use Hex values

    // Define Server / Database options
    define('SERVER_ID_',        '1');
    define('CLIENT_ID_',        '0');
    define('IP_TYPE_',            'IPv6');
    define('VIRTUALHOST_',        'y');
    define('VIRTUALHOST_PORT_',    '80,443');

    // ISPConfig
    define('USER_',            'admin');
    define('PASSWD_',        '***');
    define('DOMAIN_',        'https://YOUR_ISPCONFIG_DOMAIN.COM');
    define('START_PAGE_',    DOMAIN_ '/index.php');
    define('LOGIN_PAGE_',    DOMAIN_ '/content.php');
    define('SUBMIT_PAGE_',    DOMAIN_ '/admin/server_ip_edit.php');
    define('PORT_',            '8080');
    define('USERAGENT_',     'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:11.0) Gecko/20100101 Firefox/11.0');
    define('COOKIE_',         '/tmp/ispc_admin_cookie.txt');    // Make sure cookie write path exists... especially on windows



    /**************************************************************************************************************
    *                                                                                                             *
    *                                         HERE BE DRAGONS                                                     *
    *                                                                                                             *
    **************************************************************************************************************/


    // Start Session Prefetching
    $ch curl_init();
    curl_setopt($chCURLOPT_URL,                   START_PAGE_);
    curl_setopt($chCURLOPT_PORT ,                    PORT_);
    curl_setopt($chCURLOPT_SSL_VERIFYPEER,        false);
    curl_setopt($chCURLOPT_SSL_VERIFYHOST,         false);
    curl_setopt($chCURLOPT_USERAGENT,             USERAGENT_);
    curl_setopt($chCURLOPT_COOKIEJAR,             COOKIE_);
    curl_setopt($chCURLOPT_HEADER,                true);
    curl_setopt($chCURLOPT_RETURNTRANSFER,        true);
    curl_setopt($chCURLOPT_FOLLOWLOCATION,        true);
    curl_setopt($chCURLOPT_NOBODY,                false);
    $r curl_exec($ch);


    // Build post data
    $data = array(
        
    'username'        =>    USER_,
        
    'passwort'        =>    PASSWD_,
        
    's_mod'            =>    'login',
        
    's_pg'            =>    'index'
    );


    // Transfer post data into url string
    foreach ($data as $key => $val) {
            
    $tmp urlencode($key) . '=' urlencode($val) . '&';
            
    $qstring .= $tmp;
    }


    // Make login
    curl_setopt($chCURLOPT_URL,                   LOGIN_PAGE_);
    curl_setopt($chCURLOPT_PORT ,                    PORT_);
    curl_setopt($chCURLOPT_SSL_VERIFYPEER,        false);
    curl_setopt($chCURLOPT_SSL_VERIFYHOST,         false);
    curl_setopt($chCURLOPT_USERAGENT,             USERAGENT_);
    curl_setopt($chCURLOPT_COOKIEFILE,            COOKIE_);
    curl_setopt($chCURLOPT_POST,                  true);
    curl_setopt($chCURLOPT_POSTFIELDS,            $qstring);
    curl_setopt($chCURLOPT_REFERER,               START_PAGE_);
    curl_setopt($chCURLOPT_RETURNTRANSFER,        true);
    curl_setopt($chCURLOPT_HEADER,                true);
    curl_setopt($chCURLOPT_FOLLOWLOCATION,        true);
    curl_setopt($chCURLOPT_NOBODY,                false);
    $r curl_exec($ch);


    // Get the PHPSESSID from the cookie
    $filename COOKIE_;
    $handle fopen($filename"r");
    $contents fread($handlefilesize($filename));
    fclose($handle);
    $phpsessid explode'PHPSESSID'$contents);
    define('PHPSESSID_',        trim($phpsessid[1]));


    // Get the ip_edit form to create necessary sessions vars
    curl_setopt($chCURLOPT_URL,                   SUBMIT_PAGE_);
    curl_setopt($chCURLOPT_PORT ,                    PORT_);
    curl_setopt($chCURLOPT_SSL_VERIFYPEER,        false);
    curl_setopt($chCURLOPT_SSL_VERIFYHOST,         false);
    curl_setopt($chCURLOPT_USERAGENT,             USERAGENT_);
    curl_setopt($chCURLOPT_COOKIEFILE,            COOKIE_);
    curl_setopt($chCURLOPT_POST,                  false);
    curl_setopt($chCURLOPT_REFERER,               START_PAGE_);
    curl_setopt($chCURLOPT_RETURNTRANSFER,        true);
    curl_setopt($chCURLOPT_HEADER,                true);
    curl_setopt($chCURLOPT_FOLLOWLOCATION,        true);
    curl_setopt($chCURLOPT_NOBODY,                false);
    $r curl_exec($ch);


    // Loop through the adding addresses
    $i hexdec(START_);
    $j hexdec(END_);
    while (
    $i <= $j) {
        
    $ip dechex($i);
        
    $ip_address SUB_ $ip;

    echo 
    "i: $i  -  j: $j  -  ip: $ip_address<br>";

        
    // Build data array
        
    unset($data);
        
    $data = array(
            
    'server_id'            => SERVER_ID_,
            
    'client_id'            => CLIENT_ID_,
            
    'ip_type'            => IP_TYPE_,
            
    'ip_address'        => $ip_address,
            
    'virtualhost'        => VIRTUALHOST_,
            
    'virtualhost_port'    => VIRTUALHOST_PORT_,
            
    'id'                => '',
            
    'next_tab'            => '',
            
    'phpsessid'            => PHPSESSID_
        
    );

        
    // Transfer post data into url string
        
    unset($qstring);
        foreach (
    $data as $key => $val) {
            
    $tmp urlencode($key) . '=' urlencode($val) . '&';
            
    $qstring .= $tmp;
        }

        
    // Make Query
        
    curl_setopt($chCURLOPT_URL,                SUBMIT_PAGE_);
        
    curl_setopt($chCURLOPT_USERAGENT,            USERAGENT_);
        
    curl_setopt($chCURLOPT_COOKIEFILE,        COOKIE_);
        
    curl_setopt($chCURLOPT_POST,                true);
        
    curl_setopt($chCURLOPT_POSTFIELDS,        $qstring);
        
    curl_setopt($chCURLOPT_REFERER,            START_PAGE_);
        
    curl_setopt($chCURLOPT_RETURNTRANSFER,    true);
        
    curl_setopt($chCURLOPT_HEADER,            true);
        
    curl_setopt($chCURLOPT_FOLLOWLOCATION,    true);
        
    curl_setopt($chCURLOPT_NOBODY,            false);
        
    $r curl_exec($ch);

        
    $i++;
    }


    ?>

    Make sure to add your password, set your domain for ISPConfig, define your subnet and the desired range.

    The script uses curl and write a cookie file to /tmp. So either use it locally on your computer or if you run it from a server, make sure to delete the cookie afterwards.

    It's not an elegant solution and the script also takes it's time to run but it's still faster than adding them by hand. Afterwards you only have to assign them to clients when needed.
     

Share This Page