[347] | 1 | DROP DATABASE ipdb;
|
---|
| 2 |
|
---|
| 3 | CREATE USER ipdb WITH PASSWORD 'ipdbpwd';
|
---|
| 4 |
|
---|
[181] | 5 | CREATE DATABASE ipdb;
|
---|
[4] | 6 |
|
---|
[347] | 7 | -- Need to do this or our triggers don't work. Why do we need to do this?
|
---|
| 8 | CREATE FUNCTION "plpgsql_call_handler" () RETURNS language_handler AS '$libdir/plpgsql' LANGUAGE C;
|
---|
| 9 | CREATE TRUSTED LANGUAGE "plpgsql" HANDLER "plpgsql_call_handler";
|
---|
| 10 |
|
---|
| 11 | UPDATE pg_database SET datdba=(SELECT usesysid FROM pg_shadow WHERE usename='ipdb')
|
---|
| 12 | WHERE datname='ipdb';
|
---|
| 13 |
|
---|
[176] | 14 | \connect ipdb ipdb
|
---|
[4] | 15 |
|
---|
| 16 | CREATE TABLE "customers" (
|
---|
[347] | 17 | "custid" character varying(16) DEFAULT '' NOT NULL,
|
---|
| 18 | "name" character varying(64),
|
---|
| 19 | "street" character varying(25),
|
---|
| 20 | "street2" character varying(25),
|
---|
| 21 | "city" character varying(30),
|
---|
| 22 | "province" character(2),
|
---|
| 23 | "country" character(2),
|
---|
| 24 | "pocode" character varying(7),
|
---|
| 25 | "phone" character varying(15),
|
---|
| 26 | "tech_handle" character varying(50),
|
---|
| 27 | "abuse_handle" character varying(50),
|
---|
| 28 | "admin_handle" character varying(50),
|
---|
| 29 | "def_rdns" character varying(40),
|
---|
| 30 | "special" text,
|
---|
| 31 | Constraint "customers_pkey" Primary Key ("custid")
|
---|
[4] | 32 | );
|
---|
| 33 |
|
---|
[34] | 34 | REVOKE ALL on "customers" from PUBLIC;
|
---|
| 35 | GRANT ALL on "customers" to "ipdb";
|
---|
| 36 |
|
---|
[4] | 37 | CREATE TABLE "masterblocks" (
|
---|
[219] | 38 | "cidr" cidr DEFAULT '255.255.255.255/32' NOT NULL PRIMARY KEY,
|
---|
[657] | 39 | "ctime" timestamp with time zone DEFAULT now(),
|
---|
| 40 | "mtime" timestamp with time zone DEFAULT now(),
|
---|
[371] | 41 | "rwhois" character(1) DEFAULT 'n' NOT NULL
|
---|
[4] | 42 | );
|
---|
| 43 |
|
---|
[34] | 44 | REVOKE ALL on "masterblocks" from PUBLIC;
|
---|
| 45 | GRANT ALL on "masterblocks" to "ipdb";
|
---|
| 46 |
|
---|
[4] | 47 | CREATE TABLE "routed" (
|
---|
[176] | 48 | "cidr" cidr DEFAULT '255.255.255.255/32' NOT NULL PRIMARY KEY,
|
---|
[4] | 49 | "maskbits" integer DEFAULT 128,
|
---|
[219] | 50 | "city" character varying(30) DEFAULT '',
|
---|
[657] | 51 | "ctime" timestamp with time zone DEFAULT now()
|
---|
[4] | 52 | );
|
---|
| 53 |
|
---|
[34] | 54 | REVOKE ALL on "routed" from PUBLIC;
|
---|
| 55 | GRANT ALL on "routed" to "ipdb";
|
---|
[316] | 56 | GRANT SELECT on "routed" to "ipdb";
|
---|
[34] | 57 |
|
---|
[57] | 58 | CREATE TABLE "freeblocks" (
|
---|
[180] | 59 | "cidr" cidr DEFAULT '255.255.255.255/32' NOT NULL PRIMARY KEY,
|
---|
[57] | 60 | "maskbits" integer DEFAULT 128,
|
---|
| 61 | "city" character varying(30) DEFAULT '',
|
---|
[176] | 62 | "routed" character(1) DEFAULT 'n'
|
---|
[34] | 63 | );
|
---|
| 64 |
|
---|
[57] | 65 | REVOKE ALL on "freeblocks" from PUBLIC;
|
---|
| 66 | GRANT ALL on "freeblocks" to "ipdb";
|
---|
[34] | 67 |
|
---|
[74] | 68 | CREATE TABLE "poolips" (
|
---|
| 69 | "pool" cidr DEFAULT '255.255.255.255/32' NOT NULL,
|
---|
[176] | 70 | "ip" cidr DEFAULT '255.255.255.255/32' NOT NULL PRIMARY KEY,
|
---|
[175] | 71 | "city" character varying(30) DEFAULT '' NOT NULL,
|
---|
| 72 | "type" character(2) DEFAULT '' NOT NULL,
|
---|
| 73 | "available" character(1) DEFAULT 'y' NOT NULL,
|
---|
| 74 | "notes" text DEFAULT '' NOT NULL,
|
---|
| 75 | "description" character varying(64) DEFAULT '' NOT NULL,
|
---|
| 76 | "circuitid" character varying(128) DEFAULT '' NOT NULL,
|
---|
[284] | 77 | "privdata" text DEFAULT '' NOT NULL,
|
---|
[347] | 78 | "custid" character varying(16) DEFAULT '',
|
---|
[657] | 79 | "createstamp" timestamp with time zone DEFAULT now(),
|
---|
| 80 | "modifystamp" timestamp with time zone DEFAULT now(),
|
---|
[176] | 81 | CHECK (((available = 'y'::bpchar) OR (available = 'n'::bpchar)))
|
---|
[74] | 82 | );
|
---|
| 83 |
|
---|
| 84 | REVOKE ALL on "poolips" from PUBLIC;
|
---|
| 85 | GRANT ALL on "poolips" to "ipdb";
|
---|
| 86 |
|
---|
| 87 | CREATE TABLE "allocations" (
|
---|
[176] | 88 | "cidr" cidr DEFAULT '255.255.255.255/32' NOT NULL PRIMARY KEY,
|
---|
[74] | 89 | "type" character(2) DEFAULT '',
|
---|
| 90 | "city" character varying(30) DEFAULT '',
|
---|
| 91 | "description" character varying(64) DEFAULT '',
|
---|
| 92 | "notes" text DEFAULT '',
|
---|
| 93 | "maskbits" integer DEFAULT 128,
|
---|
| 94 | "circuitid" character varying(128) DEFAULT '',
|
---|
[657] | 95 | "createstamp" timestamp with time zone DEFAULT now(),
|
---|
| 96 | "modifystamp" timestamp with time zone DEFAULT now(),
|
---|
[284] | 97 | "privdata" text DEFAULT '' NOT NULL,
|
---|
[347] | 98 | "custid" character varying(16) DEFAULT '',
|
---|
[316] | 99 | swip character(1) DEFAULT 'n'
|
---|
[74] | 100 | );
|
---|
| 101 |
|
---|
| 102 | REVOKE ALL on "allocations" from PUBLIC;
|
---|
| 103 | GRANT ALL on "allocations" to "ipdb";
|
---|
| 104 |
|
---|
[455] | 105 | CREATE VIEW "searchme" as SELECT allocations.cidr, allocations.custid, allocations."type", allocations.city, allocations.description, allocations.notes, allocations.circuitid FROM allocations UNION SELECT poolips.ip, poolips.custid, poolips.type, poolips.city, poolips.description, poolips.notes, poolips.circuitid FROM poolips;
|
---|
[92] | 106 |
|
---|
[176] | 107 | REVOKE ALL on "searchme" from PUBLIC;
|
---|
| 108 | GRANT ALL on "searchme" to "ipdb";
|
---|
| 109 |
|
---|
[92] | 110 | CREATE TABLE "alloctypes" (
|
---|
[176] | 111 | "type" character(2) DEFAULT '' NOT NULL PRIMARY KEY,
|
---|
[92] | 112 | "listname" character varying(40) DEFAULT '',
|
---|
| 113 | "dispname" character varying(40) DEFAULT '',
|
---|
| 114 | "listorder" integer DEFAULT 0,
|
---|
[324] | 115 | "def_custid" character varying(16) DEFAULT '',
|
---|
[347] | 116 | "arin_netname" character varying(20) DEFAULT 'ISP'
|
---|
[92] | 117 | );
|
---|
| 118 |
|
---|
[321] | 119 | --
|
---|
| 120 | -- Name: alloctypes; Type: TABLE DATA; Schema: public; Owner: ipdb
|
---|
| 121 | --
|
---|
| 122 |
|
---|
[388] | 123 | COPY alloctypes ("type", listname, dispname, listorder, def_custid, arin_netname) FROM stdin;
|
---|
[324] | 124 | cn Customer netblock Customer netblock 0 ISPCUST
|
---|
[403] | 125 | si Static IP - Server pool Server pool IP 20 ISP
|
---|
| 126 | ci Static IP - Cable Static cable IP 21 ISP
|
---|
| 127 | di Static IP - DSL Static DSL IP 22 ISP
|
---|
| 128 | mi Static IP - Dialup Static dialup IP 23 ISP
|
---|
| 129 | wi Static IP - Wireless Static wireless IP 24 ISP
|
---|
[417] | 130 | sd Static Pool - Servers Server pool 40 5554242 ISP
|
---|
[324] | 131 | cd Static Pool - Cable Cable pool 41 CBL-BUS ISP-STATIC-CABLE
|
---|
| 132 | dp Static Pool - DSL DSL pool 42 DSL-BUS ISP-STATIC-DSL
|
---|
| 133 | mp Static Pool - Dialup Static dialup pool 43 DIAL-BUS ISP-STATIC-DIAL
|
---|
| 134 | wp Static Pool - Wireless Static wireless pool 44 WL-BUS ISP-STATIC-WIFI
|
---|
[417] | 135 | en End-use netblock End-use netblock 100 5554242 ISP
|
---|
[324] | 136 | me Dialup netblock Dialup netblock 101 DIAL-RES ISP-DIAL
|
---|
| 137 | de Dynamic DSL block Dynamic DSL block 102 DSL-RES ISP-DSL
|
---|
| 138 | ce Dynamic cable block Dynamic cable block 103 CBL-RES ISP-CABLE
|
---|
| 139 | we Dynamic WiFi block Dynamic WiFi block 104 WL-RES ISP-WIFI
|
---|
| 140 | ve Dynamic VoIP block Dynamic VoIP block 105 DYN-VOIP ISP
|
---|
[403] | 141 | li Static IP - LAN/POP Static LAN/POP IP 190 NOC-VPN ISP
|
---|
[409] | 142 | ai Static IP - Management Static management IP 192 NOC-VPN ISP
|
---|
[403] | 143 | bi Static IP - Wifi CPE Wifi CPE IP 193 ISP
|
---|
| 144 | ld Static Pool - LAN/POP LAN pool 195 NOC-VPN ISP
|
---|
[409] | 145 | ad Static Pool - Management Management pool 196 NOC-VPN ISP
|
---|
[403] | 146 | bd Static pool - Wifi CPE Wifi CPE pool 197 ISP
|
---|
[417] | 147 | in Internal netblock Internal netblock 199 5554242 ISP
|
---|
| 148 | wc Reserve for CORE/WAN blocks CORE/WAN blocks 200 5554242 ISP
|
---|
| 149 | pc Reserve for dynamic-route DSL netblocks Dynamic-route netblocks 201 5554242 ISP-STATIC-DSL
|
---|
| 150 | ac Reserve for ATM ATM blocks 202 5554242 ISP
|
---|
| 151 | fc Reserve for fibre Fibre blocks 203 5554242 ISP
|
---|
| 152 | wr CORE/WAN block CORE/WAN block 220 5554242 ISP
|
---|
[403] | 153 | pr Dynamic-route DSL netblock (cust) Dynamic-route DSL (cust) 221 ISPCUST
|
---|
[324] | 154 | ar ATM block ATM block 222 ISP
|
---|
[403] | 155 | fr Fibre Fibre 223 ISP
|
---|
[417] | 156 | rm Routing Routed netblock 500 5554242 ISP
|
---|
| 157 | mm Master block Master block 999 5554242 ISP
|
---|
[182] | 158 | \.
|
---|
[218] | 159 |
|
---|
[316] | 160 | REVOKE ALL on "alloctypes" from PUBLIC;
|
---|
| 161 | GRANT ALL on "alloctypes" to "ipdb";
|
---|
| 162 |
|
---|
| 163 | CREATE TABLE "cities" (
|
---|
| 164 | "id" serial NOT NULL PRIMARY KEY,
|
---|
| 165 | "city" character varying(30) DEFAULT '' NOT NULL,
|
---|
| 166 | "routing" character(1) DEFAULT 'n' NOT NULL
|
---|
| 167 | );
|
---|
| 168 |
|
---|
| 169 | REVOKE ALL on "cities" from PUBLIC;
|
---|
| 170 | GRANT ALL on "cities" to "ipdb";
|
---|
| 171 |
|
---|
[218] | 172 | --
|
---|
| 173 | -- Trigger and matching function to update modifystamp on allocations, poolips
|
---|
| 174 | --
|
---|
| 175 | CREATE FUNCTION up_modtime () RETURNS OPAQUE AS '
|
---|
| 176 | BEGIN
|
---|
| 177 | NEW.modifystamp := ''now'';
|
---|
| 178 | RETURN NEW;
|
---|
| 179 | END;
|
---|
| 180 | ' LANGUAGE 'plpgsql';
|
---|
| 181 |
|
---|
| 182 | CREATE TRIGGER up_modtime BEFORE UPDATE ON allocations
|
---|
| 183 | FOR EACH ROW EXECUTE PROCEDURE up_modtime();
|
---|
| 184 |
|
---|
| 185 | CREATE TRIGGER up_modtime BEFORE UPDATE ON poolips
|
---|
| 186 | FOR EACH ROW EXECUTE PROCEDURE up_modtime();
|
---|
[233] | 187 |
|
---|
| 188 | --
|
---|
| 189 | -- User data table - required for proper ACLs
|
---|
| 190 | --
|
---|
| 191 |
|
---|
| 192 | CREATE TABLE "users" (
|
---|
[237] | 193 | "username" varchar(16) NOT NULL PRIMARY KEY,
|
---|
[233] | 194 | "password" varchar(16) DEFAULT '',
|
---|
| 195 | "acl" varchar(16) DEFAULT 'b'
|
---|
| 196 | );
|
---|
[257] | 197 |
|
---|
[347] | 198 | -- Default password is admin
|
---|
| 199 | INSERT INTO users VALUES ('admin','luef5C4XumqIs','bacdsA');
|
---|
| 200 |
|
---|
[397] | 201 | -- Network nodes - allows finding customers affected by a broken <x> quickly
|
---|
| 202 | CREATE TABLE noderef (
|
---|
| 203 | block inet NOT NULL PRIMARY KEY,
|
---|
| 204 | node_id integer
|
---|
| 205 | );
|
---|
| 206 |
|
---|
| 207 | CREATE TABLE nodes (
|
---|
| 208 | node_id serial NOT NULL PRIMARY KEY,
|
---|
| 209 | node_type character varying(2),
|
---|
| 210 | node_name character varying(40),
|
---|
| 211 | node_ip inet
|
---|
| 212 | );
|
---|
[416] | 213 |
|
---|
| 214 | -- Email notifications on <action>
|
---|
| 215 | CREATE TABLE notify (
|
---|
| 216 | action varchar(5) NOT NULL PRIMARY KEY,
|
---|
| 217 | reciplist varchar(500)
|
---|
| 218 | );
|
---|