1#!/usr/bin/perl -w 2#!/usr/local/bin/perl -w 3#!/opt/perl/bin/perl -w 4# 5# Copyright (C) 1999 Mark Baysinger (mbaysing@ucsd.edu) 6# Copyright (C) 1999,2000,2001 Ross Combs (rocombs@cs.nmsu.edu) 7# Copyright (C) 2001 Roland Haeder (webmaster@ai-project-now.de) 8# 9# This program is free software; you can redistribute it and/or 10# modify it under the terms of the GNU General Public License 11# as published by the Free Software Foundation; either version 2 12# of the License, or (at your option) any later version. 13# 14# This program is distributed in the hope that it will be useful, 15# but WITHOUT ANY WARRANTY; without even the implied warranty of 16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17# GNU General Public License for more details. 18# 19# You should have received a copy of the GNU General Public License 20# along with this program; if not, write to the Free Software 21# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 23# Version of this script 24$version = "v1.05"; 25 26# modify to use correct locations 27$infile = "./bnetdlist.txt"; 28#$infile = "/var/tmp/bnetdlist.txt"; 29$outfile = "./bnetdlist.html"; 30#$outfile = "/home/httpd/html/bnetdlist.html"; 31$tmpfile = $outfile . ".temp"; 32 33# document look 34$page_bg_color = "#202020"; 35$link_color = "#5070FF"; 36$alink_color = "#FF3030"; 37$vlink_color = "#8090FF"; 38$tbl_border_color = "#404040"; 39$tbl_border_ramp = "0"; 40$tbl_border_width = "2"; 41$tbl_padding = "1"; 42$tbl_head_bg_color = "$tbl_border_color"; 43$tbl_bg_color = "#000000"; 44$tbl_text_color = "#80A0FF"; 45$title_bg_color = "$page_bg_color"; 46$title_text_color = "#FFFFFF"; 47$sum_bg_color = "$page_bg_color"; 48$sum_text_color = "$title_text_color"; 49 50# header strings 51$title = "BNETD Server Status"; 52$header = "<br>$title<br>"; 53 54 55 56open(INFILE, "<$infile") || die("Can't open \"$infile\" for reading: $!\n"); 57$/ = "\#\#\#\n"; 58@servers = <INFILE>; 59chomp @servers; 60close INFILE; 61 62 63open(OUTFILE, ">$tmpfile") || die("Can't open \"$tmpfile\" for writing: $!\n"); 64 65print OUTFILE "<html>\n"; 66print OUTFILE "<head>\n"; 67print OUTFILE " <meta name=\"GENERATOR\" content=\"process.pl $version\">\n"; 68print OUTFILE " <title>$title</title>\n"; 69print OUTFILE "</head>\n"; 70print OUTFILE "<body bgcolor=\"$page_bg_color\" text=\"$tbl_text_color\" link=\"$link_color\" vlink=\"$vlink_color\" alink=\"$alink_color\">\n"; 71print OUTFILE " <font face=\"Verdana,Helvetica,Arial\">\n"; 72 73print OUTFILE " <table border=\"0\" width=\"100%\">\n"; 74print OUTFILE " <tr>\n"; 75print OUTFILE " <td align=middle bgcolor=\"$title_bg_color\"><font color=\"$title_text_color\">$header</font><br></td>\n"; 76print OUTFILE " </tr>\n"; 77print OUTFILE " <tr>\n"; 78print OUTFILE " <td align=middle>\n"; 79print OUTFILE " <table border=\"0\" cellspacing=\"0\" bgcolor=\"$tbl_border_color\">\n"; 80print OUTFILE " <tr>\n"; 81print OUTFILE " <td>\n"; 82print OUTFILE " <table border=\"$tbl_border_ramp\" cellspacing=\"$tbl_border_width\" cellpadding=\"$tbl_padding\" bgcolor=\"$tbl_bg_color\">\n"; 83print OUTFILE " <tr>\n"; 84print OUTFILE " <th bgcolor=\"$tbl_head_bg_color\"><font size=2>Address</font></th>\n"; 85print OUTFILE " <th bgcolor=\"$tbl_head_bg_color\"><font size=2>Location</font></th>\n"; 86print OUTFILE " <th bgcolor=\"$tbl_head_bg_color\"><font size=2>Description</font></th>\n"; 87print OUTFILE " <th bgcolor=\"$tbl_head_bg_color\"><font size=2>URL</font></th>\n"; 88print OUTFILE " <th bgcolor=\"$tbl_head_bg_color\"><font size=2>Uptime</font></th>\n"; 89print OUTFILE " <th bgcolor=\"$tbl_head_bg_color\"><font size=2>Contact</font></th>\n"; 90print OUTFILE " <th bgcolor=\"$tbl_head_bg_color\"><font size=2>Software</font></th>\n"; 91print OUTFILE " <th bgcolor=\"$tbl_head_bg_color\"><font size=2>U</font></th>\n"; 92print OUTFILE " <th bgcolor=\"$tbl_head_bg_color\"><font size=2>C</font></th>\n"; 93print OUTFILE " <th bgcolor=\"$tbl_head_bg_color\"><font size=2>G</font></th>\n"; 94print OUTFILE " </tr>\n"; 95 96$allservers = 0; 97$allusers = 0; 98$allgames = 0; 99 100foreach $server (@servers) { 101 print OUTFILE " <tr>\n"; 102 $/ = "\#\#\n"; 103 104 # Fix-up for special characters 105 $server =~ s/&/&/g; 106 $server =~ s/</</g; 107 $server =~ s/>/>/g; 108 109 @serverinfo = split /^\#\#\n/m, $server; 110 chomp @serverinfo; 111 chop @serverinfo; 112 113 # put fields into descriptive variable names 114 $addr = $serverinfo[0]; 115 116 $loc = $serverinfo[2]; 117 if (length($loc)<1) { 118 $loc = " "; 119 } 120 $desc = $serverinfo[8]; 121 if (length($desc)<1) { 122 $desc = " "; 123 } 124 125 $soft = $serverinfo[3] . " " . $serverinfo[4]; 126 $osys = $serverinfo[9]; 127 if (length($osys)<1) { 128 $osys = "unknown"; 129 } 130 131 $url = $serverinfo[10]; 132 133 $contact = $serverinfo[11]; 134 if (length($contact)<1) { 135 $contact = " "; 136 } 137 $email = $serverinfo[12]; 138 139 $currusers = $serverinfo[5]; 140 $totusers = $serverinfo[15]; 141 142 $currchans = $serverinfo[6]; 143 144 $currgames = $serverinfo[7]; 145 $totgames = $serverinfo[14]; 146 147 $uptime = sprintf("%02d:%02d:%02d",int $serverinfo[13]/3600, int ($serverinfo[13]%3600)/60, int $serverinfo[13]%60); 148 149 # print it out 150 print OUTFILE " <td><font size=1><a href=\"bnetd://$addr/\">$addr</a></font></td>\n"; # IP 151 print OUTFILE " <td><font size=1>$loc</font></td>\n"; 152 print OUTFILE " <td><font size=1>$desc</font></td>\n"; 153 if (length($url)<1) { 154 print OUTFILE " <td><font size=1> </font></td>\n"; 155 } else { 156 print OUTFILE " <td><a href=\"$url\"><font size=1>$url</font></a></td>\n"; 157 } 158 print OUTFILE " <td align=right><font size=1>$uptime</font></td>\n"; 159 if (length($email)<1) { 160 print OUTFILE " <td><font size=1>$contact</font></td>\n"; 161 } else { 162 print OUTFILE " <td><font size=1>$contact <a href=\"mailto:$email\">($email)</a></font></td>\n"; 163 } 164 print OUTFILE " <td><font size=1>$soft<br>$osys</font></td>\n"; 165 print OUTFILE " <td align=right><font size=1>${currusers}c<br>${totusers}t</font></td>\n"; 166 print OUTFILE " <td align=right><font size=1>${currchans}</font></td>\n"; 167 print OUTFILE " <td align=right><font size=1>${currgames}c<br>${totgames}t</font></td>\n"; 168 print OUTFILE " </tr>\n"; 169 170 $allservers++; 171 $allusers+=${currusers}; 172 $allgames+=${currgames}; 173} 174 175print OUTFILE " </table>\n"; 176print OUTFILE " </td>\n"; 177print OUTFILE " </tr>\n"; 178print OUTFILE " </table>\n"; 179print OUTFILE " <br><br>\n"; 180print OUTFILE " </td>\n"; 181print OUTFILE " </tr>\n"; 182 183print OUTFILE " <tr>\n"; 184print OUTFILE " <td align=middle><table border=\"0\">\n"; 185print OUTFILE " <tr>\n"; 186print OUTFILE " <td align=middle bgcolor=\"$sum_bg_color\">\n"; 187print OUTFILE " <font size=2 color=\"$sum_text_color\">\n"; 188print OUTFILE " servers: " . $allservers . "<br>\n"; 189print OUTFILE " users: " . $allusers . "<br>\n"; 190print OUTFILE " games: " . $allgames . "<br>\n"; 191print OUTFILE " <br>\n"; 192print OUTFILE " Last updated " . gmtime(time) . " GMT<br>\n"; 193print OUTFILE " </font><br>\n"; 194print OUTFILE " </td>\n"; 195print OUTFILE " </tr>\n"; 196print OUTFILE " </table></td>\n"; 197print OUTFILE " </tr>\n"; 198 199print OUTFILE " </table>\n"; 200print OUTFILE " </font>\n"; 201print OUTFILE "</body></html>\n"; 202 203close(OUTFILE); 204 205unlink($outfile); 206rename($tmpfile, $outfile); 207 208exit(0); 209 210