From dff222fbec7e95fa19ae822141a58d5ca46d233d Mon Sep 17 00:00:00 2001 From: Jonas Lindstad Date: Tue, 17 Mar 2015 21:30:23 +0100 Subject: =?UTF-8?q?foobar=20apache+PHP=20funker=20n=C3=A5..?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fap/README.md | 3 +- fap/database/README.md | 43 +++---- fap/httpd/README.md | 26 ++++ fap/httpd/ex2200.template | 29 +---- fap/httpd/files/.gitignore | 3 + fap/httpd/httpd_root/.htaccess | 3 + fap/httpd/httpd_root/ex2200.template | 226 +++++++++++++++++++++++++++++++++++ fap/httpd/httpd_root/x.php | 52 ++++++++ fap/httpd/server_http.py | 5 +- 9 files changed, 338 insertions(+), 52 deletions(-) create mode 100644 fap/httpd/README.md create mode 100644 fap/httpd/files/.gitignore create mode 100644 fap/httpd/httpd_root/.htaccess create mode 100644 fap/httpd/httpd_root/ex2200.template create mode 100644 fap/httpd/httpd_root/x.php diff --git a/fap/README.md b/fap/README.md index af91c1b..f41e879 100644 --- a/fap/README.md +++ b/fap/README.md @@ -25,7 +25,8 @@ Example: dhcpd/terminal.log # TODO -* Support for IPv6 management (in progress) +* DONE: Support for IPv6 management +* 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/README.md b/fap/database/README.md index e49ab91..c4cfde7 100644 --- a/fap/database/README.md +++ b/fap/database/README.md @@ -27,11 +27,12 @@ bootstrap=> \d switches mgmt_gw | character varying(15) | not null mgmt_vlan | smallint | not null last_config_fetch | integer | - current_mac | character varying(17) | default NULL::character varying + current_mac | character varying(17) | model | character varying(20) | - ztp_addr | character varying(15) | - ztp_cidr | smallint | - ztp_gw | character varying(15) | + traffic_vlan | integer | + mgmt_v6_cidr | smallint | + mgmt_v6_addr | character varying(35) | + mgmt_v6_gw | character varying(35) | Indexes: "switches_pkey" PRIMARY KEY, btree (id) ``` @@ -39,19 +40,19 @@ Indexes: **Sample content in DB** ``` -bootstrap=> select * from switches; - id | hostname | distro_name | distro_phy_port | mgmt_addr | mgmt_cidr | mgmt_gw | mgmt_vlan | last_config_fetch | current_mac | model | ztp_addr | ztp_cidr | ztp_gw | traffic_vlan -----+----------+-------------+-----------------+-----------+-----------+----------+-----------+-------------------+-------------------+-------+----------+----------+--------+-------------- - 23 | e-00-2 | rs1.sector0 | ge-0/0/2 | 10.0.0.12 | 24 | 10.0.0.1 | 666 | | | | | | | 102 - 25 | e-00-4 | rs1.sector0 | ge-0/0/4 | 10.0.0.14 | 24 | 10.0.0.1 | 666 | | | | | | | 104 - 27 | e-00-6 | rs1.sector0 | ge-0/0/6 | 10.0.0.16 | 24 | 10.0.0.1 | 666 | | | | | | | 106 - 26 | e-00-5 | rs1.sector0 | ge-0/0/5 | 10.0.0.15 | 24 | 10.0.0.1 | 666 | 1426539826 | 44:f4:77:69:5e:c1 | | | | | 105 - 24 | e-00-3 | rs1.sector0 | ge-0/0/3 | 10.0.0.13 | 24 | 10.0.0.1 | 666 | 1426535091 | 44:f4:77:69:49:81 | | | | | 103 - 22 | e-00-1 | rs1.sector0 | ge-0/0/1 | 10.0.0.11 | 24 | 10.0.0.1 | 666 | 1426535243 | 44:f4:77:68:f7:c1 | | | | | 101 - 30 | e-00-9 | rs1.sector0 | ge-0/0/9 | 10.0.0.19 | 24 | 10.0.0.1 | 666 | 1426539974 | 44:f4:77:68:b5:01 | | | | | 109 - 21 | e-00-0 | rs1.sector0 | ge-0/0/0 | 10.0.0.10 | 24 | 10.0.0.1 | 666 | 1426540122 | 44:f4:77:69:4c:c1 | | | | | 100 - 28 | e-00-7 | rs1.sector0 | ge-0/0/7 | 10.0.0.17 | 24 | 10.0.0.1 | 666 | 1426540272 | 44:f4:77:69:22:41 | | | | | 107 - 29 | e-00-8 | rs1.sector0 | ge-0/0/8 | 10.0.0.18 | 24 | 10.0.0.1 | 666 | 1426540272 | 44:f4:77:69:4f:c1 | | | | | 108 +bootstrap=> select * from switches order by hostname; + id | hostname | distro_name | distro_phy_port | mgmt_addr | mgmt_cidr | mgmt_gw | mgmt_vlan | last_config_fetch | current_mac | model | traffic_vlan | mgmt_v6_cidr | mgmt_v6_addr | mgmt_v6_gw +----+----------+-------------+-----------------+-----------+-----------+----------+-----------+-------------------+-------------------+-------+--------------+--------------+---------------------+------------------- + 21 | e-00-0 | rs1.sector0 | ge-0/0/0 | 10.0.0.10 | 24 | 10.0.0.1 | 666 | 1426608997 | 44:f4:77:69:51:41 | | 100 | 64 | 2a02:ed02:0666::100 | 2a02:ed02:0666::1 + 22 | e-00-1 | rs1.sector0 | ge-0/0/1 | 10.0.0.11 | 24 | 10.0.0.1 | 666 | 1426607722 | 44:f4:77:68:f7:c1 | | 101 | 64 | 2a02:ed02:0666::101 | 2a02:ed02:0666::1 + 23 | e-00-2 | rs1.sector0 | ge-0/0/2 | 10.0.0.12 | 24 | 10.0.0.1 | 666 | | | | 102 | 64 | 2a02:ed02:0666::102 | 2a02:ed02:0666::1 + 24 | e-00-3 | rs1.sector0 | ge-0/0/3 | 10.0.0.13 | 24 | 10.0.0.1 | 666 | 1426606900 | 44:f4:77:69:49:81 | | 103 | 64 | 2a02:ed02:0666::103 | 2a02:ed02:0666::1 + 25 | e-00-4 | rs1.sector0 | ge-0/0/4 | 10.0.0.14 | 24 | 10.0.0.1 | 666 | | | | 104 | 64 | 2a02:ed02:0666::104 | 2a02:ed02:0666::1 + 26 | e-00-5 | rs1.sector0 | ge-0/0/5 | 10.0.0.15 | 24 | 10.0.0.1 | 666 | 1426607987 | 44:f4:77:69:5e:c1 | | 105 | 64 | 2a02:ed02:0666::105 | 2a02:ed02:0666::1 + 27 | e-00-6 | rs1.sector0 | ge-0/0/6 | 10.0.0.16 | 24 | 10.0.0.1 | 666 | | | | 106 | 64 | 2a02:ed02:0666::106 | 2a02:ed02:0666::1 + 28 | e-00-7 | rs1.sector0 | ge-0/0/7 | 10.0.0.17 | 24 | 10.0.0.1 | 666 | 1426540295 | 44:f4:77:69:22:41 | | 107 | 64 | 2a02:ed02:0666::107 | 2a02:ed02:0666::1 + 29 | e-00-8 | rs1.sector0 | ge-0/0/8 | 10.0.0.18 | 24 | 10.0.0.1 | 666 | 1426608145 | 44:f4:77:69:4f:c1 | | 108 | 64 | 2a02:ed02:0666::108 | 2a02:ed02:0666::1 + 30 | e-00-9 | rs1.sector0 | ge-0/0/9 | 10.0.0.19 | 24 | 10.0.0.1 | 666 | 1426608293 | 44:f4:77:68:b5:01 | | 109 | 64 | 2a02:ed02:0666::109 | 2a02:ed02:0666::1 (10 rows) ``` @@ -102,10 +103,4 @@ values ## TODO -ALTER TABLE bootstrap ADD mgmt_v6_cidr smallint; -ALTER TABLE bootstrap ADD mgmt_v6_addr character varying(35); -ALTER TABLE bootstrap ADD mgmt_v6_gw character varying(35); - -Rename v4 column names to follow v6 scheme - -Delete ztp_* columns +* Rename v4 column names to follow v6 scheme diff --git a/fap/httpd/README.md b/fap/httpd/README.md new file mode 100644 index 0000000..73c5634 --- /dev/null +++ b/fap/httpd/README.md @@ -0,0 +1,26 @@ +# HTTPD + +Well, not working out quite as I've hoped (at least for now). + +Resorted to Apache2, PHP and Postgres for the HTTP. Apache starts at boot, so no action required to get the stack up and after installation. + +``` +j@lappie:~/git/tgmanage$ cat /etc/apache2/sites-enabled/000-default.conf + + ServerAdmin webmaster@localhost + + DocumentRoot /home/j/git/tgmanage/fap/httpd/httpd_root/ + + + Options Indexes FollowSymLinks MultiViews + AllowOverride All + Order allow,deny + allow from all + + + ErrorLog ${APACHE_LOG_DIR}/error.log + LogLevel warn + + CustomLog ${APACHE_LOG_DIR}/access.log combined + +``` diff --git a/fap/httpd/ex2200.template b/fap/httpd/ex2200.template index aa62ff2..3adcdf9 100644 --- a/fap/httpd/ex2200.template +++ b/fap/httpd/ex2200.template @@ -82,9 +82,8 @@ interfaces { family ethernet-switching { port-mode trunk; vlan { - members deltagere; + members [deltagere mgmt]; } - native-vlan-id mgmt; } } } @@ -101,6 +100,7 @@ interfaces { filter { input v6-mgmt; } + address $mgmt_v6_addr/$mgmt_v6_cidr; } } } @@ -162,29 +162,6 @@ firewall { } } -ethernet-switching-options { - secure-access-port { - interface edge-ports { - no-dhcp-trusted; - } - vlan deltagere { - arp-inspection; - examine-dhcp; - examine-dhcpv6; - neighbor-discovery-inspection; - ip-source-guard; - ipv6-source-guard; - dhcp-option82; - dhcpv6-option18 { - use-option-82; - } - } - ipv6-source-guard-sessions { - max-number 128; - } - } -} - protocols { sflow { sample-rate { @@ -240,7 +217,7 @@ routing-options { rib inet6.0 { static { route ::/0 { - next-hop 20a0:dead::beef; + next-hop $mgmt_v6_gw; } } } diff --git a/fap/httpd/files/.gitignore b/fap/httpd/files/.gitignore new file mode 100644 index 0000000..cec9082 --- /dev/null +++ b/fap/httpd/files/.gitignore @@ -0,0 +1,3 @@ +* + +!.gitignore diff --git a/fap/httpd/httpd_root/.htaccess b/fap/httpd/httpd_root/.htaccess new file mode 100644 index 0000000..17add11 --- /dev/null +++ b/fap/httpd/httpd_root/.htaccess @@ -0,0 +1,3 @@ +RewriteEngine on +RewriteRule ^files/(.+)$ x.php?mode=image&file=$1 [L] +RewriteRule ^tg-edge/(.+)$ x.php?mode=config&hostname=$1 [L] diff --git a/fap/httpd/httpd_root/ex2200.template b/fap/httpd/httpd_root/ex2200.template new file mode 100644 index 0000000..e7c99f7 --- /dev/null +++ b/fap/httpd/httpd_root/ex2200.template @@ -0,0 +1,226 @@ +system { + host-name ; + 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 "; + aggregated-ether-options { + lacp { + active; + } + } + unit 0 { + family ethernet-switching { + port-mode trunk; + vlan { + members [deltagere mgmt]; + } + } + } + } + vlan { + unit { + description "MGMT L3 interface"; + family inet { + filter { + input v4-mgmt; + } + address ; + } + family inet6 { + filter { + input v6-mgmt; + } + address ; + } + } + } +} +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 ; + } + mgmt { + vlan-id ; + l3-interface vlan.; + } +} + +routing-options { + rib inet.0 { + static { + route 0.0.0.0/0 { + next-hop ; + } + } + } + rib inet6.0 { + static { + route ::/0 { + next-hop ; + } + } + } +} + + diff --git a/fap/httpd/httpd_root/x.php b/fap/httpd/httpd_root/x.php new file mode 100644 index 0000000..70607cc --- /dev/null +++ b/fap/httpd/httpd_root/x.php @@ -0,0 +1,52 @@ + diff --git a/fap/httpd/server_http.py b/fap/httpd/server_http.py index bc9ceea..a9ae74c 100644 --- a/fap/httpd/server_http.py +++ b/fap/httpd/server_http.py @@ -62,7 +62,10 @@ def main(): 'mgmt_cidr': row['mgmt_cidr'], 'mgmt_gw': row['mgmt_gw'], 'mgmt_vlan': row['mgmt_vlan'], - 'traffic_vlan': row['traffic_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() -- cgit v1.2.3