From 41b1eca7a62d450bc0d2357027a6be6acd51a7a6 Mon Sep 17 00:00:00 2001 From: Joachim Tingvold Date: Wed, 1 Apr 2015 03:49:53 +0200 Subject: Changes... --- fap/README.md | 27 +-- fap/database/create_tables.sql | 17 ++ fap/httpd/OLD - DEPRECATED/# ex2200.template | 226 ++++++++++++++++++++++++++ fap/httpd/OLD - DEPRECATED/# server_http.py | 146 +++++++++++++++++ fap/httpd/OLD - DEPRECATED/# terminal.log | 14 ++ fap/httpd/apache_base_config | 15 ++ fap/httpd/ex2200.template | 226 -------------------------- fap/httpd/server_http.py | 146 ----------------- fap/httpd/terminal.log | 14 -- fap/tools/create_queries/create_queries.php | 62 +++++++ fap/tools/tools_includes/ipcalc_functions.php | 134 +++++++++++++++ 11 files changed, 629 insertions(+), 398 deletions(-) create mode 100644 fap/database/create_tables.sql create mode 100644 fap/httpd/OLD - DEPRECATED/# ex2200.template create mode 100644 fap/httpd/OLD - DEPRECATED/# server_http.py create mode 100644 fap/httpd/OLD - DEPRECATED/# terminal.log create mode 100644 fap/httpd/apache_base_config delete mode 100644 fap/httpd/ex2200.template delete mode 100644 fap/httpd/server_http.py delete mode 100644 fap/httpd/terminal.log create mode 100644 fap/tools/create_queries/create_queries.php create mode 100644 fap/tools/tools_includes/ipcalc_functions.php diff --git a/fap/README.md b/fap/README.md index f41e879..f07a968 100644 --- a/fap/README.md +++ b/fap/README.md @@ -9,24 +9,27 @@ Licensed under the GNU GPL, version 2. See the included COPYING file. ## Usage -Launch the python scripts for fap from tgmanage directory. +### Installation/configuration +* Install apache2, postgresql, php, php-cli, python3, python-psycopg2 +* Configure Postgresql with user + db name "fap", and password to your liking +* Create DB tables from database/create_tables.sql +* Configure Apache, necessary config in fap/httpd/apache_base_config +* Enable mod_rewrite in Apache - "a2enmod rewrite" +* Start/restart Apache -### HTTPD - j@lappie:~/git/tgmanage$ sudo python3 fap/httpd/server_http.py - -Example: httpd/terminal.log - - -### DHCPD - j@lappie:~/git/tgmanage$ sudo python3 fap/dhcpd/server_dhcp.py - -Example: dhcpd/terminal.log +### FAP workflow +* planning.cpp generates switches.txt and patchlist.txt +* "php -f fap/tools/create_queries/create_queries.php" generates SQL queries +* Manually insert queries from create_queries.php into DB +* "php -f fap/tools/generate_distro_config_ae_event-options/generate.php" generates distroconfig into generated_configs/ +* Copy distro config from generated_configs/* to HTTPD (fap/httpd/files/), and load them from the distros (load merge /files/.conf in configure mode) +* Start FAP DHCPD (sudo python3 fap/dhcpd/server_dhcp.py) # TODO * DONE: Support for IPv6 management -* Process multiple HTTP request simultaneously +* DONE: Process multiple HTTP request simultaneously * Support for only pushing JunOS image to switch - no config (for backup switches) * Try/catch on whole ethernet frame in DHCPD * Timestamps on each line in log both from DHCPD and HTTPD diff --git a/fap/database/create_tables.sql b/fap/database/create_tables.sql new file mode 100644 index 0000000..b4aab3f --- /dev/null +++ b/fap/database/create_tables.sql @@ -0,0 +1,17 @@ +CREATE TABLE switches ( + id serial, + hostname character varying(20), + distro_name character varying(100), + distro_phy_port character varying(100), + mgmt_v4_addr character varying(15), + mgmt_v4_cidr smallint, + mgmt_v4_gw character varying(15), + mgmt_v6_cidr smallint, + mgmt_v6_addr character varying(35), + mgmt_v6_gw character varying(35), + mgmt_vlan smallint, + last_config_fetch integer, + current_mac character varying(17), + model character varying(20), + traffic_vlan integer +); diff --git a/fap/httpd/OLD - DEPRECATED/# ex2200.template b/fap/httpd/OLD - DEPRECATED/# ex2200.template new file mode 100644 index 0000000..3adcdf9 --- /dev/null +++ b/fap/httpd/OLD - DEPRECATED/# ex2200.template @@ -0,0 +1,226 @@ +system { + host-name $hostname; + auto-snapshot; + time-zone Europe/Oslo; + authentication-order [ tacplus password ]; + root-authentication { + encrypted-password "$1$v1xWD3zI$OhStP6PnpgIUO3RLtMmIJ/"; + } + name-server { + 1.1.1.1; + 2.2.2.2; + } + login { + user technet{ + uid 2000; + class super-user; + authentication { + encrypted-password "$1$v1xWD3zI$OhStP6PnpgIUO3RLtMmIJ/"; + } + } + } + services { + ssh { + root-login deny; + } + netconf { + ssh; + } + } + syslog { + user * { + any emergency; + } + file messages { + any notice; + authorization info; + } + file interactive-commands { + interactive-commands any; + } + } + ntp { + server 1.2.3.4; + server 2.3.4.5; + } +} + +chassis { + aggregated-devices { + ethernet { + device-count 1; + } + } +} + +interfaces { + interface-range edge-ports { + member-range ge-0/0/0 to ge-0/0/43; + unit 0 { + family ethernet-switching { + port-mode access; + vlan { + members deltagere; + } + } + } + } + interface-range core-ports { + member-range ge-0/0/44 to ge-0/0/47; + ether-options { + 802.3ad ae0; + } + } + ae0 { + description "Til $distro_name $distro_phy_port"; + aggregated-ether-options { + lacp { + active; + } + } + unit 0 { + family ethernet-switching { + port-mode trunk; + vlan { + members [deltagere mgmt]; + } + } + } + } + vlan { + unit $mgmt_vlan { + description "MGMT L3 interface"; + family inet { + filter { + input v4-mgmt; + } + address $mgmt_addr/$mgmt_cidr; + } + family inet6 { + filter { + input v6-mgmt; + } + address $mgmt_v6_addr/$mgmt_v6_cidr; + } + } + } +} +firewall { + family inet { + filter v4-mgmt { + term accept-noc { + from { + source-address { + 0.0.0.0/0; + } + } + then accept; + } + term accept-icmp { + from { + protocol icmp; + } + then { + accept; + } + } + term reject-all { + then { + log; + syslog; + reject; + } + } + } + } + family inet6 { + filter v6-mgmt { + term accept-noc { + from { + source-address { + ::/0; + } + } + then accept; + } + term accept-icmp { + from { + next-header icmp6; + } + then { + accept; + } + } + term reject-all { + then { + log; + syslog; + reject; + } + } + } + } +} + +protocols { + sflow { + sample-rate { + ingress 10000; + egress 10000; + } + collector 91.209.30.12; + interfaces edge-ports; + interfaces core-ports; + } + igmp-snooping { + vlan all { + version 3; + immediate-leave; + } + } + mld-snooping { + vlan all { + version 2; + immediate-leave; + } + } + rstp { + bridge-priority 8k; + interface edge-ports { + edge; + no-root-port; + } + } + lldp { + interface ae0.0 + } +} + +vlans { + deltagere { + vlan-id $traffic_vlan; + } + mgmt { + vlan-id $mgmt_vlan; + l3-interface vlan.$mgmt_vlan; + } +} + +routing-options { + rib inet.0 { + static { + route 0.0.0.0/0 { + next-hop $mgmt_gw; + } + } + } + rib inet6.0 { + static { + route ::/0 { + next-hop $mgmt_v6_gw; + } + } + } +} + + diff --git a/fap/httpd/OLD - DEPRECATED/# server_http.py b/fap/httpd/OLD - DEPRECATED/# server_http.py new file mode 100644 index 0000000..a9ae74c --- /dev/null +++ b/fap/httpd/OLD - DEPRECATED/# server_http.py @@ -0,0 +1,146 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +from http.server import BaseHTTPRequestHandler, HTTPServer +from string import Template +import time +import psycopg2 +import psycopg2.extras +import sys +import os + +def main(): + # + # Settings + # + settings = { + 'db': { + 'user': 'bootstrap', + 'password': 'asdf', + 'dbname': 'bootstrap', + 'host': 'localhost' + }, + 'http': { + 'host': '0.0.0.0', + 'port': 80 + } + } + + # + # Connect to DB + # + try: + connect_params = ("dbname='%s' user='%s' host='%s' password='%s'" % (settings['db']['dbname'], settings['db']['user'], settings['db']['host'], settings['db']['password'])) + conn = psycopg2.connect(connect_params) + cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor) + # cur.execute("""SELECT * from switches""") + # rows = cur.fetchall() + # print ("\nSwitches in DB during server_http.py startup:") + # for row in rows: + # print (" --> %s, connected to %s port %s" % (row['hostname'], row['distro_name'], row['distro_phy_port'])) + + except (psycopg2.DatabaseError, psycopg2.OperationalError) as e: + print ('Error: %s' % e) + sys.exit(1) + + except: + print(sys.exc_info()[0]) + sys.exit(1) + + def template_get(model): + return open('fap/httpd/' + model + '.template').read() + + def template_parse(template_src, hostname): + cur.execute("SELECT * FROM switches WHERE hostname = '%s'" % hostname) + if(cur.rowcount == 1): + row = cur.fetchall()[0] + d={ + 'hostname': row['hostname'], + 'distro_name': row['distro_name'], + 'distro_phy_port': row['distro_phy_port'], + 'mgmt_addr': row['mgmt_addr'], + 'mgmt_cidr': row['mgmt_cidr'], + 'mgmt_gw': row['mgmt_gw'], + 'mgmt_vlan': row['mgmt_vlan'], + 'traffic_vlan': row['traffic_vlan'], + 'mgmt_v6_addr': row['mgmt_v6_addr'], + 'mgmt_v6_cidr': row['mgmt_v6_cidr'], + 'mgmt_v6_gw': row['mgmt_v6_gw'] + } + cur.execute("UPDATE switches SET last_config_fetch = '%s' WHERE hostname = '%s'" % (str(time.time()).split('.')[0], hostname)) # updated DB with last config fetch + conn.commit() + return Template(template_src).safe_substitute(d) + else: + return False + + class httpd(BaseHTTPRequestHandler): + def do_GET(self): + print('[%s] [%s] Incoming HTTP GET URI:%s ' % (self.client_address[0], time.asctime(), self.path)) + + # Client asks for the config file + if '/tg-edge/' in self.path: + hostname = self.path.split('/tg-edge/')[1] + if len(hostname) > 0: + print('[%s] --> Hostname "%s" accepted, fetching info from DB' % (self.client_address[0], hostname)) + template_parsed = template_parse(template_get('ex2200'), hostname) + if template_parsed: + print('[%s] --> Template successfully populated' % self.client_address[0]) + print('[%s] --> Sending response to client' % self.client_address[0]) + self.send_response(200) + self.send_header("Content-type", "text/plain") + self.end_headers() + self.wfile.write(bytes(template_parsed, "utf-8")) + print('[%s] --> Success - %s bytes sent to client' % (self.client_address[0], len(template_parsed))) + else: + print('[%s] --> Error - could not find hostname "%s" in DB' % (self.client_address[0], hostname)) + else: + print('[%s] --> Rejected due to missing hostname' % self.client_address[0]) + + # Client asks for a file download - most likely a JunOS file + elif '/files/' in self.path: + # It seems that "http.server" escapes nastiness from the URL - ("/files/../../../root_file" => "/files/root_file") + requested_file = self.path.split('/files/')[1] + files_dir = 'fap/httpd/files/' + print('[%s] --> File request for "%s" in "%s"' % (self.client_address[0], requested_file, files_dir)) + if os.path.isfile(files_dir + requested_file): + print('[%s] --> File found' % self.client_address[0]) + try: + f = open(files_dir + requested_file) + self.send_response(200) + self.send_header('Content-type', 'application/x-gzip') # correct content type for tar.gz + self.end_headers() + print('[%s] --> File transfer started' % self.client_address[0]) + f = open(files_dir + requested_file, 'rb') + self.wfile.write(f.read()) + f.close() + print('[%s] --> File transfer completed' % self.client_address[0]) + return + except IOError: + self.send_error(404,'File Not Found: %s' % self.path) + print('[%s] --> ERROR 404 - File not found' % self.client_address[0]) + pass + except: + print('[%s] --> Generic error during file reading' % self.client_address[0]) + pass + else: + print('[%s] --> File request rejected due to nonexisting file' % self.client_address[0]) + else: + print('[%s] --> rejected due to bad URI' % self.client_address[0]) + # silence stderr from BaseHTTPRequestHandler + # source: http://stackoverflow.com/questions/3389305/how-to-silent-quiet-httpserver-and-basichttprequesthandlers-stderr-output + def log_message(self, format, *args): + return + + httpd_instance = HTTPServer((settings['http']['host'], settings['http']['port']), httpd) + print("\n[%s] Server Starts - %s:%s" % (time.asctime(), settings['http']['host'], settings['http']['port'])) + + try: + httpd_instance.serve_forever() + except KeyboardInterrupt: + pass + + httpd_instance.server_close() + print("\n\n[%s] HTTP Server stopped\n" % time.asctime()) + +if __name__ == "__main__": + main() diff --git a/fap/httpd/OLD - DEPRECATED/# terminal.log b/fap/httpd/OLD - DEPRECATED/# terminal.log new file mode 100644 index 0000000..bedb829 --- /dev/null +++ b/fap/httpd/OLD - DEPRECATED/# terminal.log @@ -0,0 +1,14 @@ +j@lappie:~/git/tgmanage$ sudo python3 fap/httpd/server_http.py + +[Thu Feb 19 23:15:45 2015] Server Starts - 0.0.0.0:80 +[10.0.200.101] [Fri Feb 20 00:18:25 2015] Incoming HTTP GET URI://tg-edge/e-00-1 +[10.0.200.101] --> Hostname "e-00-1" accepted, fetching info from DB +[10.0.200.101] --> Template successfully populated +[10.0.200.101] --> Sending response to client +[10.0.200.101] --> Success - 1437 bytes sent to client +[10.0.200.101] [Fri Feb 20 00:18:26 2015] Incoming HTTP GET URI://files/jinstall-ex-2200-12.3R6.6-domestic-signed.tgz +[10.0.200.101] --> File request for "jinstall-ex-2200-12.3R6.6-domestic-signed.tgz" in "fap/httpd/files/" +[10.0.200.101] --> File found +[10.0.200.101] --> File transfer started +[10.0.200.101] --> File transfer completed + diff --git a/fap/httpd/apache_base_config b/fap/httpd/apache_base_config new file mode 100644 index 0000000..dc17635 --- /dev/null +++ b/fap/httpd/apache_base_config @@ -0,0 +1,15 @@ +root@copernicus:/home/lol# cat /etc/apache2/sites-enabled/000-default.conf | grep -v "#" + + ServerAdmin webmaster@localhost + DocumentRoot /srv/fap/httpd/httpd_root/ + ErrorLog ${APACHE_LOG_DIR}/error.log + CustomLog ${APACHE_LOG_DIR}/access.log combined + + +root@copernicus:/home/lol# cat /etc/apache2/apache2.conf +[...] + + Options Indexes FollowSymLinks + AllowOverride All + Require all granted + diff --git a/fap/httpd/ex2200.template b/fap/httpd/ex2200.template deleted file mode 100644 index 3adcdf9..0000000 --- a/fap/httpd/ex2200.template +++ /dev/null @@ -1,226 +0,0 @@ -system { - host-name $hostname; - auto-snapshot; - time-zone Europe/Oslo; - authentication-order [ tacplus password ]; - root-authentication { - encrypted-password "$1$v1xWD3zI$OhStP6PnpgIUO3RLtMmIJ/"; - } - name-server { - 1.1.1.1; - 2.2.2.2; - } - login { - user technet{ - uid 2000; - class super-user; - authentication { - encrypted-password "$1$v1xWD3zI$OhStP6PnpgIUO3RLtMmIJ/"; - } - } - } - services { - ssh { - root-login deny; - } - netconf { - ssh; - } - } - syslog { - user * { - any emergency; - } - file messages { - any notice; - authorization info; - } - file interactive-commands { - interactive-commands any; - } - } - ntp { - server 1.2.3.4; - server 2.3.4.5; - } -} - -chassis { - aggregated-devices { - ethernet { - device-count 1; - } - } -} - -interfaces { - interface-range edge-ports { - member-range ge-0/0/0 to ge-0/0/43; - unit 0 { - family ethernet-switching { - port-mode access; - vlan { - members deltagere; - } - } - } - } - interface-range core-ports { - member-range ge-0/0/44 to ge-0/0/47; - ether-options { - 802.3ad ae0; - } - } - ae0 { - description "Til $distro_name $distro_phy_port"; - aggregated-ether-options { - lacp { - active; - } - } - unit 0 { - family ethernet-switching { - port-mode trunk; - vlan { - members [deltagere mgmt]; - } - } - } - } - vlan { - unit $mgmt_vlan { - description "MGMT L3 interface"; - family inet { - filter { - input v4-mgmt; - } - address $mgmt_addr/$mgmt_cidr; - } - family inet6 { - filter { - input v6-mgmt; - } - address $mgmt_v6_addr/$mgmt_v6_cidr; - } - } - } -} -firewall { - family inet { - filter v4-mgmt { - term accept-noc { - from { - source-address { - 0.0.0.0/0; - } - } - then accept; - } - term accept-icmp { - from { - protocol icmp; - } - then { - accept; - } - } - term reject-all { - then { - log; - syslog; - reject; - } - } - } - } - family inet6 { - filter v6-mgmt { - term accept-noc { - from { - source-address { - ::/0; - } - } - then accept; - } - term accept-icmp { - from { - next-header icmp6; - } - then { - accept; - } - } - term reject-all { - then { - log; - syslog; - reject; - } - } - } - } -} - -protocols { - sflow { - sample-rate { - ingress 10000; - egress 10000; - } - collector 91.209.30.12; - interfaces edge-ports; - interfaces core-ports; - } - igmp-snooping { - vlan all { - version 3; - immediate-leave; - } - } - mld-snooping { - vlan all { - version 2; - immediate-leave; - } - } - rstp { - bridge-priority 8k; - interface edge-ports { - edge; - no-root-port; - } - } - lldp { - interface ae0.0 - } -} - -vlans { - deltagere { - vlan-id $traffic_vlan; - } - mgmt { - vlan-id $mgmt_vlan; - l3-interface vlan.$mgmt_vlan; - } -} - -routing-options { - rib inet.0 { - static { - route 0.0.0.0/0 { - next-hop $mgmt_gw; - } - } - } - rib inet6.0 { - static { - route ::/0 { - next-hop $mgmt_v6_gw; - } - } - } -} - - diff --git a/fap/httpd/server_http.py b/fap/httpd/server_http.py deleted file mode 100644 index a9ae74c..0000000 --- a/fap/httpd/server_http.py +++ /dev/null @@ -1,146 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -from http.server import BaseHTTPRequestHandler, HTTPServer -from string import Template -import time -import psycopg2 -import psycopg2.extras -import sys -import os - -def main(): - # - # Settings - # - settings = { - 'db': { - 'user': 'bootstrap', - 'password': 'asdf', - 'dbname': 'bootstrap', - 'host': 'localhost' - }, - 'http': { - 'host': '0.0.0.0', - 'port': 80 - } - } - - # - # Connect to DB - # - try: - connect_params = ("dbname='%s' user='%s' host='%s' password='%s'" % (settings['db']['dbname'], settings['db']['user'], settings['db']['host'], settings['db']['password'])) - conn = psycopg2.connect(connect_params) - cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor) - # cur.execute("""SELECT * from switches""") - # rows = cur.fetchall() - # print ("\nSwitches in DB during server_http.py startup:") - # for row in rows: - # print (" --> %s, connected to %s port %s" % (row['hostname'], row['distro_name'], row['distro_phy_port'])) - - except (psycopg2.DatabaseError, psycopg2.OperationalError) as e: - print ('Error: %s' % e) - sys.exit(1) - - except: - print(sys.exc_info()[0]) - sys.exit(1) - - def template_get(model): - return open('fap/httpd/' + model + '.template').read() - - def template_parse(template_src, hostname): - cur.execute("SELECT * FROM switches WHERE hostname = '%s'" % hostname) - if(cur.rowcount == 1): - row = cur.fetchall()[0] - d={ - 'hostname': row['hostname'], - 'distro_name': row['distro_name'], - 'distro_phy_port': row['distro_phy_port'], - 'mgmt_addr': row['mgmt_addr'], - 'mgmt_cidr': row['mgmt_cidr'], - 'mgmt_gw': row['mgmt_gw'], - 'mgmt_vlan': row['mgmt_vlan'], - 'traffic_vlan': row['traffic_vlan'], - 'mgmt_v6_addr': row['mgmt_v6_addr'], - 'mgmt_v6_cidr': row['mgmt_v6_cidr'], - 'mgmt_v6_gw': row['mgmt_v6_gw'] - } - cur.execute("UPDATE switches SET last_config_fetch = '%s' WHERE hostname = '%s'" % (str(time.time()).split('.')[0], hostname)) # updated DB with last config fetch - conn.commit() - return Template(template_src).safe_substitute(d) - else: - return False - - class httpd(BaseHTTPRequestHandler): - def do_GET(self): - print('[%s] [%s] Incoming HTTP GET URI:%s ' % (self.client_address[0], time.asctime(), self.path)) - - # Client asks for the config file - if '/tg-edge/' in self.path: - hostname = self.path.split('/tg-edge/')[1] - if len(hostname) > 0: - print('[%s] --> Hostname "%s" accepted, fetching info from DB' % (self.client_address[0], hostname)) - template_parsed = template_parse(template_get('ex2200'), hostname) - if template_parsed: - print('[%s] --> Template successfully populated' % self.client_address[0]) - print('[%s] --> Sending response to client' % self.client_address[0]) - self.send_response(200) - self.send_header("Content-type", "text/plain") - self.end_headers() - self.wfile.write(bytes(template_parsed, "utf-8")) - print('[%s] --> Success - %s bytes sent to client' % (self.client_address[0], len(template_parsed))) - else: - print('[%s] --> Error - could not find hostname "%s" in DB' % (self.client_address[0], hostname)) - else: - print('[%s] --> Rejected due to missing hostname' % self.client_address[0]) - - # Client asks for a file download - most likely a JunOS file - elif '/files/' in self.path: - # It seems that "http.server" escapes nastiness from the URL - ("/files/../../../root_file" => "/files/root_file") - requested_file = self.path.split('/files/')[1] - files_dir = 'fap/httpd/files/' - print('[%s] --> File request for "%s" in "%s"' % (self.client_address[0], requested_file, files_dir)) - if os.path.isfile(files_dir + requested_file): - print('[%s] --> File found' % self.client_address[0]) - try: - f = open(files_dir + requested_file) - self.send_response(200) - self.send_header('Content-type', 'application/x-gzip') # correct content type for tar.gz - self.end_headers() - print('[%s] --> File transfer started' % self.client_address[0]) - f = open(files_dir + requested_file, 'rb') - self.wfile.write(f.read()) - f.close() - print('[%s] --> File transfer completed' % self.client_address[0]) - return - except IOError: - self.send_error(404,'File Not Found: %s' % self.path) - print('[%s] --> ERROR 404 - File not found' % self.client_address[0]) - pass - except: - print('[%s] --> Generic error during file reading' % self.client_address[0]) - pass - else: - print('[%s] --> File request rejected due to nonexisting file' % self.client_address[0]) - else: - print('[%s] --> rejected due to bad URI' % self.client_address[0]) - # silence stderr from BaseHTTPRequestHandler - # source: http://stackoverflow.com/questions/3389305/how-to-silent-quiet-httpserver-and-basichttprequesthandlers-stderr-output - def log_message(self, format, *args): - return - - httpd_instance = HTTPServer((settings['http']['host'], settings['http']['port']), httpd) - print("\n[%s] Server Starts - %s:%s" % (time.asctime(), settings['http']['host'], settings['http']['port'])) - - try: - httpd_instance.serve_forever() - except KeyboardInterrupt: - pass - - httpd_instance.server_close() - print("\n\n[%s] HTTP Server stopped\n" % time.asctime()) - -if __name__ == "__main__": - main() diff --git a/fap/httpd/terminal.log b/fap/httpd/terminal.log deleted file mode 100644 index bedb829..0000000 --- a/fap/httpd/terminal.log +++ /dev/null @@ -1,14 +0,0 @@ -j@lappie:~/git/tgmanage$ sudo python3 fap/httpd/server_http.py - -[Thu Feb 19 23:15:45 2015] Server Starts - 0.0.0.0:80 -[10.0.200.101] [Fri Feb 20 00:18:25 2015] Incoming HTTP GET URI://tg-edge/e-00-1 -[10.0.200.101] --> Hostname "e-00-1" accepted, fetching info from DB -[10.0.200.101] --> Template successfully populated -[10.0.200.101] --> Sending response to client -[10.0.200.101] --> Success - 1437 bytes sent to client -[10.0.200.101] [Fri Feb 20 00:18:26 2015] Incoming HTTP GET URI://files/jinstall-ex-2200-12.3R6.6-domestic-signed.tgz -[10.0.200.101] --> File request for "jinstall-ex-2200-12.3R6.6-domestic-signed.tgz" in "fap/httpd/files/" -[10.0.200.101] --> File found -[10.0.200.101] --> File transfer started -[10.0.200.101] --> File transfer completed - diff --git a/fap/tools/create_queries/create_queries.php b/fap/tools/create_queries/create_queries.php new file mode 100644 index 0000000..d579370 --- /dev/null +++ b/fap/tools/create_queries/create_queries.php @@ -0,0 +1,62 @@ + $pieces[0], + 'distro_name' => 'rs1.' . $pieces[1], # prefix with "rs." so we get "rs1.distro0" syntax + 'distro_phy_port' => $pieces[2] + ); + } + + /* + Assign to logical and usable names in array + */ + foreach($switches as $lines){ + $pieces = explode(' ', trim($lines)); + $dataset[$pieces[0]]['mgmt_v4_addr'] = explode('/', $pieces[3])[0]; + $dataset[$pieces[0]]['mgmt_v4_cidr'] = explode('/', $pieces[3])[1]; + $dataset[$pieces[0]]['mgmt_v4_gw'] = net_to_gw($pieces[3]); + $dataset[$pieces[0]]['mgmt_v6_addr'] = explode('/', $pieces[4])[0]; + $dataset[$pieces[0]]['mgmt_v6_cidr'] = explode('/', $pieces[4])[1]; + $dataset[$pieces[0]]['mgmt_v6_gw'] = net_to_gw($pieces[4]); + $dataset[$pieces[0]]['traffic_vlan'] = $pieces[5]; + $dataset[$pieces[0]]['mgmt_vlan'] = '666'; + } + + /* + Prints the query rows + */ + $sql_query = ''; + foreach($dataset as $k => $v){ + $columns = implode(', ', array_keys($v)); + $values = "'" . implode("', '", array_values($v)) . "'"; + $sql_query .= 'INSERT INTO switches (' . $columns . ') VALUES (' . $values . ');' . "\n"; + } + + echo $sql_query; +?> diff --git a/fap/tools/tools_includes/ipcalc_functions.php b/fap/tools/tools_includes/ipcalc_functions.php new file mode 100644 index 0000000..e848ef1 --- /dev/null +++ b/fap/tools/tools_includes/ipcalc_functions.php @@ -0,0 +1,134 @@ + 255 ) { + $newValue = $newValue - 256; + $carry = 1; + } else { + $carry = 0; + } + array_unshift($result,$newValue); + } + return $result; + } + + + /* Useful Functions */ + function _cdr2Bin ($cdrin,$len=4){ + if ( $len > 4 || $cdrin > 32 ) { // Are we ipv6? + return str_pad(str_pad("", $cdrin, "1"), 128, "0"); + } else { + return str_pad(str_pad("", $cdrin, "1"), 32, "0"); + } + } + + + function _bin2Cdr ($binin){ + return strlen(rtrim($binin,"0")); + } + + + function _cdr2Char ($cdrin,$len=4){ + $hex = _bin2Hex(_cdr2Bin($cdrin,$len)); + return _hex2Char($hex); + } + + + function _char2Cdr ($char){ + $bin = _hex2Bin(_char2Hex($char)); + return _bin2Cdr($bin); + } + + + function _hex2Char($hex){ + return pack('H*',$hex); + } + + + function _char2Hex($char){ + $hex = unpack('H*',$char); + return array_pop($hex); + } + + + function _hex2Bin($hex){ + $bin=''; + for($i=0;$i=0;$i-=4) + $hex.=dechex(bindec(substr($bin,$i,4))); + return strrev($hex); + } + + /* + Converts a v4/v6 subnet to the first usable IP + */ + function net_to_gw($net){ + $maxSubNets = '2048'; // Stop memory leak from invalid input or large ranges + $charHost = inet_pton(strtok($net, '/')); + $charMask = _cdr2Char(strtok('/'),strlen($charHost)); + $charHostMask = substr(_cdr2Char(127),-strlen($charHost)); + $charNet = $charHost & $charMask; // Supernet network address + $charHostMin = $charNet | ~$charHostMask; + return inet_ntop($charHostMin); + } + + + + + + + + +/* + + $maxSubNets = '2048'; // Stop memory leak from invalid input or large ranges + $superNet = '2a02:ed02:180a::13/64'; + if (ereg('/',$superNet)){ //if cidr type mask + $charHost = inet_pton(strtok($superNet, '/')); + $charMask = _cdr2Char(strtok('/'),strlen($charHost)); + } + + $charHostMask = substr(_cdr2Char(127),-strlen($charHost)); + $charNet = $charHost & $charMask; // Supernet network address + $charHostMin = $charNet | ~$charHostMask; + echo 'Første brukbare adresse i ' . $superNet . ': '; + echo inet_ntop($charHostMin); +*/ + +?> -- cgit v1.2.3