1 | -- Need to do this or our triggers don't work. Why do we need to do this?
|
---|
2 | -- CREATE FUNCTION "plpgsql_call_handler" () RETURNS language_handler AS '$libdir/plpgsql' LANGUAGE C;
|
---|
3 | -- CREATE TRUSTED LANGUAGE "plpgsql" HANDLER "plpgsql_call_handler";
|
---|
4 |
|
---|
5 | -- Table for VRF list
|
---|
6 | CREATE TABLE vrfs (
|
---|
7 | vrf varchar(32) DEFAULT '' NOT NULL,
|
---|
8 | comment text DEFAULT '' NOT NULL,
|
---|
9 | location varchar(4) DEFAULT '' NOT NULL
|
---|
10 | );
|
---|
11 |
|
---|
12 | COPY vrfs (vrf, comment, location) FROM stdin;
|
---|
13 | DEFAULT Initial default VRF
|
---|
14 | \.
|
---|
15 |
|
---|
16 | ALTER TABLE ONLY vrfs
|
---|
17 | ADD CONSTRAINT vrfs_pkey PRIMARY KEY (vrf);
|
---|
18 |
|
---|
19 | -- Table for tracking active netblock assignments and containers.
|
---|
20 | -- Note that maskbits is obsolete but left in for a release cycle or two
|
---|
21 | -- so that legacy dumps can still be loaded, in the unlikely event.
|
---|
22 | CREATE TABLE allocations (
|
---|
23 | cidr cidr DEFAULT '255.255.255.255/32'::cidr NOT NULL,
|
---|
24 | "type" character(2) DEFAULT ''::bpchar,
|
---|
25 | city character varying(30) DEFAULT ''::character varying,
|
---|
26 | description character varying(128) DEFAULT ''::character varying,
|
---|
27 | notes text DEFAULT ''::text,
|
---|
28 | maskbits integer DEFAULT 128,
|
---|
29 | circuitid character varying(128) DEFAULT ''::character varying,
|
---|
30 | createstamp timestamp with time zone DEFAULT now(),
|
---|
31 | modifystamp timestamp with time zone DEFAULT now(),
|
---|
32 | privdata text DEFAULT ''::text NOT NULL,
|
---|
33 | custid character varying(16) DEFAULT ''::character varying,
|
---|
34 | swip character(1) DEFAULT 'n'::bpchar,
|
---|
35 | vrf text DEFAULT ''::text NOT NULL,
|
---|
36 | vlan text DEFAULT ''::text NOT NULL,
|
---|
37 | rdns text DEFAULT ''::text NOT NULL,
|
---|
38 | parent_id integer DEFAULT 0 NOT NULL,
|
---|
39 | master_id integer DEFAULT 0 NOT NULL,
|
---|
40 | backup_id integer DEFAULT 0 NOT NULL,
|
---|
41 | id serial NOT NULL
|
---|
42 | );
|
---|
43 |
|
---|
44 | ALTER TABLE ONLY allocations
|
---|
45 | ADD CONSTRAINT allocations_pkey PRIMARY KEY (id);
|
---|
46 | CREATE UNIQUE INDEX allocations_skey ON allocations (cidr,vrf,type);
|
---|
47 |
|
---|
48 | -- Customer or POP site cities or locations.
|
---|
49 | CREATE TABLE cities (
|
---|
50 | id serial NOT NULL,
|
---|
51 | city character varying(30) DEFAULT ''::character varying NOT NULL,
|
---|
52 | routing character(1) DEFAULT 'n'::bpchar NOT NULL
|
---|
53 | );
|
---|
54 |
|
---|
55 | ALTER TABLE ONLY cities
|
---|
56 | ADD CONSTRAINT cities_pkey PRIMARY KEY (id);
|
---|
57 |
|
---|
58 | -- Local table for rWHOIS customer data
|
---|
59 | CREATE TABLE customers (
|
---|
60 | custid character varying(16) DEFAULT ''::character varying NOT NULL,
|
---|
61 | name character varying(64),
|
---|
62 | street character varying(25),
|
---|
63 | street2 character varying(25),
|
---|
64 | city character varying(30),
|
---|
65 | province character(2),
|
---|
66 | country character(2),
|
---|
67 | pocode character varying(7),
|
---|
68 | phone character varying(15),
|
---|
69 | tech_handle character varying(50),
|
---|
70 | abuse_handle character varying(50),
|
---|
71 | admin_handle character varying(50),
|
---|
72 | def_rdns character varying(40),
|
---|
73 | special text
|
---|
74 | );
|
---|
75 |
|
---|
76 | ALTER TABLE ONLY customers
|
---|
77 | ADD CONSTRAINT customers_pkey PRIMARY KEY (custid);
|
---|
78 |
|
---|
79 | -- Flag table for deciding if we can usefully do rDNS RPC calls.
|
---|
80 | CREATE TABLE dnsavail (
|
---|
81 | "zone" cidr PRIMARY KEY,
|
---|
82 | "location" varchar(4) DEFAULT '',
|
---|
83 | parent_alloc integer NOT NULL
|
---|
84 | );
|
---|
85 |
|
---|
86 | -- Store backup fields in a separate table
|
---|
87 | CREATE TABLE backuplist (
|
---|
88 | backup_id serial NOT NULL,
|
---|
89 | bkbrand text,
|
---|
90 | bkmodel text,
|
---|
91 | bktype text,
|
---|
92 | bkport integer,
|
---|
93 | bksrc text,
|
---|
94 | bkuser text,
|
---|
95 | bkvpass text,
|
---|
96 | bkepass text,
|
---|
97 | bkip inet
|
---|
98 | );
|
---|
99 |
|
---|
100 | -- Table for tracking netblocks available for assignment
|
---|
101 | CREATE TABLE freeblocks (
|
---|
102 | cidr cidr DEFAULT '255.255.255.255/32'::cidr NOT NULL,
|
---|
103 | maskbits integer DEFAULT 128,
|
---|
104 | city character varying(30) DEFAULT ''::character varying,
|
---|
105 | routed character(1) DEFAULT 'n'::bpchar,
|
---|
106 | vrf text DEFAULT ''::text NOT NULL,
|
---|
107 | parent_id integer DEFAULT 0 NOT NULL,
|
---|
108 | master_id integer DEFAULT 0 NOT NULL,
|
---|
109 | reserve_for integer DEFAULT 0 NOT NULL,
|
---|
110 | id serial NOT NULL
|
---|
111 | );
|
---|
112 |
|
---|
113 | ALTER TABLE ONLY freeblocks
|
---|
114 | ADD CONSTRAINT freeblocks_pkey PRIMARY KEY (cidr, parent_id);
|
---|
115 |
|
---|
116 | -- Network nodes - allows finding customers affected by a broken <x> quickly
|
---|
117 | CREATE TABLE noderef (
|
---|
118 | block inet NOT NULL PRIMARY KEY,
|
---|
119 | node_id integer
|
---|
120 | );
|
---|
121 |
|
---|
122 | CREATE TABLE nodes (
|
---|
123 | node_id serial NOT NULL PRIMARY KEY,
|
---|
124 | node_type character varying(2),
|
---|
125 | node_name character varying(40),
|
---|
126 | node_ip inet
|
---|
127 | );
|
---|
128 |
|
---|
129 |
|
---|
130 | -- Email notifications on <action>
|
---|
131 | CREATE TABLE notify (
|
---|
132 | action varchar(5) NOT NULL PRIMARY KEY,
|
---|
133 | reciplist varchar(500)
|
---|
134 | );
|
---|
135 |
|
---|
136 |
|
---|
137 | -- Table for tracking single IP assignments. Single static IP assignments
|
---|
138 | -- need somewhat stronger clustering than provided by other types.
|
---|
139 | CREATE TABLE poolips (
|
---|
140 | pool cidr DEFAULT '255.255.255.255/32'::cidr NOT NULL,
|
---|
141 | ip cidr DEFAULT '255.255.255.255/32'::cidr NOT NULL,
|
---|
142 | city character varying(30) DEFAULT ''::character varying NOT NULL,
|
---|
143 | "type" character(2) DEFAULT ''::bpchar NOT NULL,
|
---|
144 | available character(1) DEFAULT 'y'::bpchar NOT NULL,
|
---|
145 | notes text DEFAULT ''::text NOT NULL,
|
---|
146 | description character varying(128) DEFAULT ''::character varying NOT NULL,
|
---|
147 | circuitid character varying(128) DEFAULT ''::character varying NOT NULL,
|
---|
148 | privdata text DEFAULT ''::text NOT NULL,
|
---|
149 | custid character varying(16) DEFAULT ''::character varying,
|
---|
150 | createstamp timestamp with time zone DEFAULT now(),
|
---|
151 | modifystamp timestamp with time zone DEFAULT now(),
|
---|
152 | vrf text DEFAULT ''::text NOT NULL,
|
---|
153 | vlan text DEFAULT ''::text NOT NULL,
|
---|
154 | rdns text DEFAULT ''::text NOT NULL,
|
---|
155 | parent_id integer DEFAULT 0 NOT NULL,
|
---|
156 | master_id integer DEFAULT 0 NOT NULL,
|
---|
157 | backup_id integer DEFAULT 0 NOT NULL,
|
---|
158 | id serial NOT NULL,
|
---|
159 | CONSTRAINT poolips_available_check CHECK (((available = 'y'::bpchar) OR (available = 'n'::bpchar)))
|
---|
160 | );
|
---|
161 |
|
---|
162 | ALTER TABLE ONLY poolips
|
---|
163 | ADD CONSTRAINT poolips_pkey PRIMARY KEY (ip, parent_id);
|
---|
164 |
|
---|
165 |
|
---|
166 | -- Combined netblock+IP view for searches
|
---|
167 | CREATE VIEW searchme AS
|
---|
168 | SELECT allocations.cidr, allocations.custid, allocations."type", allocations.city,
|
---|
169 | allocations.description, allocations.notes, allocations.circuitid, allocations.vrf,
|
---|
170 | allocations.vlan, allocations.id, allocations.parent_id, allocations.master_id, 'n' AS available
|
---|
171 | FROM allocations
|
---|
172 | UNION
|
---|
173 | SELECT poolips.ip AS cidr, poolips.custid, poolips."type", poolips.city,
|
---|
174 | poolips.description, poolips.notes, poolips.circuitid, poolips.vrf,
|
---|
175 | poolips.vlan, poolips.id, poolips.parent_id, poolips.master_id, poolips.available
|
---|
176 | FROM poolips;
|
---|
177 |
|
---|
178 |
|
---|
179 | -- Type list for assignments
|
---|
180 | CREATE TABLE alloctypes (
|
---|
181 | "type" character(2) DEFAULT ''::bpchar NOT NULL,
|
---|
182 | listname character varying(40) DEFAULT ''::character varying,
|
---|
183 | dispname character varying(40) DEFAULT ''::character varying,
|
---|
184 | listorder integer DEFAULT 0,
|
---|
185 | def_custid character varying(16) DEFAULT ''::character varying,
|
---|
186 | arin_netname character varying(20) DEFAULT 'ISP'::character varying
|
---|
187 | );
|
---|
188 |
|
---|
189 | ALTER TABLE ONLY alloctypes
|
---|
190 | ADD CONSTRAINT alloctypes_pkey PRIMARY KEY ("type");
|
---|
191 |
|
---|
192 |
|
---|
193 | -- Initial/standard allocation types. Update def_custid and arin_netname as appropriate.
|
---|
194 | COPY alloctypes ("type", listname, dispname, listorder, def_custid, arin_netname) FROM stdin;
|
---|
195 | cn Customer netblock Customer netblock 0 ISPCUST
|
---|
196 | si Static IP - Server pool Server pool IP 20 ISP
|
---|
197 | ci Static IP - Cable Static cable IP 21 ISP
|
---|
198 | di Static IP - DSL Static DSL IP 22 ISP
|
---|
199 | mi Static IP - Dialup Static dialup IP 23 ISP
|
---|
200 | wi Static IP - Wireless Static wireless IP 24 ISP
|
---|
201 | sd Static Pool - Servers Server pool 40 5554242 ISP
|
---|
202 | cd Static Pool - Cable Cable pool 41 CBL-BUS ISP-STATIC-CABLE
|
---|
203 | dp Static Pool - DSL DSL pool 42 DSL-BUS ISP-STATIC-DSL
|
---|
204 | mp Static Pool - Dialup Static dialup pool 43 DIAL-BUS ISP-STATIC-DIAL
|
---|
205 | wp Static Pool - Wireless Static wireless pool 44 WL-BUS ISP-STATIC-WIFI
|
---|
206 | en End-use netblock End-use netblock 100 5554242 ISP
|
---|
207 | me Dialup netblock Dialup netblock 101 DIAL-RES ISP-DIAL
|
---|
208 | de Dynamic DSL block Dynamic DSL block 102 DSL-RES ISP-DSL
|
---|
209 | ce Dynamic cable block Dynamic cable block 103 CBL-RES ISP-CABLE
|
---|
210 | we Dynamic WiFi block Dynamic WiFi block 104 WL-RES ISP-WIFI
|
---|
211 | ve Dynamic VoIP block Dynamic VoIP block 105 DYN-VOIP ISP
|
---|
212 | li Static IP - LAN/POP Static LAN/POP IP 190 NOC-VPN ISP
|
---|
213 | ai Static IP - Management Static management IP 192 NOC-VPN ISP
|
---|
214 | bi Static IP - Wifi CPE Wifi CPE IP 193 ISP
|
---|
215 | ld Static Pool - LAN/POP LAN pool 195 NOC-VPN ISP
|
---|
216 | ad Static Pool - Management Management pool 196 NOC-VPN ISP
|
---|
217 | bd Static pool - Wifi CPE Wifi CPE pool 197 ISP
|
---|
218 | in Internal netblock Internal netblock 199 5554242 ISP
|
---|
219 | wc Reserve for CORE/WAN blocks CORE/WAN blocks 200 5554242 ISP
|
---|
220 | pc Reserve for dynamic-route DSL netblocks Dynamic-route netblocks 201 5554242 ISP-STATIC-DSL
|
---|
221 | ac Reserve for ATM ATM blocks 202 5554242 ISP
|
---|
222 | fc Reserve for fibre Fibre blocks 203 5554242 ISP
|
---|
223 | wr CORE/WAN block CORE/WAN block 220 5554242 ISP
|
---|
224 | pr Dynamic-route DSL netblock (cust) Dynamic-route DSL (cust) 221 ISPCUST
|
---|
225 | ar ATM block ATM block 222 ISP
|
---|
226 | fr Fibre Fibre 223 ISP
|
---|
227 | rm Routing aggregation Routing aggregation 500 5554242 ISP
|
---|
228 | mm Master block Master block 999 5554242 ISP
|
---|
229 | \.
|
---|
230 |
|
---|
231 | -- User data table - required for proper ACLs
|
---|
232 | CREATE TABLE users (
|
---|
233 | username character varying(256) NOT NULL,
|
---|
234 | "password" character varying(256) DEFAULT ''::character varying,
|
---|
235 | acl character varying(256) DEFAULT 'b'::character varying
|
---|
236 | );
|
---|
237 |
|
---|
238 | ALTER TABLE ONLY users
|
---|
239 | ADD CONSTRAINT users_pkey PRIMARY KEY (username);
|
---|
240 |
|
---|
241 | -- Default password is admin
|
---|
242 | INSERT INTO users VALUES ('admin','luef5C4XumqIs','bacdsAm');
|
---|
243 |
|
---|
244 |
|
---|
245 | -- Trigger and matching function to update modifystamp on allocations, poolips
|
---|
246 | CREATE FUNCTION up_modtime () RETURNS OPAQUE AS '
|
---|
247 | BEGIN
|
---|
248 | NEW.modifystamp := ''now'';
|
---|
249 | RETURN NEW;
|
---|
250 | END;
|
---|
251 | ' LANGUAGE 'plpgsql';
|
---|
252 |
|
---|
253 | CREATE TRIGGER up_modtime BEFORE UPDATE ON allocations
|
---|
254 | FOR EACH ROW EXECUTE PROCEDURE up_modtime();
|
---|
255 |
|
---|
256 | CREATE TRIGGER up_modtime BEFORE UPDATE ON poolips
|
---|
257 | FOR EACH ROW EXECUTE PROCEDURE up_modtime();
|
---|