]>
Commit | Line | Data |
---|---|---|
19a8d9a0 MT |
1 | #!/usr/bin/python |
2 | ||
3 | import cgitb, os, time, socket, cgi, DNS, GeoIP | |
4 | cgitb.enable() | |
5 | ||
6 | #gi = GeoIP.new(GeoIP.GEOIP_STANDARD) | |
7 | gi = GeoIP.new(GeoIP.GEOIP_MEMORY_CACHE) | |
8 | ||
9 | def print_header(): | |
10 | print '''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | |
11 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
12 | <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> | |
13 | <head> | |
14 | <title>IPFire - Distribution</title> | |
15 | <style type="text/css"> | |
16 | body { font-family: Verdana; font-size: 9pt; background-color:#f0f0f0; } | |
17 | a:link { color: black; text-decoration: none; } | |
18 | a:visited { color: black; text-decoration: none; } | |
19 | table { font-family: Verdana; font-size: 8pt; border: 1px solid; } | |
20 | td.header { background-color: #a0a0a0; text-align: center; color: white; } | |
21 | td.date { text-align: center; } | |
22 | font.installed { color: green; } | |
23 | font.deleted { color: red; } | |
24 | font.update { color: blue; } | |
25 | font.error { color: red; } | |
26 | td.online { background: green; color: white; text-align: center; } | |
27 | td.offline { background: red; color: white; text-align: center; } | |
28 | </style> | |
29 | <meta http-equiv="refresh" content="60; URL=%s?ver=%s&uuid=%s" /> | |
30 | </head> | |
31 | <body> | |
32 | <h1>IPFire Distribution</h1> | |
33 | <p>Made: %s</p>''' % (os.environ['SCRIPT_NAME'], ver, uuid, time.ctime()) | |
34 | ||
35 | def beautify_ip(ip): | |
36 | try: | |
37 | hostname = socket.gethostbyaddr(ip) | |
38 | string = "<b>%s</b> (%s - %s)" % (hostname[0], ip, gi.country_code_by_addr(ip)) | |
39 | except socket.herror, e: | |
40 | error = "Couldn't look up name: %s" % e | |
41 | string = "<b>%s</b> (%s)" % (error, ip) | |
42 | return string | |
d17fcd70 | 43 | |
19a8d9a0 MT |
44 | def beautify_time(timestamp): |
45 | return time.strftime("%d-%m-%Y - %H:%M", time.localtime(float(timestamp))) | |
46 | ||
47 | def get_attributes(line): | |
48 | status = "" | |
49 | pak = "" | |
50 | command = "" | |
51 | args = line.split(" ") | |
52 | ip = args[0] | |
53 | timestamp = args[1] | |
54 | if len(args) > 2: | |
55 | command = args[2] | |
56 | if len(args) > 3: | |
57 | pak = args[3] | |
58 | if len(args) > 4: | |
59 | status = args[4] | |
60 | ||
61 | return ip, timestamp, command, pak, status | |
62 | ||
63 | def showuuid(uuid, ver): | |
64 | print "<h3><a href='%s?ver=%s&uuid=%s#%s'>%s</a></h3>" % (os.environ['SCRIPT_NAME'], dir, uuid, uuid, uuid) | |
d17fcd70 | 65 | |
19a8d9a0 MT |
66 | def summurize_addons(): |
67 | addons={} | |
68 | installed={} | |
69 | upgraded={} | |
70 | deleted={} | |
71 | oldest="9999999999999" | |
72 | newest="0000000000000" | |
73 | for dir in os.listdir("version/"): | |
26d04920 MT |
74 | if (dir == "empty.txt" ): |
75 | pass | |
76 | else: | |
77 | # print dir+"<br />" | |
78 | for uuid in os.listdir("version/"+dir): | |
79 | # print uuid+"<br />" | |
80 | f = open("version/"+dir+"/"+uuid) | |
81 | while True: | |
82 | line = f.readline() | |
83 | if len(line) == 0: | |
84 | break # EOF | |
85 | status = "" | |
86 | pak = "" | |
87 | command = "" | |
88 | args = line.split(" ") | |
89 | if oldest > args[1]: | |
90 | oldest = args[1] | |
91 | if newest < args[1]: | |
92 | newest = args[1] | |
93 | if len(args) > 2: | |
94 | command = args[2] | |
95 | # print command | |
96 | if len(args) > 3: | |
97 | pak = args[3] | |
98 | # print pak | |
99 | if len(args) > 4: | |
100 | status = args[4] | |
101 | # print status+"<br />" | |
102 | if (status == "0\n") and (command == "installed") and (dir == "2.1" or dir == "2.3" ): | |
103 | addons[pak] = addons.get(pak,0)+1 | |
104 | installed[pak] = installed.get(pak,0)+1 | |
105 | if (status == "0\n") and (command == "deleted") and (dir == "2.1" or dir == "2.3"): | |
106 | addons[pak] = addons.get(pak,0)-1 | |
107 | deleted[pak] = deleted.get(pak,0)+1 | |
108 | if (status == "0\n") and (command == "upgraded") and (dir == "2.1" or dir == "2.3"): | |
109 | upgraded[pak] = upgraded.get(pak,0)+1 | |
110 | f.close() | |
19a8d9a0 MT |
111 | print "Oldest one installed - %s" % beautify_time(oldest) |
112 | for x in range(10): | |
113 | print " " | |
114 | print "Latest action done - %s" % beautify_time(newest) | |
115 | print "<br /><br /><table width='50%'><tr>" | |
116 | ||
117 | for x in range(1,31): | |
118 | if ( x % 8 ): | |
119 | print "<td align='center'>Core %s - %s</td>" % (x,upgraded.get("core-upgrade-" + str(x),0)) | |
120 | else: | |
121 | print "<td align='center'>Core %s - %s</td></tr><tr>" % (x,upgraded.get("core-upgrade-" + str(x),0)) | |
122 | print "</table><br /><br /><table width='50%'>" | |
123 | ||
124 | print "<tr><td class='header'>Addon</td><td class='header'>Anzahl</td><td class='header'>Installiert</td><td class='header'>Deinstalliert</td></tr>" | |
125 | for name, nummer in sorted(addons.items()): | |
126 | print "<tr><td align='center'>" | |
127 | print name | |
128 | print "</td><td align='center'>" | |
129 | print nummer | |
130 | print "</td><td align='center'><font color=green>+" | |
131 | print installed.get(name, 0) | |
132 | print "</fond></td><td align='center'><font color=red>-" | |
133 | print deleted.get(name, 0) | |
134 | print "</td></tr>" | |
135 | print "</table>" | |
136 | ||
137 | def showdetails(uuid, ver): | |
138 | f = open("version/"+dir+"/"+uuid) | |
139 | print "<a name='"+uuid+"' />\n<h3>"+uuid+"</h3>" | |
140 | print "<table width='70%'>" | |
141 | print "<tr><td class='header' width='70%'>IP-address<td class='header' width='30%'>Updates" | |
142 | while True: | |
143 | line = f.readline() | |
144 | if len(line) == 0: | |
145 | break # EOF | |
d17fcd70 | 146 | |
19a8d9a0 | 147 | ip, timestamp, command, pak, status = get_attributes(line) |
d17fcd70 | 148 | |
19a8d9a0 MT |
149 | if command == "update\n": |
150 | last_update = timestamp | |
151 | continue | |
152 | ||
153 | string = "<tr><td>" | |
154 | string += beautify_ip(ip) | |
155 | ||
156 | timestamp = beautify_time(timestamp) | |
d17fcd70 M |
157 | |
158 | ||
19a8d9a0 MT |
159 | if command: |
160 | string += " - <font class='%s'>%s</font> - %s" % (command, command, pak) | |
161 | if not status == "0\n": | |
162 | string += " <font class='error'>%s</font>" % status | |
d17fcd70 | 163 | |
19a8d9a0 | 164 | string += "</td><td class='date'>%s</td></tr>" % timestamp |
d17fcd70 | 165 | |
19a8d9a0 MT |
166 | print string |
167 | ||
d17fcd70 | 168 | print "<tr><td>Last update:</td><td align='center'>%s" % beautify_time(timestamp) |
19a8d9a0 MT |
169 | print "</table>" |
170 | f.close() | |
171 | ||
172 | ||
173 | def summary(type): | |
174 | print "<table width='50%'>" | |
175 | print "<tr><td class='header' colspan='2'>Summary</td></tr>" | |
176 | if type == "global": | |
177 | print "<tr><td>Versions available:</td><td>", | |
26d04920 MT |
178 | for dir in os.listdir("version/"): |
179 | if (dir == "empty.txt" ): | |
180 | pass | |
181 | else: | |
d17fcd70 | 182 | print "%s (%s)<br>" % (dir, len(os.listdir("version/"+dir))), |
19a8d9a0 | 183 | print "</td></tr>" |
d17fcd70 | 184 | |
19a8d9a0 | 185 | count = 0 |
d17fcd70 M |
186 | version={} |
187 | ||
19a8d9a0 | 188 | for dir in os.listdir("version/"): |
26d04920 | 189 | if (dir == "empty.txt" ): |
d17fcd70 | 190 | pass |
26d04920 MT |
191 | else: |
192 | count += len(os.listdir("version/"+dir)) | |
d17fcd70 | 193 | print "<tr><td>Number of total hosts:</td><td>",count, |
19a8d9a0 MT |
194 | print "</td></tr>" |
195 | ||
d17fcd70 | 196 | |
19a8d9a0 MT |
197 | print "</table>" |
198 | ||
199 | ### HTTP-Header | |
200 | # | |
201 | print "Content-type: text/html" | |
202 | ||
203 | ||
204 | form = cgi.FieldStorage() | |
205 | ||
206 | ver = form.getfirst('ver') | |
207 | uuid = form.getfirst('uuid') | |
208 | ||
209 | if not uuid: | |
210 | uuid = "" | |
211 | ||
212 | print_header() | |
213 | ||
214 | summary("global") | |
215 | ||
216 | for dir in os.listdir("version/"): | |
26d04920 MT |
217 | if (dir == "empty.txt" ): |
218 | pass | |
219 | else: | |
220 | print "<h2><a href='%s?ver=%s&uuid='>%s</a></h2>" % (os.environ['SCRIPT_NAME'], dir, dir) | |
221 | if ver == dir: | |
222 | for i in os.listdir("version/"+dir): | |
223 | if i == uuid: | |
224 | showdetails(i, dir) | |
225 | else: | |
226 | showuuid(i, dir) | |
19a8d9a0 MT |
227 | |
228 | summurize_addons() | |
229 | ||
230 | print "</body></html>" |