diff --git a/.htaccess b/.htaccess
new file mode 100644
index 000000000..23367653a
--- /dev/null
+++ b/.htaccess
@@ -0,0 +1,34 @@
+
+
+RewriteEngine on
+
+# change rewrite base if not in root
+RewriteBase /
+
+# passthroughs
+RewriteRule ^(api)($|/) - [L]
+RewriteRule ^index.php$ - [L]
+RewriteRule ^(css|js|site|test)/.*$ - [L]
+RewriteRule site/login/captcha/captchashow.php - [L]
+
+# redirect errors
+ErrorDocument 400 /error/400/
+ErrorDocument 401 /error/401/
+ErrorDocument 403 /error/403/
+ErrorDocument 404 /error/404/
+ErrorDocument 500 /error/500/
+
+# IE login dashboard fix
+RewriteRule ^login/dashboard/$ dashboard/ [R]
+RewriteRule ^logout/dashboard/$ dashboard/ [R]
+# search override
+RewriteRule ^tools/search/(.*)/(.*)/(.*)/(.*)$ index.php?page=tools§ion=search&addresses=$1&subnets=$2&vlans=$3&ip=$4 [L]
+
+# Rewrites
+RewriteRule ^(.*)/(.*)/(.*)/(.*)/(.*)/$ index.php?page=$1§ion=$2&subnetId=$3&sPage=$4&ipaddrid=$5 [L]
+RewriteRule ^(.*)/(.*)/(.*)/(.*)/$ index.php?page=$1§ion=$2&subnetId=$3&sPage=$4 [L]
+RewriteRule ^(.*)/(.*)/(.*)/$ index.php?page=$1§ion=$2&subnetId=$3 [L]
+RewriteRule ^(.*)/(.*)/$ index.php?page=$1§ion=$2 [L]
+RewriteRule ^(.*)/$ index.php?page=$1 [L]
+
+
\ No newline at end of file
diff --git a/INSTALL.txt b/INSTALL.txt
new file mode 100755
index 000000000..4549f985d
--- /dev/null
+++ b/INSTALL.txt
@@ -0,0 +1 @@
+http://phpipam.net/phpipam-installation-guide/
\ No newline at end of file
diff --git a/README b/README
new file mode 100755
index 000000000..178f4e34f
--- /dev/null
+++ b/README
@@ -0,0 +1,76 @@
+Description
+===========
+phpipam is an open-source web IP address management application. Its goal is to provide light and simple |P address management application.
+It is ajax-based using jQuery libraries, it uses php scripts and javascript and some HTML5/CSS3 features, so some modern browser is preferred to be able to display javascript quickly and correctly...
+
+Features and tools:
+- Section / Subnet separation
+- Subnet nesting
+- IPv4/IPv6 support
+- Subnet ICMP/telnet scanning and automatic status updates
+- Displays free range and number of clients
+- Subnet statistics
+- User management
+- AD/LDAP/OpenLDAP authentication support
+- E-Mail notification with IP details
+- Import IP addresses from XLS / CSV file
+- Export IP database to XLS file
+- IPv4/IPv6 calculator
+- Search IP database
+- IP request module
+- Custom IP address fields
+- and much more...
+
+What it does not do:
+- Updates DNS server
+
+License
+=======
+phpipam is released under the GPL v3 license, see misc/gpl-3.0.txt.
+
+Requirements
+============
+- Apache2 web server with php and mod_rewrite support (set "AllowOverride all" in vhost config)
+- Mysql server (5.1+)
+- PHP version 5.2+ with following modules (On windows php 5.3 is required!)
+ + + mysqli : Adds support for the improved mySQL libraries
+ + + session : Adds persistent session support
+ + + gmp : Adds support for dev-libs/gmp (GNU MP library) -> to calculate IPv6 networks
+ + + ldap : Adds LDAP support (Lightweight Directory Access Protocol)
+ + + json : Adds supports for JSON data-interexchange format
+ + + SimpleXML : Adds SimpleXML support for parsin XML files
+ + + gettext : Add support for gettext translations
+- PHP PEAR support (dev-php/pear)
+
+Install
+=======
+- http://phpipam.net/phpipam-installation-guide/
+
+Update
+=======
+- see UPDATE file for details
+
+Demo page
+============
+http://demo.phpipam.net
+
+Default user
+============
+Admin / ipamadmin
+
+Changelog
+=========
+See misc/CHANGELOG
+
+Roadmap
+=========
+See misc/Roadmap
+
+Contact
+=======
+miha.petkovsek@gmail.com
+
+special thank also to Hosterdam team (http://www.hosterdam.com) for VPS server
+that is used for development of phpIPAM and for demo site.
+
+And also to all users that filed a bug report / feature report and helped with feature testing!
\ No newline at end of file
diff --git a/UPDATE b/UPDATE
new file mode 100755
index 000000000..f84465f51
--- /dev/null
+++ b/UPDATE
@@ -0,0 +1,50 @@
+#
+# phpipam update instructions
+#
+
+phpIPAM supports upgrading only to 2 older release, for example only version >= 0.9 can be upgraded to 1.1.
+
+
+It is recommended that you backup the old phpipam database before you upgrade to new version (change username and pass to ones in config.php):
+ /usr/bin/mysqldump -u ipv6 -pipv6admin phpipam > /phpipam__migration_backup.db
+
+Backup phpipam files:
+ mv /phpipam /phpipam-
+
+
+#
+# !!! important !!!
+#
+
+since version 0.7 phpipam uses mod_rewrite to handle url's. Please make sure you meet the following requirements:
+ 1.) Apache2 with mod_rewrite support
+ 2.) "AllowOverride all" set in vhost config for mod_rewrite to work
+
+In case your URL for phpipam is not root please set the following variables (example for /phpipam/):
+ 3.) Set BASE in config.php to /phpipam/
+ 4.) RewriteBase /phpipam/ in .htaccess
+
+
+#
+# a) Automatic upgrade procedure
+#
+
+ 1.) Extract files form tar package:
+ tar -xvf phpipam-1.1.tar
+ 2.) Set database connection settings in config.php;
+ 3.) Open phpipam in browser and update database;
+
+
+
+#
+# b) Manual upgrade procedure
+#
+ 1.) Extract files form tar package:
+ tar -xvf phpipam-1.1.tar
+ 2.) Set database connection settings in config.php;
+ 3.) Manual database structure update
+ Update database structure by importing database scheme for your version.
+ If you have version 1.0 and want to upgrade to 1.1 use all update files form UPDATE-v1.0.sql on;
+ mysql -u root -p phpipam < db/UPDATE-v1.01.sql
+ mysql -u root -p phpipam < db/UPDATE-v1.02.sql
+ ...
\ No newline at end of file
diff --git a/api/.htaccess b/api/.htaccess
new file mode 100644
index 000000000..b07049873
--- /dev/null
+++ b/api/.htaccess
@@ -0,0 +1,5 @@
+# controller rewrites
+RewriteRule ^(.*)/(.*)/(.*)/(.*)/$ ?app_id=$1&controller=$2&id=$3&id2=$4 [L,QSA]
+RewriteRule ^(.*)/(.*)/(.*)/$ ?app_id=$1&controller=$2&id=$3 [L,QSA]
+RewriteRule ^(.*)/(.*)/$ ?app_id=$1&controller=$2 [L,QSA]
+RewriteRule ^(.*)/$ ?app_id=$1 [L,QSA]
\ No newline at end of file
diff --git a/api/index.php b/api/index.php
new file mode 100644
index 000000000..54f182dc5
--- /dev/null
+++ b/api/index.php
@@ -0,0 +1,11 @@
+
\ No newline at end of file
diff --git a/api/v1/.htaccess b/api/v1/.htaccess
new file mode 100755
index 000000000..7b76dc0e1
--- /dev/null
+++ b/api/v1/.htaccess
@@ -0,0 +1,6 @@
+# redirect errors
+ErrorDocument 400 error/400/
+ErrorDocument 401 error/401/
+ErrorDocument 403 error/403/
+ErrorDocument 404 error/404/
+ErrorDocument 500 error/500/
\ No newline at end of file
diff --git a/api/v1/README b/api/v1/README
new file mode 100755
index 000000000..aa9bcc5a3
--- /dev/null
+++ b/api/v1/README
@@ -0,0 +1,159 @@
+phpIPAM API documentation v 0.1
+===============================
+
+phpIPAM provides API server for providing data to clients. It is a webapp and can be called
+via HTTP requests by providing appropriate GET parameters that define controller, actions and
+additional parameters required for each controller, such as id, name, etc.
+
+Response is in JSON format with success true or false and provided error message or object.
+
+You can find examples of client API calls in folder api/_examples/.
+
+Client based request values must be encrypted with app_id and app_code. You first have to
+enable API module in phpipam administration and create an app_id and app_code, that will be
+used for external app with appropriate permissions.
+
+
+Required php extensions for API server:
+ mcrypt
+ curl
+
+
+Available controllers:
+--------------------------------
+ sections
+ subnets
+ addresses
+ vlans
+ vrfs
+ //users
+ //groups
+
+Available actions:
+------------------
+ read
+ create
+ update
+ delete
+
+
+Output format for subnets and IP addresses
+------------------------------------------
+ You can manually specify output format for subnets and IP addresses:
+
+ format=decimal returns in decimal form (default)
+ format=ip returns in IP address
+
+
+
+
+
+Per-controller options and examples
+===================================
+
+= Sections
+----------
+ = read
+ all returns all sections
+ id returns section by id
+ name returns section by name
+
+ example: ?controller=sections&action=read&id=1
+
+ = create
+ not available
+
+ = update
+ not available
+
+ = delete
+ id (mandatory) id of the section to be deleted
+ subnets will delete also belonging subnets (default = true)
+ addresses will delete also belonging ips (default = true)
+
+ example: ?controller=sections&action=delete&id=1
+
+
+= Subnets
+---------
+ = read
+ all returns all subnet
+ id returns subnet by id
+ sectionId returns all subnets in specified sectionId
+ format returns subnet in specified format
+
+ example: ?controller=subnets&action=read&id=1
+
+ = create
+ not available
+
+ = update
+ not available
+
+ = delete
+ id (mandatory) subnet id
+ addresses will delete also belonging ips (default = true)
+
+ example: ?controller=addresses&action=delete&id=1
+
+
+= IP addresses
+--------------
+ = read
+ subnetId returns all ip addresses in subnet
+ id returns ip address details by id
+ format returns ip in specified format
+
+ example: ?controller=addresses&action=read&id=1
+
+ = create
+ not available
+
+ = update
+ not available
+
+ = delete
+ id (mandatory)
+
+ example: ?controller=addresses&action=delete&id=1
+
+
+= Vlans
+-------
+ = read
+ all returns all vlans
+ id returns vlan details by id
+ subnets return also ids of all attached subnets
+
+ example: ?controller=vlans&action=read&id=1
+
+ = create
+ not available
+
+ = update
+ not available
+
+ = delete
+ id (mandatory)
+
+ example: ?controller=vlans&action=delete&id=1
+
+= VRFs
+-------
+ = read
+ all returns all vrfs
+ id returns vrf details by id
+ subnets return also ids of all attached subnets
+
+ example: ?controller=vrfs&action=read&id=1
+
+ = create
+ not available
+
+ = update
+ not available
+
+ = delete
+ id (mandatory)
+
+ example: ?controller=vrfs&action=delete&id=1
\ No newline at end of file
diff --git a/api/v1/_examples/addresses/deleteAddress.php b/api/v1/_examples/addresses/deleteAddress.php
new file mode 100755
index 000000000..3e9641314
--- /dev/null
+++ b/api/v1/_examples/addresses/deleteAddress.php
@@ -0,0 +1,35 @@
+sendRequest($req);
+
+ print "
";
+ print_r($response);
+}
+catch( Exception $e ) {
+ //catch any exceptions and report the problem
+ print "Error: ".$e->getMessage();
+}
+
+?>
\ No newline at end of file
diff --git a/api/v1/_examples/addresses/getAddressesById.php b/api/v1/_examples/addresses/getAddressesById.php
new file mode 100755
index 000000000..2e1c21d5b
--- /dev/null
+++ b/api/v1/_examples/addresses/getAddressesById.php
@@ -0,0 +1,38 @@
+sendRequest($req);
+
+ print "
";
+ print_r($response);
+}
+catch( Exception $e ) {
+ //catch any exceptions and report the problem
+ print "Error: ".$e->getMessage();
+}
+
+?>
\ No newline at end of file
diff --git a/api/v1/_examples/addresses/getAllAddressesInSubnet.php b/api/v1/_examples/addresses/getAllAddressesInSubnet.php
new file mode 100755
index 000000000..f1fd9ed78
--- /dev/null
+++ b/api/v1/_examples/addresses/getAllAddressesInSubnet.php
@@ -0,0 +1,38 @@
+sendRequest($req);
+
+ print "
";
+ print_r($response);
+}
+catch( Exception $e ) {
+ //catch any exceptions and report the problem
+ print "Error: ".$e->getMessage();
+}
+
+?>
\ No newline at end of file
diff --git a/api/v1/_examples/apiClient.php b/api/v1/_examples/apiClient.php
new file mode 100755
index 000000000..4c5aaaebc
--- /dev/null
+++ b/api/v1/_examples/apiClient.php
@@ -0,0 +1,71 @@
+ in which format to return data
+
+ //construct an ApiCaller object, taking an
+ //APP ID, APP KEY and API URL parameter
+ public function __construct($app_id, $app_key, $api_url, $api_resp="array")
+ {
+ $this->_app_id = $app_id;
+ $this->_app_key = $app_key;
+ $this->_api_url = $api_url;
+ $this->_api_resp = $api_resp;
+ }
+
+ //send the request to the API server
+ //also encrypts the request, then checks
+ //if the results are valid
+ public function sendRequest($request_params)
+ {
+ //encrypt the request parameters
+ $enc_request = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->_app_key, json_encode($request_params), MCRYPT_MODE_ECB));
+
+ //create the params array, which will
+ //be the POST parameters
+ $params = array();
+ $params['enc_request'] = $enc_request;
+ $params['app_id'] = $this->_app_id;
+
+ //initialize and setup the curl handler
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $this->_api_url);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($ch, CURLOPT_POST, count($params));
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
+
+ //execute the request
+ $result = curl_exec($ch);
+
+ //json_decode the result
+ $result = @json_decode($result, true);
+
+ //check if we're able to json_decode the result correctly
+ if( $result == false || isset($result['success']) == false ) {
+ throw new Exception('Request was not correct');
+ }
+
+ //if there was an error in the request, throw an exception
+ if( $result['success'] == false ) {
+ throw new Exception($result['errormsg']);
+ }
+
+ //if everything went great, return the data
+ if($this->_api_resp == "json") {
+ return json_encode($result['data']);
+ } else {
+ return ($result['data']);
+ }
+ }
+}
+
+?>
\ No newline at end of file
diff --git a/api/v1/_examples/apiConfig.php b/api/v1/_examples/apiConfig.php
new file mode 100755
index 000000000..ed1d680fa
--- /dev/null
+++ b/api/v1/_examples/apiConfig.php
@@ -0,0 +1,17 @@
+
\ No newline at end of file
diff --git a/api/v1/_examples/sections/deleteSection.php b/api/v1/_examples/sections/deleteSection.php
new file mode 100755
index 000000000..71e6577d4
--- /dev/null
+++ b/api/v1/_examples/sections/deleteSection.php
@@ -0,0 +1,39 @@
+sendRequest($req);
+
+ print "
";
+ print_r($response);
+}
+catch( Exception $e ) {
+ //catch any exceptions and report the problem
+ print "Error: ".$e->getMessage();
+}
+
+?>
\ No newline at end of file
diff --git a/api/v1/_examples/sections/getAllSections.php b/api/v1/_examples/sections/getAllSections.php
new file mode 100755
index 000000000..bcb0b3f3f
--- /dev/null
+++ b/api/v1/_examples/sections/getAllSections.php
@@ -0,0 +1,37 @@
+sendRequest($req);
+
+ print "
";
+ print_r($response);
+}
+catch( Exception $e ) {
+ //catch any exceptions and report the problem
+ print "Error: ".$e->getMessage();
+}
+
+?>
\ No newline at end of file
diff --git a/api/v1/_examples/sections/getSectionById.php b/api/v1/_examples/sections/getSectionById.php
new file mode 100755
index 000000000..ef28e6e8e
--- /dev/null
+++ b/api/v1/_examples/sections/getSectionById.php
@@ -0,0 +1,39 @@
+sendRequest($req);
+
+ print "
";
+ print_r($response);
+}
+catch( Exception $e ) {
+ //catch any exceptions and report the problem
+ print "
";
+ print_r($e->getMessage());
+}
+
+?>
\ No newline at end of file
diff --git a/api/v1/_examples/subnets/deleteSubnet.php b/api/v1/_examples/subnets/deleteSubnet.php
new file mode 100755
index 000000000..2377babe1
--- /dev/null
+++ b/api/v1/_examples/subnets/deleteSubnet.php
@@ -0,0 +1,36 @@
+sendRequest($req);
+
+ print "
";
+ print_r($response);
+}
+catch( Exception $e ) {
+ //catch any exceptions and report the problem
+ print $e->getMessage();
+}
+
+?>
\ No newline at end of file
diff --git a/api/v1/_examples/subnets/getAllSubnetsInSection.php b/api/v1/_examples/subnets/getAllSubnetsInSection.php
new file mode 100755
index 000000000..f6d113626
--- /dev/null
+++ b/api/v1/_examples/subnets/getAllSubnetsInSection.php
@@ -0,0 +1,38 @@
+sendRequest($req);
+
+ print "
";
+ print_r($response);
+}
+catch( Exception $e ) {
+ //catch any exceptions and report the problem
+ print "Error: ".$e->getMessage();
+}
+
+?>
\ No newline at end of file
diff --git a/api/v1/_examples/subnets/getSubnetById.php b/api/v1/_examples/subnets/getSubnetById.php
new file mode 100755
index 000000000..226dbfab0
--- /dev/null
+++ b/api/v1/_examples/subnets/getSubnetById.php
@@ -0,0 +1,39 @@
+sendRequest($req);
+
+ print "
";
+ print_r($response);
+}
+catch( Exception $e ) {
+ //catch any exceptions and report the problem
+ print "Error: ".$e->getMessage();
+}
+
+?>
\ No newline at end of file
diff --git a/api/v1/_examples/vlans/deleteSubnet.php b/api/v1/_examples/vlans/deleteSubnet.php
new file mode 100755
index 000000000..2377babe1
--- /dev/null
+++ b/api/v1/_examples/vlans/deleteSubnet.php
@@ -0,0 +1,36 @@
+sendRequest($req);
+
+ print "
";
+ print_r($response);
+}
+catch( Exception $e ) {
+ //catch any exceptions and report the problem
+ print $e->getMessage();
+}
+
+?>
\ No newline at end of file
diff --git a/api/v1/_examples/vlans/getVlanById.php b/api/v1/_examples/vlans/getVlanById.php
new file mode 100755
index 000000000..a91880d92
--- /dev/null
+++ b/api/v1/_examples/vlans/getVlanById.php
@@ -0,0 +1,40 @@
+sendRequest($req);
+
+ print "
";
+ print_r($response);
+}
+catch( Exception $e ) {
+ //catch any exceptions and report the problem
+ print "Error: ".$e->getMessage();
+}
+
+?>
\ No newline at end of file
diff --git a/api/v1/controllers/Addresses.php b/api/v1/controllers/Addresses.php
new file mode 100755
index 000000000..b45b8f5eb
--- /dev/null
+++ b/api/v1/controllers/Addresses.php
@@ -0,0 +1,66 @@
+_params = $params;
+ }
+
+ /**
+ * read addresses
+ */
+ public function readAddresses()
+ {
+ # init section class
+ $address = new Address ();
+
+ # set method
+ if(isset($this->_params['format'])) { $address->format = $this->_params['format']; }
+
+ # get all ips in subnet?
+ if($this->_params['subnetId']) { $address->subnetId = $this->_params['subnetId']; }
+ # get ip by Id
+ elseif($this->_params['id']) { $address->id = $this->_params['id']; }
+ # false
+ else { }
+
+ # fetch results
+ $res = $address->readAddress();
+ # return result
+ return $res;
+ }
+
+
+ /**
+ * delete addresses
+ */
+ public function deleteAddresses()
+ {
+ # init section class
+ $address = new Address ();
+ # set Id
+ if($this->_params['id']) { $address->id = $this->_params['id']; }
+
+ # fetch results
+ $res = $address->deleteAddress();
+ # return result
+ return $res;
+ }
+
+}
+
+?>
\ No newline at end of file
diff --git a/api/v1/controllers/Sections.php b/api/v1/controllers/Sections.php
new file mode 100755
index 000000000..d30816974
--- /dev/null
+++ b/api/v1/controllers/Sections.php
@@ -0,0 +1,101 @@
+_params = $params;
+ }
+
+
+ /**
+ * create new section
+ */
+ public function createSections()
+ {
+ /* not yet implemented */
+ throw new Exception('Action not yet implemented');
+ }
+
+
+ /**
+ * read sections
+ */
+ public function readSections()
+ {
+ //init section class
+ $section = new Section();
+
+ //get all sections?
+ if($this->_params['all']) { $section->all = true; }
+ //get section by name
+ elseif($this->_params['name']) { $section->name = $this->_params['name']; }
+ //get section by ID
+ else { $section->id = $this->_params['id']; }
+
+ //fetch results
+ $res = $section->readSection();
+ //return section(s) in array format
+ return $res;
+ }
+
+
+ /**
+ * update existing section
+ */
+ public function updateSections()
+ {
+ /* not yet implemented */
+ throw new Exception('Action not yet implemented');
+ }
+
+
+ /**
+ * delete section
+ */
+ public function deleteSections()
+ {
+ //init section class
+ $section = new Section();
+ //required parameters
+ $section->id = $this->_params['id'];
+
+ //delete also IPs and subnets?
+ if(isset($this->_params['subnets'])) {
+ if($this->_params['subnets'] == false) { $section->subnets = false; }
+ else { $section->subnets = true; }
+ } else {
+ { $section->subnets = true; }
+ }
+ //delete also addresses?
+ if($section->subnets == true) {
+ if(isset($this->_params['addresses'])) {
+ if($this->_params['addresses'] == false) { $section->addresses = false; }
+ else { $section->addresses = true; }
+ } else {
+ { $section->addresses = true; }
+ }
+ }
+
+ //delete section
+ $res = $section->deleteSection();
+ //return result
+ return $res;
+ }
+}
+
+?>
\ No newline at end of file
diff --git a/api/v1/controllers/Subnets.php b/api/v1/controllers/Subnets.php
new file mode 100755
index 000000000..213a64338
--- /dev/null
+++ b/api/v1/controllers/Subnets.php
@@ -0,0 +1,102 @@
+_params = $params;
+
+ //ip address format, can be decimal or ip
+ if(!$this->_params['format']) { $this->_params['format'] = "decimal"; }
+ //verify IP address format
+ if(!($this->_params['format']=="decimal" || $this->_params['format']== "ip")) {
+ throw new Exception('Invalid format');
+ }
+ }
+
+
+ /**
+ * create subnet
+ */
+ public function createSubnets()
+ {
+ /* not yet implemented */
+ throw new Exception('Action not yet implemented');
+ }
+
+
+ /**
+ * read subnets
+ */
+ public function readSubnets()
+ {
+ //init subnet class
+ $subnet = new Subnet();
+
+ //set IP address format
+ $subnet->format = $this->_params['format'];
+
+ //get all subnets
+ if($this->_params['all']) { $subnet->all = true; }
+ //get all subnets in subnet
+ elseif($this->_params['sectionId']) { $subnet->sectionId = $this->_params['sectionId']; }
+ //get subnet by ID
+ else { $subnet->id = $this->_params['id']; }
+
+ //fetch results
+ $res = $subnet->readSubnet();
+
+ //return subnet(s) in array format
+ return $res;
+ }
+
+
+ /**
+ * update existing subnet
+ */
+ public function updateSubnets()
+ {
+ /* not yet implemented */
+ throw new Exception('Action not yet implemented');
+ }
+
+
+ /**
+ * delete subnet
+ */
+ public function deleteSubnets()
+ {
+ //init subnet class
+ $subnet = new Subnet();
+
+ //provide id
+ $subnet->id = $this->_params['id'];
+ //delete also IPs?
+ if(isset($this->_params['addresses'])) {
+ if($this->_params['addresses'] == false) { $subnet->addresses = false; }
+ else { $subnet->addresses = true; }
+ } else {
+ { $subnet->addresses = true; }
+ }
+ //fetch results
+ $res = $subnet->deleteSubnet();
+
+ //return subnet(s) in array format
+ return $res;
+ }
+}
+
+?>
\ No newline at end of file
diff --git a/api/v1/controllers/Vlans.php b/api/v1/controllers/Vlans.php
new file mode 100755
index 000000000..605d67f2e
--- /dev/null
+++ b/api/v1/controllers/Vlans.php
@@ -0,0 +1,86 @@
+_params = $params;
+ }
+
+
+ /**
+ * create vlan
+ */
+ public function createVlans()
+ {
+ /* not yet implemented */
+ throw new Exception('Action not yet implemented');
+ }
+
+
+ /**
+ * read vlans
+ */
+ public function readVlans()
+ {
+ //init Vlan class
+ $vlan = new Vlan();
+
+ //get also ids of belonging subnets?
+ if($this->_params['subnets']) { $vlan->subnets = true; }
+
+ //get all vlans
+ if($this->_params['all']) { $vlan->all = true; }
+ //get vlan by ID
+ else { $vlan->id = $this->_params['id']; }
+
+ //fetch results
+ $res = $vlan->readVlan();
+
+ //return Vlan(s) in array format
+ return $res;
+ }
+
+
+ /**
+ * update existing Vlan
+ */
+ public function updateVlans()
+ {
+ /* not yet implemented */
+ throw new Exception('Action not yet implemented');
+ }
+
+
+ /**
+ * delete Vlan
+ */
+ public function deleteVlans()
+ {
+ //init Vlan class
+ $vlan = new Vlan();
+
+ //provide id
+ $vlan->id = $this->_params['id'];
+
+ //fetch results
+ $res = $vlan->deleteVlan();
+
+ //return Vlan(s) in array format
+ return $res;
+ }
+}
+
+?>
\ No newline at end of file
diff --git a/api/v1/controllers/Vrfs.php b/api/v1/controllers/Vrfs.php
new file mode 100755
index 000000000..3b9c6c56e
--- /dev/null
+++ b/api/v1/controllers/Vrfs.php
@@ -0,0 +1,86 @@
+_params = $params;
+ }
+
+
+ /**
+ * create Vrf
+ */
+ public function createVrfs()
+ {
+ /* not yet implemented */
+ throw new Exception('Action not yet implemented');
+ }
+
+
+ /**
+ * read Vrfs
+ */
+ public function readVrfs()
+ {
+ //init Vrf class
+ $vrf = new Vrf();
+
+ //get also ids of belonging subnets?
+ if($this->_params['subnets']) { $vrf->subnets = true; }
+
+ //get all Vrfs
+ if($this->_params['all']) { $vrf->all = true; }
+ //get Vrf by ID
+ else { $vrf->id = $this->_params['id']; }
+
+ //fetch results
+ $res = $vrf->readVrf();
+
+ //return Vrf(s) in array format
+ return $res;
+ }
+
+
+ /**
+ * update existing Vrf
+ */
+ public function updateVrfs()
+ {
+ /* not yet implemented */
+ throw new Exception('Action not yet implemented');
+ }
+
+
+ /**
+ * delete Vrf
+ */
+ public function deleteVrfs()
+ {
+ //init Vrf class
+ $vrf = new Vrf();
+
+ //provide id
+ $vrf->id = $this->_params['id'];
+
+ //fetch results
+ $res = $vrf->deleteVrf();
+
+ //return Vrf(s) in array format
+ return $res;
+ }
+}
+
+?>
\ No newline at end of file
diff --git a/api/v1/functions/dbfunctions.php b/api/v1/functions/dbfunctions.php
new file mode 100644
index 000000000..d26b07be8
--- /dev/null
+++ b/api/v1/functions/dbfunctions.php
@@ -0,0 +1,218 @@
+error:".$e->getMessage().""; }
+ return false;
+ }
+
+ if(!isset($e))
+ $this->set_charset("utf8");
+
+
+ # change back reporting for exception throwing to scripts
+ //mysqli_report(MYSQLI_REPORT_ERROR);
+ }
+
+
+ /**
+ * execute given query
+ *
+ */
+ public function executeQuery( $query, $lastId = false )
+ {
+ # execute query
+ $result = parent::query( $query );
+ $this->lastSqlId = $this->insert_id;
+
+ # if it failes throw new exception
+ if ( mysqli_error( $this ) ) {
+ throw new exception( mysqli_error( $this ), mysqli_errno( $this ) );
+ }
+ else {
+ # return lastId if requested
+ if($lastId) { return $this->lastSqlId; }
+ else { return true; }
+ }
+ }
+
+
+ /**
+ * get only 1 row
+ *
+ */
+ function getRow ( $query )
+ {
+ /* get result */
+ if ($result = parent::query($query)) {
+ $resp = $result->fetch_row();
+ }
+ else {
+ throw new exception( mysqli_error( $this ), mysqli_errno( $this ) );
+ }
+ /* return result */
+ return $resp;
+ }
+
+
+
+ /**
+ * get array of results
+ *
+ * returns multi-dimensional array
+ * first dimension is number
+ * from second on the values
+ *
+ * if nothing is provided use assocciative results
+ *
+ */
+ function getArray( $query , $assoc = true )
+ {
+ /* execute query */
+ $result = parent::query($query);
+
+ /* if it failes throw new exception */
+ if(mysqli_error($this)) {
+ throw new exception(mysqli_error($this), mysqli_errno($this));
+ }
+
+ /**
+ * fetch array of all access responses
+ * either assoc or num, based on input
+ *
+ */
+ if ($assoc == true) {
+ while($row = $result->fetch_array(MYSQLI_ASSOC)) {
+ $fields[] = $row;
+ }
+ }
+ else {
+ while($row = $result->fetch_array(MYSQLI_NUM)) {
+ $fields[] = $row;
+ }
+ }
+
+ /* return result array */
+ if(isset($fields)) {
+ return($fields);
+ }
+ else {
+ $fields = array();
+ return $fields;
+ }
+ }
+
+
+
+ /**
+ * get array of multiple results
+ *
+ * returns multi-dimensional array
+ * first dimension is number
+ * from second on the values
+ *
+ * if nothing is provided use assocciative results
+ *
+ */
+ function getMultipleResults( $query )
+ {
+ /* execute query */
+ $result = parent::multi_query($query);
+
+ /**
+ * get results to array
+ * first save it, than get each row from result and store it to active[]
+ */
+ do {
+ $results = parent::store_result();
+
+ /* save each to array (only first field) */
+ while ( $row = $results->fetch_row() ) {
+ $rows[] = $row[0];
+ }
+ $results->free();
+ }
+ while( parent::next_result() );
+
+ /* return result array of rows */
+ return($rows);
+ }
+
+
+ /**
+ * Execute multiple querries!
+ *
+ */
+ function executeMultipleQuerries( $query, $lastId = false )
+ {
+ # execute querries
+ //$result = parent::multi_query($query);
+
+ if ($result = parent::multi_query($query)) {
+ do {
+ /* store first result set */
+ if ($result = parent::store_result()) {
+ $result->free();
+ }
+ } while (parent::next_result());
+ }
+
+ # save lastid
+ $this->lastSqlId = $this->insert_id;
+
+ # if it failes throw new exception
+ if ( mysqli_error( $this ) ) {
+ throw new exception( mysqli_error( $this ), mysqli_errno( $this ) );
+ }
+ else {
+ if($lastId) { return $this->lastSqlId; }
+ else { return true; }
+ }
+ }
+
+
+ /**
+ * Select database
+ *
+ */
+ function selectDatabase( $database )
+ {
+ /* execute querries */
+ $result = parent::select_db($database);
+
+ /* if it failes throw new exception */
+ if ( mysqli_error( $this ) ) {
+ throw new exception( mysqli_error( $this ), mysqli_errno( $this ) );
+ }
+ else {
+ return true;
+ }
+ }
+}
+
+?>
\ No newline at end of file
diff --git a/api/v1/functions/functions-admin.php b/api/v1/functions/functions-admin.php
new file mode 100644
index 000000000..e76c8149e
--- /dev/null
+++ b/api/v1/functions/functions-admin.php
@@ -0,0 +1,2661 @@
+getArray( $query ); }
+ catch (Exception $e) {
+ $error = $e->getMessage();
+ die("
"._('Error').": $error
");
+ }
+
+ # user already exists
+ if (sizeof($details) != 0) { $errors[] = _("User")." ".$userModDetails['username']." "._("already exists!"); }
+ }
+ # return errors
+ return($errors);
+}
+
+
+/**
+ * Delete user by ID
+ */
+function deleteUserById($id, $name = "")
+{
+ global $database;
+
+ $query = 'delete from `users` where `id` = "'. $id .'";'; # set query, open db connection and fetch results */
+
+ /* execute */
+ try { $database->executeQuery( $query ); }
+ catch (Exception $e) { $error = $e->getMessage(); }
+
+ # ok
+ if(!isset($error)) {
+ updateLogTable ('User '. $name .' deleted ok', 'User '. $name .' deleted ok', 1); # write success log
+ return true;
+ }
+ # problem
+ else {
+ print "