Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > ISPConfig 3 > Tips/Tricks/Mods

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 15th March 2012, 11:46
sjau sjau is offline
Local Meanie
 
Join Date: Apr 2006
Location: Switzerland
Posts: 1,146
Thanks: 4
Thanked 55 Times in 51 Posts
 
Default Mass Adding IPv6 Addresses

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

PHP Code:
<?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.
__________________
"Common sense is not as common as commonly believed" by sjau

Auto-Install Script for ISPConfig and Horde on a Vanilla Debian Stable

Need more Repos for Ubuntu? Repository Generator
Need more Repos for Debian? Debian Repository Generator
Reply With Quote
The Following User Says Thank You to sjau For This Useful Post:
falko (16th March 2012)
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
Something blocking port 53 stigge2000 Installation/Configuration 4 5th April 2011 14:46
Strato Server - Restoring with SystemImager popper2001 HOWTO-Related Questions 5 28th July 2007 10:18
Creating image with Systemimager cuongtim HOWTO-Related Questions 3 18th November 2006 13:55
Ipv6 on Xen witless1 HOWTO-Related Questions 5 31st July 2006 10:50
Adding IP Addresses radioguy Installation/Configuration 1 15th August 2005 09:07


All times are GMT +2. The time now is 14:24.


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