forked from KA8SCP/reg-check
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dstar-regcheck
396 lines (335 loc) · 15.1 KB
/
dstar-regcheck
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
#!/usr/bin/perl
#
# DStar-Registrierungs-Check
#
# (C) Hans-J. Barthen, DL5DI
# Franz-Josef-Str. 20
# D-56642 Kruft
#
# 2009-09-19 start of development
# 2009-12-29 find more errors (double registration, terminals registered at dif
# 2010-01-25 show IP address range (startip + 7)
# 2010-01-26 check if terminal-IP is in dedicated IP-range
# 2010-04-01 check for terminals even if no user registration exists
# 2010-09-15 check for database entries created by ircDDB
# 2010-09-17 first multi-language version
# 2010-09-22 bugfix, text $t21 (hit-counter) was accidently called $t20
# 2010-10-17 bugfix, hitcounter not set before use
# 2010-12-17 converted to Hamnet
# 2012-03-28 check if callsign is a registered gateway
use LWP::Simple;
use CGI;
$| = 1; # flush print and write
$rev = "2017/03/16";
$owncall = "GW-CALL";
if(substr($ENV{'HTTP_ACCEPT_LANGUAGE'}, 0, 2) eq "de"){
$language = "DE";
$t00 = "<td><b><font size=+2>DStar-Gateway Registrierungs-Check</center></font></b></td>";
$t01 = "<hr><center><form action=\"/cgi-bin/dstar-regcheck\" method=get>Callsign:<input name=\"callsign\" size=10 maxlength=7 value=\"\"><input TYPE=\"SUBMIT\" VALUE=\"SUCHE\"></form></center>";
} else {
$t00 = "<td><b><font size=+2>DStar-Gateway Registration Check</center></font></b></td>";
$t01 = "<hr><center><form action=\"/cgi-bin/dstar-regcheck\" method=get>Callsign:<input name=\"callsign\" size=10 maxlength=7 value=\"\"><input TYPE=\"SUBMIT\" VALUE=\"SUBMIT\"></form></center>";
}
###################### HTTP-Header ########################
print(CGI::header());
###################### HTML-Header ########################
print("<!doctype html public \"-//w3c//dtd html 4.0 transitional//en\">");
print("<html>");
print("<head>");
print(" <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">");
print(" <meta name=\"Author\" content=\"Hans-Juergen Barthen, DL5DI\">");
print(" <meta name=\"GENERATOR\" content=\"dstar-regcheck.pl DL5DI 12/2009\">");
print(" <META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">");
print(" <title>DStar-Repeater/Gateway - $owncall<br>Registration-Check</title>");
print("</head>");
print("<body>");
print("<table CELLPADDING=5>");
print("<tr>");
print("<td>");
print("<table CELLPADDING=5>");
print("<tr>");
print("<td><a href=\"/\"><img SRC=\"/img/d-star-logo.gif\" BORDER=0 height=60 width=120></a></td>");
print"$t00";
print("</tr>");
print("</table>");
print("<p> ");
print"$t01";
print("<hr>");
print(" <br>");
$callsign = CGI::param('callsign');
if($callsign){
$callsign =~ tr/a-z/A-Z/;
use DBI;
my $dbname = "dstar_global";
my $user = "dstar";
my $pass = "icom";
my $hostname = "127.0.0.1";
my $table1 = "sync_rip";
my $table2 = "sync_mng";
my $table3 = "sync_gip";
($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst)=gmtime(time);
$mon++;
$year+=1900;
my $Timestamp = sprintf("%4.4d/%2.2d/%2.2d %2.2d:%2.2d",$year,$mon,$day,$hour,$min);
# read and increase hit counter
if (open(CNTFILE, "/tmp/dstar-regcheck.cnt")) {
$cnt = <CNTFILE>;
close(CNTFILE);
chop($cnt);
$cnt++;
} else {
$cnt = 1;
}
# write counter back to file
if (open(CNTFILE, ">/tmp/dstar-regcheck.cnt")) {
printf(CNTFILE "$cnt\n");
close(CNTFILE);
}
if($language eq "DE"){
$t1 = "<p><br><font size=+1><center><b>Registrierungs-Info:</b></center></font>"; # Ueberschrift
$t2 = "<tr><td><center>Registr.Call</center></td><td><center>Registrierungsserver</center></td><td><center>Datum der Registrierung</center></td><td><center>IP-Address-Pool</center></td></tr>"; # Tabelle 1
$t3 = "<BR><font size=+1><b>Es existiert keine Registrierung!</b></font><P>";
$t4 = "<br><font size=+1><center><b>Folgender Registrierungs-Eintrag wurde gelöscht:</b></center></font><br>";
$t5 = "<tr><td><center>Call/ID</center></td><td><center>Registrierungsserver</center></td><td><center>Löschdatum</center></td></tr>";
$t6 = "<p><br><font size=+1><center><b>Dieser Eintrag wurde lokal von ircDDB generiert</center></font>";
$t7 = "<p><br><font size=+1><center><b>Fälschlicherweise noch aktivierte <a href=\"/DStarTerminalIDs.html\" >Terminal-IDs:</a></b></center></font>";
$t8 = "<p><br><font size=+1><center><b>Aktivierte <a href=\"/DStarTerminalIDs.html\" >Terminal-IDs:</a></b></center></font>";
$t9 = "<tr><td><center>Device Call/ID</center></td><td><center>Registrierungsserver</center></td><td><center>IP-Adresse</center></td><td><center>Letztmals gehört</center></td><td><center> Repeater </center></td><td><center> Gateway </center></td></tr>";
$t10 = "<BR><font size=+1><b>Mehrfachregistrierung!</b></font>";
$t11 = "<BR><font size=+1><b>Terminalanmeldung fehlerhaft!</b></font>";
$t12 = "<BR><font size=+1><b>Fehlender Eintrag mit leerer ID / Leerzeichen!</b></font>";
$t13 = "<BR><font size=+1><b>Registrierung bitte beim Registrierungs server <font size=+2><a href=\"https://REGSRV.dstargateway.org/Dstar.do\">REGSRV</a></font> komplettieren!</b></font>";
$t14 = "<BR><font size=+1><b>Mehr Informationen zum <a href=\"https://regist.dstargateway.org/instructions/\">Registrierungsvorgang hier!</a></b></font>";
#TODO Need new translation and links
$t15 = "<P><font size=+1 color=red><b>Registrierung NICHT OK!</b></font>";
$t16 = "<P><font size=+1 color=red><b>Registrierung NICHT OK!<br>(IP ausserhalb des zugewiesenen Adress-Pools)</b></font>";
$t17 = "<P><font size=+1><b>Registrierung OK!</b></font>";
$t18 = "<P><font size=+1><b>Terminalanmeldung OK für ircDDB-Netzwerk!</b></font>";
$t19 = "<center><br><font size=+1><b>Existierende Terminals müssen vom Admin des neuen<br>Registrierungs-Servers gelöscht werden.<br>Bitte nach dem ersten Registrierungsschritt bei ihm melden!</b></font><p>";
$t20 = "<BR><center><font size=+1><a href=\"https://regist.dstargateway.org/instructions/\" target =\"_blank\" > Registrierung z.B. hier bei $owncall </a></font><BR>";
$t21 = "<center><i>$cnt Abrufe seit 20090817</font></i><br>"; # Abrufe seit Installationsdatum - einfuegen !!
$t22 = " ist ein registriertes <a href=\"http://www.dstarusers.org/repeaters.php\" target=\"_blank\">US-Trust-Gateway</a>";
$t23 = " ist ein registriertes <a href=\"http://status.ircddb.net/cgi-bin/ircddb-gwst\" target=\"_blank\">ircDDB-Gateway</a>";
$t24 = "<BR>Bei einem Gateway sollte die leere ID (Leerzeichen) <u>NICHT</u><br> registriert sein, da dies Routingprobleme verursachen kann!<br>";
} else {
$t1 = "<p><br><font size=+1><center><b>Registration Information:</b></center></font>"; # Headline
$t2 = "<tr><td><center>Registr.Call</center></td><td><center>Registration Server</center></td><td><center>Date of Registration</center></td><td><center>IP-Address-Pool</center></td></tr>"; # table 1
$t3 = "<BR><font size=+1><b>No Registration!</b></font><P>";
$t4 = "<br><font size=+1><center><b>The following Registration-Record had been erased:</b></center></font><br>";
$t5 = "<tr><td><center>Call/ID</center></td><td><center>Registration Server</center></td><td><center>Date of erase</center></td></tr>";
$t6 = "<p><br><font size=+1><center><b>This entry was created locally by ircDDB</center></font>";
$t7 = "<p><br><font size=+1><center><b>Orphan <a href=\"/DStarTerminalIDs.html\" >Terminal-IDs:</a></b></center></font>";
$t8 = "<p><br><font size=+1><center><b>Activated <a href=\"/DStarTerminalIDs.html\" >Terminal-IDs:</a></b></center></font>";
$t9 = "<tr><td><center>Device Call/ID</center></td><td><center>Registration Server</center></td><td><center>IP-Address</center></td><td><center>Last Heard</center></td><td><center> Repeater </center></td><td><center> Gateway </center></td></tr>";
$t10 = "<BR><font size=+1><b>Multi Registration!</b></font>";
$t11 = "<BR><font size=+1><b>Wrong Terminal registration!</b></font>";
$t12 = "<BR><font size=+1><b>Missing Eintry with Space-ID!</b></font>";
$t13 = "<BR><font size=+1><b>Please complete registration at Registration server <font size=+2><a href=\"https://REGSRV.dstargateway.org/Dstar.do\">REGSRV</a></font> !</b></font>";
$t14 = "<BR><font size=+1><b>More informationen on the <a href=\"https://regist.dstargateway.org/instructions/\">registration process!</a></b></font>";
$t15 = "<p><font size=+1 color=red><b>Please verify this registration at <a href=\"http://dstar.info/query.html\" target=\"_blank\">Trust Server Database Direct Inquiry</a> or at <a href=\"https://regist.dstargateway.org/regcheck/index.php\" target=\"_blank\">REGIST Registration Validation</a></b></font>";
$t16 = "<P><font size=+1 color=red><b>Registration NOT OK!<br>(IP outside of assigned pool!)</b></font>";
$t17 = "<P><font size=+1><b>Registration OK!</b></font>";
$t18 = "<P><font size=+1><b>Registration OK for ircDDB-Network!</b></font>";
$t19 = "<center><br><font size=+1><b>Existing Terminals have to be deleted by the Admin of the <br>new Registration-Servers.<br>Please contact him after the first step of the Registration process!</b></font><p>";
$t20 = "<BR><center><font size=+1><a href=\"https://regist.dstargateway.org/instructions/\" target =\"_blank\" > Registration is possible at $owncall </a></font>";
$t21 = "<center><i>$cnt hits since 20100917</font></i><br>"; # hits since installation - enter installation date here !
$t22 = " is a registered <a href=\"http://www.dstarusers.org/repeaters.php\" target=\"_blank\">US-trust gateway</a>";
$t23 = " is a registered <a href=\"http://status.ircddb.net/cgi-bin/ircddb-gwst\" target=\"_blank\">ircDDB gateway</a>";
$t24 = "<BR>The Space-ID should <u>NOT</u> be registered for a gateway, it may create routing issues!<br>";
}
#----- connect db -------
my $dsn = "DBI:Pg:database=$dbname;host=$hostname";
my $dbh = DBI->connect( $dsn, $user, $pass ) || die DBI::errstr;
#----- read table1 ------
$sql= "SELECT regist_rp_cs, last_mod_time, start_ipaddr FROM $table1 WHERE user_cs = '$callsign' And del_flg = 'FALSE'";
#print "SQL-Command: $sql\n";
$sth = $dbh->prepare($sql);
$num = $sth->execute();
######################################################################
# Table start
print"$t1";
print("<center><table BORDER CELLSPACING=0 CELLPADDING=0 BGCOLOR=\"#33CCFF\" >");
print"$t2";
# my @data = $sth->fetchrow_array;
$rs = 0;
$userreg = 0;
while (my @data = $sth->fetchrow_array) {
$userreg++;
print("<tr>");
printf("<td ALIGN=CENTER>%8s</td>",$callsign); # Terminal Call
printf("<td ALIGN=CENTER>%7s</td>",$data[0]); # Registration Server
if($rs == 0){
$regsrv = $data[0];
}
printf("<td ALIGN=CENTER>%20s</td>",$data[1]); # Last Mod
$startip = $data[2];
($h1,$h2,$h3,$h4) = split(/\./,$startip);
$startipdez = 16777216 * $h1 + 65536 * $h2 + 256 * $h3 + $h4;
$h4 += 7;
$endipdez = $startipdez + 7;
$endip = sprintf("%s.%s.%s.%s",$h1,$h2,$h3,$h4);
printf("<td ALIGN=CENTER>%s-<br>%s</td>",$startip,$endip); # Start IP-Address
print("</tr>");
$rs++;
}
print("</table>");
#print "$rs\n";
if(!$regsrv) {
print"$t3";
my $sql= "SELECT regist_rp_cs, last_mod_time FROM $table1 WHERE user_cs = '$callsign' And del_flg = 'TRUE'";
my $sth = $dbh->prepare($sql);
my $num = $sth->execute();
my @data = $sth->fetchrow_array;
if($data[0]){
# Table start
print "$t4";
print("<center><table BORDER CELLSPACING=0 CELLPADDING=0 BGCOLOR=\"RED\" >");
print "$t5";
print("<tr>");
printf("<td ALIGN=CENTER>%8s</td>",$callsign); # Terminal-Call
printf("<td ALIGN=CENTER>%7s</td>",$data[0]); # Registrierungsserver
printf("<td ALIGN=CENTER>%20s</td>",$data[1]); # Letzte Aenderung
print("</tr>");
print("</table>");
}
}
#----- read table2 ------
my $sql= "SELECT target_cs, last_mod_time, regist_rp_cs, pc_ipaddr, arearp_cs, zonerp_cs, del_flg FROM $table2 WHERE user_cs = '$callsign' And del_flg = 'FALSE'";
#print "SQL-Command: $sql\n";
my $sth = $dbh->prepare($sql);
my $num = $sth->execute();
# Table start
$i = 0;
$sp_entry = 0;
$termerr = 0;
$ircddb = 0;
$iperr = 0;
while (my @data = $sth->fetchrow_array) {
($h1,$h2,$h3,$h4) = split(/\./,$data[3]);
$termipdez = 16777216 * $h1 + 65536 * $h2 + 256 * $h3 + $h4;
if($termipdez == "0.0.0.0"){
$ircddb = 1;
}
if ($i == 0){
if($userreg == 0){
if($ircddb){
print"$t6";
} else {
print"$t7";
}
} else {
print"$t8";
}
print("<center><table BORDER CELLSPACING=0 CELLPADDING=0 BGCOLOR=\"#33CCFF\" >");
print"$t9";
}
print("<tr>");
printf("<td ALIGN LEFT>%8s</td>",$data[0]); # Terminal-Call
printf("<td ALIGN=CENTER>%15s</td>",$data[2]); # RegServ
if($data[3] ne '0.0.0.0' && ($termipdez < $startipdez) || ($termipdez > $endipdez)) {
printf("<td ALIGN=CENTER>%15s</td>",$data[3]); # IP-address
$iperr++;
} else {
printf("<td ALIGN=CENTER>%15s</td>",$data[3]); # IP-address
}
printf("<td ALIGN=CENTER>%20s</td>",$data[1]); # last change
printf("<td ALIGN LEFT>%8s</td>",$data[4]); # ZoneRP
printf("<td ALIGN LEFT>%8s</td>",$data[5]); # AreaRP
print("</tr>");
if($regsrv ne $data[2]) {
$termerr = 1;
}
#print "$termerr\n";
$id = substr($data[0],7,1);
#print"<br>ID:-$id-<br>";
if($id eq " ") {
$sp_entry = 1;
}
$i++;
}
# Table end
if($i > 0){
print("</table>");
}
$err = 0;
#----- check in table 3 if it is a registered US-trust gateway -------
$gateway = 0;
$sql= "SELECT * FROM $table3 WHERE zonerp_cs = '$callsign' And del_flg = 'FALSE'";
#print "SQL-Command: $sql\n";
$sth = $dbh->prepare($sql);
$num = $sth->execute();
$ustrust = $sth->rows();
if($ustrust > 0 && $regsrv =~ m/$callsign/){
printf("<br><b>%s %s</b>",$callsign,$t22);
$gateway = 1;
}
#----- check at ircddb.net if it is a registered ircDDB gateway -------
$url = "https://status.ircddb.net/isgw.php?call=$callsign";
$ircddb = get($url);
if($ircddb > 0){
printf("<br><b>%s %s</b>",$callsign,$t23);
$gateway = 1;
}
if($userreg > 0){
if($rs > 1) {
print"$t10";
$err = 1;
}
if($termerr > 0) {
print"$t11";
$err = 1;
}
if($sp_entry == 0) {
if($gateway == 0){
print"$t12";
$err = 1;
$regsrvA=$regsrv;
$regsrvA =~ s/\s+$//;
$t13 =~ s/REGSRV/$regsrvA/g;
print"$t13";
if(index($regsrv,$owncall) == 0){
print"$t14";
}
}
} else {
if($gateway == 1){
print"$t24";
$err++;
}
}
if($err > 0){
print"$t15";
} elsif ($iperr > 0) {
print"$t16";
} else {
print"$t17";
}
} else {
if ($i > 0){
if($ircddb){
print"$t18";
$err = 0;
} else {
print"$t19";
}
}
if(!$ircddb){
print"$t20";
}
}
#print "<br>US-Trust:$ustrust<br>ircDDB:$ircddb<br>";
print("<BR> <br>");
print"$t21";
print "<center>Status: $Timestamp UTC<br>";
print "<center>Software-Rev.: $rev (dl5di)<br>";
# print "Referer: $ref";
print("</center></table>");
#------ DB close ------
$sth->finish;
$dbh->disconnect;
}
###################### HTML-Footer ################################
#
print("</body>");
print"</html>";
###