From 5b42f93b5b0d33dc5c790991431b6282a5671bc9 Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Tue, 12 Apr 2016 18:35:37 +0200 Subject: Some housekeeping/reorganizing moving things that need work into extras/ --- extras/fap/README.md | 37 ++ extras/fap/database/README.md | 63 ++ extras/fap/dhcpd/DHCP_protocol_breakdown.txt | 18 + extras/fap/dhcpd/module_craft_option.py | 79 +++ extras/fap/dhcpd/module_lease.py | 174 ++++++ extras/fap/dhcpd/server_dhcp.py | 360 +++++++++++ extras/fap/dhcpd/terminal.log | 146 +++++ extras/fap/httpd/# DEPRECATED/server_http.py | 146 +++++ extras/fap/httpd/# DEPRECATED/terminal.log | 14 + extras/fap/httpd/README.md | 26 + extras/fap/httpd/files/.gitignore | 3 + .../create_queries.php | 55 ++ .../ipcalc_functions.php | 134 +++++ .../# create_queries - DEPRECATED/patchlist.txt | 142 +++++ .../# create_queries - DEPRECATED/switches.txt | 142 +++++ extras/fap/httpd/httpd_root/.gitignore | 0 extras/fap/httpd/httpd_root/.htaccess | 3 + extras/fap/httpd/httpd_root/ex2200.template | 288 +++++++++ extras/fap/httpd/httpd_root/ex2200_secure.template | 312 ++++++++++ extras/fap/httpd/httpd_root/pg_connect.php | 6 + extras/fap/httpd/httpd_root/x.php | 67 +++ extras/fap/logs/httpd.log | 667 +++++++++++++++++++++ .../proof_of_concepts/distro_during_testing.config | 355 +++++++++++ .../fap/proof_of_concepts/tg15-tech82-poc1.tar.gz | Bin 0 -> 4691 bytes extras/fap/tools_temp/get_info.php | 48 ++ extras/misc/apache2.conf | 56 ++ extras/misc/varnish.vcl | 55 ++ extras/tools/add_switches.txt.pl | 17 + extras/tools/deplist.sh | 22 + extras/tools/get_mibs.sh | 15 + 30 files changed, 3450 insertions(+) create mode 100644 extras/fap/README.md create mode 100755 extras/fap/database/README.md create mode 100755 extras/fap/dhcpd/DHCP_protocol_breakdown.txt create mode 100755 extras/fap/dhcpd/module_craft_option.py create mode 100755 extras/fap/dhcpd/module_lease.py create mode 100755 extras/fap/dhcpd/server_dhcp.py create mode 100755 extras/fap/dhcpd/terminal.log create mode 100755 extras/fap/httpd/# DEPRECATED/server_http.py create mode 100755 extras/fap/httpd/# DEPRECATED/terminal.log create mode 100755 extras/fap/httpd/README.md create mode 100755 extras/fap/httpd/files/.gitignore create mode 100644 extras/fap/httpd/httpd_root/# create_queries - DEPRECATED/create_queries.php create mode 100644 extras/fap/httpd/httpd_root/# create_queries - DEPRECATED/ipcalc_functions.php create mode 100644 extras/fap/httpd/httpd_root/# create_queries - DEPRECATED/patchlist.txt create mode 100644 extras/fap/httpd/httpd_root/# create_queries - DEPRECATED/switches.txt create mode 100644 extras/fap/httpd/httpd_root/.gitignore create mode 100755 extras/fap/httpd/httpd_root/.htaccess create mode 100755 extras/fap/httpd/httpd_root/ex2200.template create mode 100755 extras/fap/httpd/httpd_root/ex2200_secure.template create mode 100644 extras/fap/httpd/httpd_root/pg_connect.php create mode 100755 extras/fap/httpd/httpd_root/x.php create mode 100644 extras/fap/logs/httpd.log create mode 100755 extras/fap/proof_of_concepts/distro_during_testing.config create mode 100755 extras/fap/proof_of_concepts/tg15-tech82-poc1.tar.gz create mode 100644 extras/fap/tools_temp/get_info.php create mode 100644 extras/misc/apache2.conf create mode 100644 extras/misc/varnish.vcl create mode 100755 extras/tools/add_switches.txt.pl create mode 100755 extras/tools/deplist.sh create mode 100755 extras/tools/get_mibs.sh (limited to 'extras') diff --git a/extras/fap/README.md b/extras/fap/README.md new file mode 100644 index 0000000..c8278f5 --- /dev/null +++ b/extras/fap/README.md @@ -0,0 +1,37 @@ +# FAP - Fast and Agile Provisioning + +Tools (DHCP daemon + HTTP daemon + DB) for managing provisioning towards a large number of factory default Juniper switches (EX2200) using ZTP (Zero Touch Protocol) over DHCP relays. + +The project is built with Python (>3.4.0) and PostgreSQL (>9.3.5). + +Licensed under the GNU GPL, version 2. See the included COPYING file. + + + +## Usage +Launch the python scripts for fap from tgmanage directory. + + apt-get install apache2 php5 python3 python3-psycopg2 php5-pgsql + a2enmod cgi + a2enmod rewrite + + + +### 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 + + +# TODO +* 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/extras/fap/database/README.md b/extras/fap/database/README.md new file mode 100755 index 0000000..3d014d3 --- /dev/null +++ b/extras/fap/database/README.md @@ -0,0 +1,63 @@ +# Database layout + +PostgreSQL + +**Tables** +``` +bootstrap-> \dt + List of relations + Schema | Name | Type | Owner +--------+----------+-------+----------- + public | switches | table | bootstrap +``` + + +**Table structure** +``` +fap=> \d switches + Table "public.switches" + Column | Type | Modifiers +-------------------+------------------------+------------------------------------------------------- + id | integer | not null default nextval('switches_id_seq'::regclass) + 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 | +``` + + +**Sample content in DB** +``` +fap=> select * from switches where [...] order by id desc; + id | hostname | distro_name | distro_phy_port | mgmt_v4_addr | mgmt_v4_cidr | mgmt_v4_gw | mgmt_v6_cidr | mgmt_v6_addr | mgmt_v6_gw | mgmt_vlan | last_config_fetch | current_mac | model | traffic_vlan +-----+--------------------+----------------+-----------------+-----------------+--------------+-----------------+--------------+---------------------+-------------------+-----------+-------------------+-------------------+-------+-------------- + 447 | sw1-crew | rs1.crew | ge-0/0/39 | 151.216.183.66 | 27 | 151.216.183.65 | 64 | 2a02:ed02:1832::66 | 2a02:ed02:1832::1 | 666 | | 44:f4:77:69:4d:41 | | 1701 + 442 | sw2-gamestudio | rs1.north | ge-0/0/45 | 151.216.183.230 | 27 | 151.216.183.225 | 64 | 2a02:ed02:1837::230 | 2a02:ed02:1837::1 | 666 | | 44:f4:77:69:5d:41 | | 229 + 435 | sw1-south | rs1.south | ge-0/0/45 | 151.216.183.98 | 27 | 151.216.183.97 | 64 | 2a02:ed02:1836::98 | 2a02:ed02:1836::1 | 666 | | 44:f4:77:69:49:81 | | 234 + 434 | sw8-creativia | rs1.distro6 | ge-0/0/25 | 151.216.181.155 | 26 | 151.216.181.129 | 64 | 2a02:ed02:181c::155 | 2a02:ed02:181c::1 | 666 | | 44:f4:77:69:1a:c1 | | 2008 + 420 | e83-1 | rs1.distro7 | ge-0/0/20 | 151.216.181.214 | 26 | 151.216.181.193 | 64 | 2a02:ed02:181d::214 | 2a02:ed02:181d::1 | 666 | | 44:f4:77:69:53:c1 | | 1831 + 419 | e81-2 | rs1.distro7 | ge-0/0/19 | 151.216.181.213 | 26 | 151.216.181.193 | 64 | 2a02:ed02:181d::213 | 2a02:ed02:181d::1 | 666 | | 44:f4:77:69:4b:81 | | 1812 + 418 | e81-1 | rs1.distro7 | ge-0/0/18 | 151.216.181.212 | 26 | 151.216.181.193 | 64 | 2a02:ed02:181d::212 | 2a02:ed02:181d::1 | 666 | | 44:f4:77:68:eb:c1 | | 1811 + 417 | e79-4 | rs1.distro6 | ge-0/0/17 | 151.216.181.147 | 26 | 151.216.181.129 | 64 | 2a02:ed02:181c::147 | 2a02:ed02:181c::1 | 666 | | 44:f4:77:69:02:c1 | | 1794 +``` + + +**Connect to DB from CLI** +``` +j@lappie:~/git/tgmanage$ psql -U bootstrap -d bootstrap -W +Password for user bootstrap: +psql (9.3.5) +Type "help" for help. + +bootstrap=> +``` diff --git a/extras/fap/dhcpd/DHCP_protocol_breakdown.txt b/extras/fap/dhcpd/DHCP_protocol_breakdown.txt new file mode 100755 index 0000000..5af2bf2 --- /dev/null +++ b/extras/fap/dhcpd/DHCP_protocol_breakdown.txt @@ -0,0 +1,18 @@ +Length of DHCP fields in octets, and their placement in packet. +Ref: http://4.bp.blogspot.com/-IyYoFjAC4l8/UXuo16a3sII/AAAAAAAAAXQ/b6BojbYXoXg/s1600/DHCPTitle.JPG +0 OP - 1 +1 HTYPE - 1 +2 HLEN - 1 +3 HOPS - 1 +4 XID - 4 +5 SECS - 2 +6 FLAGS - 2 +7 CIADDR - 4 +8 YIADDR - 4 +9 SIADDR - 4 +10 GIADDR - 4 +11 CHADDR - 6 +12 MAGIC COOKIE - 10 +13 PADDING - 192 octets of 0's +14 MAGIC COOKIE - 4 +15 OPTIONS - variable length diff --git a/extras/fap/dhcpd/module_craft_option.py b/extras/fap/dhcpd/module_craft_option.py new file mode 100755 index 0000000..35e7328 --- /dev/null +++ b/extras/fap/dhcpd/module_craft_option.py @@ -0,0 +1,79 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +''' + Created by Jonas 'j' Lindstad for The Gathering 2015 + License: GPLv3 + + Class used to craft byte hex encoded DHCP options + + NB: No direct support for suboptions. Should be possible to craft suboptions as + options, and inject them with craft_option(