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