]> andersk Git - moira.git/blame_incremental - gen/ip-billing.gen
Add pointer to a file allowing us to deny users printing access.
[moira.git] / gen / ip-billing.gen
... / ...
CommitLineData
1#!/moira/bin/perl -Tw
2
3# $Id$
4# The following exit codes are defined and MUST BE CONSISTENT with the
5# error codes the library uses:
6$MR_DBMS_ERR = 47836421;
7$MR_OCONFIG = 47836460;
8
9$ENV{PATH} = "/bin:/usr/bin:/sbin:/usr/sbin";
10
11$outdir = '/moira/dcm/ip-billing';
12$outfile = '/moira/dcm/ip-billing.out';
13$outdat = '/moira/dcm/ip-billing/moira.dat';
14$outctl = '/moira/dcm/ip-billing/moira.ctl';
15$count = 0;
16
17use DBI;
18
19umask 022;
20open(DAT, ">$outdat") || exit $MR_OCONFIG;
21open(CTL, ">$outctl") || exit $MR_OCONFIG;
22
23$dbh = DBI->connect("dbi:Oracle:moira", "moira", "moira")
24 || exit $MR_DBMS_ERR;
25
26# First report all the NETWK-A hosts.
27$sth = $dbh->prepare("SELECT m.address, m.location, m.name, m.contact, " .
28 "m.billing_contact, m.account_number, m.created, " .
29 "m.modtime FROM machine m, subnet s WHERE m.status = 1 " .
30 "AND m.snet_id = s.snet_id AND s.status = 1 " .
31 "AND m.address != 'unassigned' ORDER BY m.address")
32 || exit $MR_DBMS_ERR;
33
34$sth->execute || exit $MR_DBMS_ERR;
35
36while (($address, $location, $name, $contact, $billingcontact, $accountnumber, $created, $modtime) =
37 $sth->fetchrow_array) {
38 $row = "$address\t$location\t$name\t$contact\t$billingcontact\t$accountnumber\t+NETWK-A\t$created\t$modtime\n";
39 $row =~ s/\0//g;
40 print DAT $row;
41 $count++;
42}
43
44# Next we do the private subnets.
45# +NETWK-10P.
46$sth = $dbh->prepare("SELECT s.saddr, s.name, s.contact, " .
47 "s.account_number, s.modtime FROM subnet s " .
48 "WHERE s.status = 2 ORDER BY s.saddr")
49 || exit $MR_DBMS_ERR;
50
51$sth->execute || exit $MR_DBMS_ERR;
52
53while (($saddr, $name, $contact, $accountnumber, $modtime) =
54 $sth->fetchrow_array) {
55 @addr = unpack("C4", pack("N", $saddr));
56 $address = "$addr[0].$addr[1].$addr[2].$addr[3]";
57 # Blank field between contact and account number below because that's
58 # where the billing contact would go if we had it for subnets.
59 $row = "$address\t\t$name\t$contact\t\t$accountnumber\t+NETWK-10P\t\t$modtime\n";
60 $row =~ s/\0//g;
61 print DAT $row;
62 $count++;
63}
64
65# +NETWK-100P
66$sth = $dbh->prepare("SELECT s.saddr, s.name, s.contact, " .
67 "s.account_number, s.modtime FROM subnet s " .
68 "WHERE s.status = 3 ORDER BY s.saddr")
69 || exit $MR_DBMS_ERR;
70
71$sth->execute || exit $MR_DBMS_ERR;
72
73while (($saddr, $name, $contact, $accountnumber, $modtime) =
74 $sth->fetchrow_array) {
75 @addr = unpack("C4", pack("N", $saddr));
76 $address = "$addr[0].$addr[1].$addr[2].$addr[3]";
77 # Blank field between contact and account number below because that's
78 # where the billing contact would go if we had it for subnets.
79 $row = "$address\t\t$name\t$contact\t\t$accountnumber\t+NETWK-100P\t\t$modtime\n";
80 $row =~ s/\0//g;
81 print DAT $row;
82 $count++;
83}
84
85# +NETWK-1000P
86$sth = $dbh->prepare("SELECT s.saddr, s.name, s.contact, " .
87 "s.account_number, s.modtime FROM subnet s " .
88 "WHERE s.status = 7 ORDER BY s.saddr")
89 || exit $MR_DBMS_ERR;
90
91$sth->execute || exit $MR_DBMS_ERR;
92
93while (($saddr, $name, $contact, $accountnumber, $modtime) =
94 $sth->fetchrow_array) {
95 @addr = unpack("C4", pack("N", $saddr));
96 $address = "$addr[0].$addr[1].$addr[2].$addr[3]";
97 # Blank field between contact and account number below because that's
98 # where the billing contact would go if we had it for subnets.
99 $row = "$address\t\t$name\t$contact\t\t$accountnumber\t+NETWK-1000P\t\t$modtime\n";
100 $row =~ s/\0//g;
101 print DAT $row;
102 $count++;
103}
104
105# +NETWK-DORM
106$sth = $dbh->prepare("SELECT m.address, m.location, m.name, m.contact, " .
107 "m.billing_contact, m.account_number, m.created, " .
108 "m.modtime FROM machine m, subnet s WHERE m.status = 1 " .
109 "AND m.snet_id = s.snet_id AND " .
110 "s.status = 5 AND m.address != 'unassigned' " .
111 "ORDER BY m.address")
112 || exit $MR_DBMS_ERR;
113
114$sth->execute || exit $MR_DBMS_ERR;
115
116while (($address, $location, $name, $contact, $billingcontact, $accountnumber, $created, $modtime) =
117 $sth->fetchrow_array) {
118 $row = "$address\t$location\t$name\t$contact\t$billingcontact\t$accountnumber\t+NETWK-DORM\t$created\t$modtime\n";
119 $row =~ s/\0//g;
120 print DAT $row;
121 $count++;
122}
123
124# +NETWK-FSILG
125$sth = $dbh->prepare("SELECT m.address, m.location, m.name, m.contact, " .
126 "m.billing_contact, m.account_number, m.created, " .
127 "m.modtime FROM machine m, subnet s WHERE m.status = 1 " .
128 "AND m.snet_id = s.snet_id AND " .
129 "s.status = 8 AND m.address != 'unassigned' " .
130 "ORDER BY m.address")
131 || exit $MR_DBMS_ERR;
132
133$sth->execute || exit $MR_DBMS_ERR;
134
135while (($address, $location, $name, $contact, $billingcontact, $accountnumber, $created, $modtime) =
136 $sth->fetchrow_array) {
137 $row = "$address\t$location\t$name\t$contact\t$billingcontact\t$accountnumber\t+NETWK-FSILG\t$created\t$modtime\n";
138 $row =~ s/\0//g;
139 print DAT $row;
140 $count++;
141}
142
143# +NETWK-OCS
144$sth = $dbh->prepare("SELECT m.address, m.location, m.name, m.contact, " .
145 "m.billing_contact, m.account_number, m.created, " .
146 "m.modtime FROM machine m, subnet s WHERE m.status = 1 " .
147 "AND m.snet_id = s.snet_id AND " .
148 "s.status = 6 AND s.name LIKE '%-DHREG' " .
149 "AND m.address != 'unassigned' ORDER BY m.address")
150 || exit $MR_DBMS_ERR;
151
152$sth->execute || exit $MR_DBMS_ERR;
153
154while (($address, $location, $name, $contact, $billingcontact, $accountnumber, $created, $modtime) =
155 $sth->fetchrow_array) {
156 $row = "$address\t$location\t$name\t$contact\t$billingcontact\t$accountnumber\t+NETWK-OCS\t$created\t$modtime\n";
157 $row =~ s/\0//g;
158 print DAT $row;
159 $count++;
160}
161
162# +NETWK-0
163$sth = $dbh->prepare("SELECT m.address, m.location, m.name, m.contact, " .
164 "m.billing_contact, m.account_number, m.created, " .
165 "m.modtime FROM machine m, subnet s WHERE m.status = 1 " .
166 "AND m.snet_id = s.snet_id AND " .
167 "(s.status = 4 OR s.status = 6) AND " .
168 "s.name NOT LIKE '%-DHREG' " .
169 "AND m.address != 'unassigned' ORDER BY m.address")
170 || exit $MR_DBMS_ERR;
171
172$sth->execute || exit $MR_DBMS_ERR;
173
174while (($address, $location, $name, $contact, $billingcontact, $accountnumber, $created, $modtime) =
175 $sth->fetchrow_array) {
176 $row = "$address\t$location\t$name\t$contact\t$billingcontact\t$accountnumber\t+NETWK-0\t$created\t$modtime\n";
177 $row =~ s/\0//g;
178 print DAT $row;
179 $count++;
180}
181
182print CTL "$count\n";
183close(CTL);
184close(DAT);
185
186system("cd $outdir && tar cf $outfile .") == 0 || exit $MR_OCONFIG;
187
188$dbh->disconnect;
189
190exit 0;
This page took 0.040116 seconds and 5 git commands to generate.