]> git.ipfire.org Git - ipfire.org.git/blame - pakfire/show.py
General commit... see diff.
[ipfire.org.git] / pakfire / show.py
CommitLineData
19a8d9a0
MT
1#!/usr/bin/python
2
3import cgitb, os, time, socket, cgi, DNS, GeoIP
4cgitb.enable()
5
6#gi = GeoIP.new(GeoIP.GEOIP_STANDARD)
7gi = GeoIP.new(GeoIP.GEOIP_MEMORY_CACHE)
8
9def 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&amp;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
35def 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
43
44def beautify_time(timestamp):
45 return time.strftime("%d-%m-%Y - %H:%M", time.localtime(float(timestamp)))
46
47def 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
63def showuuid(uuid, ver):
64 print "<h3><a href='%s?ver=%s&amp;uuid=%s#%s'>%s</a></h3>" % (os.environ['SCRIPT_NAME'], dir, uuid, uuid, uuid)
65
66def 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 "&nbsp;"
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
137def 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
146
147 ip, timestamp, command, pak, status = get_attributes(line)
148
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)
157
158
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
163
164 string += "</td><td class='date'>%s</td></tr>" % timestamp
165
166 print string
167
168 print "<tr><td>Last update:</td><td align='center'>%s" % beautify_time(timestamp)
169 print "</table>"
170 f.close()
171
172
173def 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:
182 print "%s<br>" % dir,
19a8d9a0
MT
183 print "</td></tr>"
184
185 print "<tr><td>Number of total hosts:</td><td>",
186 count = 0
187 for dir in os.listdir("version/"):
26d04920
MT
188 if (dir == "empty.txt" ):
189 pass
190 else:
191 count += len(os.listdir("version/"+dir))
19a8d9a0
MT
192 print count,
193 print "</td></tr>"
194
195
196 print "</table>"
197
198### HTTP-Header
199#
200print "Content-type: text/html"
201print
202
203form = cgi.FieldStorage()
204
205ver = form.getfirst('ver')
206uuid = form.getfirst('uuid')
207
208if not uuid:
209 uuid = ""
210
211print_header()
212
213summary("global")
214
215for dir in os.listdir("version/"):
26d04920
MT
216 if (dir == "empty.txt" ):
217 pass
218 else:
219 print "<h2><a href='%s?ver=%s&amp;uuid='>%s</a></h2>" % (os.environ['SCRIPT_NAME'], dir, dir)
220 if ver == dir:
221 for i in os.listdir("version/"+dir):
222 if i == uuid:
223 showdetails(i, dir)
224 else:
225 showuuid(i, dir)
19a8d9a0
MT
226
227summurize_addons()
228
229print "</body></html>"