85 |
|
output = output + '<h2>Subscribers</h2>' |
86 |
|
|
87 |
|
found_subs = 0 |
88 |
< |
for x in g_subscribed[:]: |
89 |
< |
if int(time.time()) > x[2]: |
90 |
< |
g_subscribed.remove(x) |
88 |
> |
for subscriber in g_subscribed[:]: |
89 |
> |
if int(time.time()) > subscriber[2]: |
90 |
> |
g_subscribed.remove(subscriber) |
91 |
|
else: |
92 |
|
found_subs = found_subs + 1 |
93 |
< |
output = output + "<p>{0}:{1}</p>".format(x[0], x[1]) |
93 |
> |
output = output + "<p>{0}:{1}</p>".format(subscriber[0], subscriber[1]) |
94 |
|
|
95 |
|
if found_subs == 0: |
96 |
|
output = output + '<p>None</p>' |
138 |
|
print "Client subscribed: {0}:{1}, searching for targets {2}".format(client_ip, client_port, client_targets) |
139 |
|
|
140 |
|
# Remove all expired entries, and previous entries of that client |
141 |
< |
for x in g_subscribed[:]: |
142 |
< |
if int(time.time()) > x[2]: |
143 |
< |
g_subscribed.remove(x) |
144 |
< |
elif (x[0] == client_ip) and (x[1] == client_port) and (x[3] == client_targets): |
145 |
< |
g_subscribed.remove(x) |
141 |
> |
for subscriber in g_subscribed[:]: |
142 |
> |
if int(time.time()) > subscriber[2]: |
143 |
> |
g_subscribed.remove(subscriber) |
144 |
> |
elif (subscriber[0] == client_ip) and (subscriber[1] == client_port) and (subscriber[3] == client_targets): |
145 |
> |
g_subscribed.remove(subscriber) |
146 |
|
|
147 |
|
# Now add our new client |
148 |
|
g_subscribed.append([client_ip, client_port, client_expires, client_targets]) |
159 |
|
|
160 |
|
found_g = 0 |
161 |
|
|
162 |
< |
for subscriber in g_subscribed: |
162 |
> |
for subscriber in g_subscribed[:]: |
163 |
|
client_ip = subscriber[0] |
164 |
|
client_port = subscriber[1] |
165 |
|
client_expires = subscriber[2] |
166 |
|
client_targets = subscriber[3] |
167 |
< |
found_c = 0 |
168 |
< |
for st in server_targets: |
169 |
< |
for ct in client_targets: |
170 |
< |
if ct == st: |
171 |
< |
found_c = found_c + 1 |
172 |
< |
found_g = found_g + 1 |
173 |
< |
if found_c > 0: |
174 |
< |
# Notify clients via threads, so that all clients are equally fast notified |
175 |
< |
thread = threading.Thread(target=self.thr_client_notify, args=(client_ip, client_port, server_targets, )) |
176 |
< |
thread.start() |
167 |
> |
|
168 |
> |
if int(time.time()) > client_expires: |
169 |
> |
g_subscribed.remove(subscriber) |
170 |
> |
else: |
171 |
> |
found_c = 0 |
172 |
> |
for st in server_targets: |
173 |
> |
for ct in client_targets: |
174 |
> |
if ct == st: |
175 |
> |
found_c = found_c + 1 |
176 |
> |
found_g = found_g + 1 |
177 |
> |
if found_c > 0: |
178 |
> |
# Notify clients via threads, so that all clients are equally fast notified |
179 |
> |
thread = threading.Thread(target=self.thr_client_notify, args=(client_ip, client_port, server_targets, )) |
180 |
> |
thread.start() |
181 |
|
|
182 |
|
if found_g == 0: |
183 |
|
print "ALERT {0}, but nobody is listening!".format(server_targets) |