[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,
|
---|
[324] | 39 | "ctime" timestamp DEFAULT now(),
|
---|
| 40 | "mtime" timestamp DEFAULT now()
|
---|
[4] | 41 | );
|
---|
| 42 |
|
---|
[34] | 43 | REVOKE ALL on "masterblocks" from PUBLIC;
|
---|
| 44 | GRANT ALL on "masterblocks" to "ipdb";
|
---|
| 45 |
|
---|
[4] | 46 | CREATE TABLE "routed" (
|
---|
[176] | 47 | "cidr" cidr DEFAULT '255.255.255.255/32' NOT NULL PRIMARY KEY,
|
---|
[4] | 48 | "maskbits" integer DEFAULT 128,
|
---|
[219] | 49 | "city" character varying(30) DEFAULT '',
|
---|
| 50 | "ctime" timestamp DEFAULT now()
|
---|
[4] | 51 | );
|
---|
| 52 |
|
---|
[34] | 53 | REVOKE ALL on "routed" from PUBLIC;
|
---|
| 54 | GRANT ALL on "routed" to "ipdb";
|
---|
[316] | 55 | GRANT SELECT on "routed" to "ipdb";
|
---|
[34] | 56 |
|
---|
[4] | 57 | CREATE TABLE "temp" (
|
---|
| 58 | "ofs" integer
|
---|
| 59 | );
|
---|
| 60 |
|
---|
[34] | 61 | REVOKE ALL on "temp" from PUBLIC;
|
---|
| 62 | GRANT ALL on "temp" to "ipdb";
|
---|
| 63 |
|
---|
[57] | 64 | CREATE TABLE "freeblocks" (
|
---|
[180] | 65 | "cidr" cidr DEFAULT '255.255.255.255/32' NOT NULL PRIMARY KEY,
|
---|
[57] | 66 | "maskbits" integer DEFAULT 128,
|
---|
| 67 | "city" character varying(30) DEFAULT '',
|
---|
[176] | 68 | "routed" character(1) DEFAULT 'n'
|
---|
[34] | 69 | );
|
---|
| 70 |
|
---|
[57] | 71 | REVOKE ALL on "freeblocks" from PUBLIC;
|
---|
| 72 | GRANT ALL on "freeblocks" to "ipdb";
|
---|
[34] | 73 |
|
---|
[74] | 74 | CREATE TABLE "poolips" (
|
---|
| 75 | "pool" cidr DEFAULT '255.255.255.255/32' NOT NULL,
|
---|
[176] | 76 | "ip" cidr DEFAULT '255.255.255.255/32' NOT NULL PRIMARY KEY,
|
---|
[347] | 77 | "oldcustid" character varying(16) DEFAULT '' NOT NULL,
|
---|
[175] | 78 | "city" character varying(30) DEFAULT '' NOT NULL,
|
---|
| 79 | "type" character(2) DEFAULT '' NOT NULL,
|
---|
| 80 | "available" character(1) DEFAULT 'y' NOT NULL,
|
---|
| 81 | "notes" text DEFAULT '' NOT NULL,
|
---|
| 82 | "description" character varying(64) DEFAULT '' NOT NULL,
|
---|
| 83 | "circuitid" character varying(128) DEFAULT '' NOT NULL,
|
---|
[284] | 84 | "privdata" text DEFAULT '' NOT NULL,
|
---|
[347] | 85 | "custid" character varying(16) DEFAULT '',
|
---|
[218] | 86 | "createstamp" timestamp DEFAULT now(),
|
---|
| 87 | "modifystamp" timestamp DEFAULT now(),
|
---|
[176] | 88 | CHECK (((available = 'y'::bpchar) OR (available = 'n'::bpchar)))
|
---|
[74] | 89 | );
|
---|
| 90 |
|
---|
| 91 | REVOKE ALL on "poolips" from PUBLIC;
|
---|
| 92 | GRANT ALL on "poolips" to "ipdb";
|
---|
| 93 |
|
---|
| 94 | CREATE TABLE "allocations" (
|
---|
[176] | 95 | "cidr" cidr DEFAULT '255.255.255.255/32' NOT NULL PRIMARY KEY,
|
---|
[347] | 96 | "oldcustid" character varying(16) DEFAULT '',
|
---|
[74] | 97 | "type" character(2) DEFAULT '',
|
---|
| 98 | "city" character varying(30) DEFAULT '',
|
---|
| 99 | "description" character varying(64) DEFAULT '',
|
---|
| 100 | "notes" text DEFAULT '',
|
---|
| 101 | "maskbits" integer DEFAULT 128,
|
---|
| 102 | "circuitid" character varying(128) DEFAULT '',
|
---|
[218] | 103 | "createstamp" timestamp DEFAULT now(),
|
---|
| 104 | "modifystamp" timestamp DEFAULT now(),
|
---|
[284] | 105 | "privdata" text DEFAULT '' NOT NULL,
|
---|
[347] | 106 | "custid" character varying(16) DEFAULT '',
|
---|
[316] | 107 | swip character(1) DEFAULT 'n'
|
---|
[74] | 108 | );
|
---|
| 109 |
|
---|
| 110 | REVOKE ALL on "allocations" from PUBLIC;
|
---|
| 111 | GRANT ALL on "allocations" to "ipdb";
|
---|
| 112 |
|
---|
[285] | 113 | CREATE VIEW "searchme" as SELECT allocations.cidr, allocations.custid, allocations."type", allocations.city, allocations.description, allocations.notes FROM allocations UNION SELECT poolips.ip, poolips.custid, poolips.type, poolips.city, poolips.description, poolips.notes FROM poolips;
|
---|
[92] | 114 |
|
---|
[176] | 115 | REVOKE ALL on "searchme" from PUBLIC;
|
---|
| 116 | GRANT ALL on "searchme" to "ipdb";
|
---|
| 117 |
|
---|
[92] | 118 | CREATE TABLE "alloctypes" (
|
---|
[176] | 119 | "type" character(2) DEFAULT '' NOT NULL PRIMARY KEY,
|
---|
[92] | 120 | "listname" character varying(40) DEFAULT '',
|
---|
| 121 | "dispname" character varying(40) DEFAULT '',
|
---|
| 122 | "listorder" integer DEFAULT 0,
|
---|
[324] | 123 | "def_custid" character varying(16) DEFAULT '',
|
---|
[347] | 124 | "arin_netname" character varying(20) DEFAULT 'ISP'
|
---|
[92] | 125 | );
|
---|
| 126 |
|
---|
[321] | 127 | --
|
---|
| 128 | -- Name: alloctypes; Type: TABLE DATA; Schema: public; Owner: ipdb
|
---|
| 129 | --
|
---|
| 130 |
|
---|
[324] | 131 | COPY "alloctypes" FROM stdin;
|
---|
| 132 | cn Customer netblock Customer netblock 0 ISPCUST
|
---|
| 133 | si Static IP - Server pool Server pool IP 20 6750400 ISP
|
---|
| 134 | ci Static IP - Cable Static cable IP 21 ISP
|
---|
| 135 | di Static IP - DSL Static DSL IP 22 ISP
|
---|
| 136 | mi Static IP - Dialup Static dialup IP 23 ISP
|
---|
| 137 | wi Static IP - Wireless Static wireless IP 24 ISP
|
---|
| 138 | sd Static Pool - Servers Server pool 40 6750400 ISP
|
---|
| 139 | cd Static Pool - Cable Cable pool 41 CBL-BUS ISP-STATIC-CABLE
|
---|
| 140 | dp Static Pool - DSL DSL pool 42 DSL-BUS ISP-STATIC-DSL
|
---|
| 141 | mp Static Pool - Dialup Static dialup pool 43 DIAL-BUS ISP-STATIC-DIAL
|
---|
| 142 | wp Static Pool - Wireless Static wireless pool 44 WL-BUS ISP-STATIC-WIFI
|
---|
| 143 | en End-use netblock End-use netblock 100 6750400 ISP
|
---|
| 144 | me Dialup netblock Dialup netblock 101 DIAL-RES ISP-DIAL
|
---|
| 145 | de Dynamic DSL block Dynamic DSL block 102 DSL-RES ISP-DSL
|
---|
| 146 | ce Dynamic cable block Dynamic cable block 103 CBL-RES ISP-CABLE
|
---|
| 147 | we Dynamic WiFi block Dynamic WiFi block 104 WL-RES ISP-WIFI
|
---|
| 148 | ve Dynamic VoIP block Dynamic VoIP block 105 DYN-VOIP ISP
|
---|
[370] | 149 | li Static IP - LAN/POP Static LAN/POP IP 190 NOC-VPN ISP
|
---|
| 150 | li Static IP - Management Static management IP 191 NOC-VPN ISP
|
---|
| 151 | ld Static Pool - LAN/POP LAN pool 195 NOC-VPN ISP
|
---|
| 152 | ld Static Pool - Management Management pool 196 NOC-VPN ISP
|
---|
| 153 | in Internal netblock Internal netblock 199 6750400 ISP
|
---|
[324] | 154 | wc Reserve for CORE/WAN blocks CORE/WAN blocks 200 6750400 ISP
|
---|
| 155 | pc Reserve for dynamic-route DSL netblocks Dynamic-route netblocks 201 6750400 ISP-STATIC-DSL
|
---|
| 156 | ac Reserve for ATM ATM blocks 202 6750400 ISP
|
---|
[347] | 157 | fc Reserve for fibre Fibre blocks 203 6750400 ISP
|
---|
[324] | 158 | wr CORE/WAN block CORE/WAN block 220 6750400 ISP
|
---|
| 159 | pr Dynamic-route DSL netblock Dynamic-route DSL 221 ISP
|
---|
| 160 | ar ATM block ATM block 222 ISP
|
---|
[347] | 161 | fr Fibre Fibre 223 ISP
|
---|
[324] | 162 | rm Routing Routed netblock 500 6750400 ISP
|
---|
| 163 | mm Master block Master block 999 6750400 ISP
|
---|
[182] | 164 | \.
|
---|
[218] | 165 |
|
---|
[316] | 166 | REVOKE ALL on "alloctypes" from PUBLIC;
|
---|
| 167 | GRANT ALL on "alloctypes" to "ipdb";
|
---|
| 168 |
|
---|
| 169 | CREATE TABLE "cities" (
|
---|
| 170 | "id" serial NOT NULL PRIMARY KEY,
|
---|
| 171 | "city" character varying(30) DEFAULT '' NOT NULL,
|
---|
| 172 | "routing" character(1) DEFAULT 'n' NOT NULL
|
---|
| 173 | );
|
---|
| 174 |
|
---|
| 175 | REVOKE ALL on "cities" from PUBLIC;
|
---|
| 176 | GRANT ALL on "cities" to "ipdb";
|
---|
| 177 |
|
---|
[218] | 178 | --
|
---|
| 179 | -- Trigger and matching function to update modifystamp on allocations, poolips
|
---|
| 180 | --
|
---|
| 181 | CREATE FUNCTION up_modtime () RETURNS OPAQUE AS '
|
---|
| 182 | BEGIN
|
---|
| 183 | NEW.modifystamp := ''now'';
|
---|
| 184 | RETURN NEW;
|
---|
| 185 | END;
|
---|
| 186 | ' LANGUAGE 'plpgsql';
|
---|
| 187 |
|
---|
| 188 | CREATE TRIGGER up_modtime BEFORE UPDATE ON allocations
|
---|
| 189 | FOR EACH ROW EXECUTE PROCEDURE up_modtime();
|
---|
| 190 |
|
---|
| 191 | CREATE TRIGGER up_modtime BEFORE UPDATE ON poolips
|
---|
| 192 | FOR EACH ROW EXECUTE PROCEDURE up_modtime();
|
---|
[233] | 193 |
|
---|
| 194 | --
|
---|
| 195 | -- User data table - required for proper ACLs
|
---|
| 196 | --
|
---|
| 197 |
|
---|
| 198 | CREATE TABLE "users" (
|
---|
[237] | 199 | "username" varchar(16) NOT NULL PRIMARY KEY,
|
---|
[233] | 200 | "password" varchar(16) DEFAULT '',
|
---|
| 201 | "acl" varchar(16) DEFAULT 'b'
|
---|
| 202 | );
|
---|
[257] | 203 |
|
---|
[347] | 204 | -- Default password is admin
|
---|
| 205 | INSERT INTO users VALUES ('admin','luef5C4XumqIs','bacdsA');
|
---|
| 206 |
|
---|
[257] | 207 | CREATE TABLE "dns" (
|
---|
| 208 | "ip" inet NOT NULL PRIMARY KEY,
|
---|
| 209 | "hostname" character varying(128),
|
---|
| 210 | "auto" character(1) DEFAULT 'y'
|
---|
| 211 | );
|
---|