-
Notifications
You must be signed in to change notification settings - Fork 0
/
DNS_server.py
94 lines (84 loc) · 3.15 KB
/
DNS_server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# -*- coding: utf-8 -*-
#
# Abstraction of a DNS server
#
from Node import *
from locator import Base
if Base != object.__class__:
from sqlalchemy import Column, Integer, String
class DNS_server(Node, Base):
if Base != object.__class__:
__tablename__ = 'dns_server'
ident = Column(String, primary_key=True)
name = Column(String)
x = Column(Integer)
y = Column(Integer)
read_features = ["name", "ip"]
features = ["name", "ip"]
tiny_pixbuf = gtk.gdk.pixbuf_new_from_xpm_data([
"26 20 5 1",
" c black",
". c grey",
"o c yellow",
"X c blue",
"- c None",
"--------------------------",
"-........................-",
"-........................-",
"-..XXXXXXXXXXXXXXXXXXXX..-",
"-..XXooXXXoXXXXoXXooooX..-",
"-..XXoXoXXooXXXoXoXXXXX..-",
"-..XXoXXoXoXoXXoXXooXXX..-",
"-..XXoXXoXoXXoXoXXXXXoX..-",
"-..XXoXoXXoXXXooXXXXXoX..-",
"-..XXooXXXoXXXXoXooooXX..-",
"-..XXXXXXXXXXXXXXXXXXXX..-",
"-........................-",
"-........................-",
"---------........---------",
"--------..........--------",
"---....................---",
"---. . . . . . . . . ..---",
"--- ---",
"---. . . . . . . . . . ---",
"--- ---",
"---. . . . . . . . . ..---"
])
def __init__(self, ipaddr=None, name=None, x=50, y=50, ident=None, gui=None):
assert(name != None)
Node.__init__(self, name, "DNS server", x, y, ident, gui)
self.ipaddr = ipaddr
if self.ipaddr == None:
self.ipaddr = gui.get_new_node("IP_address", None, None, x - 30, y)
gui.connect(self, self.ipaddr)
assert(self.ipaddr != None)
self.ip = self.ipaddr.getIp()
self.find_neighbors_script = "./script.sh"
def node_clicked(self, widget, event):
# If right-click
if event.button == 3:
newmenu = gtk.Menu()
newitem = gtk.MenuItem('Find neighbors')
newmenu.append(newitem)
newitem.connect("button-press-event", self.find_neighbors)
item_remove = gtk.MenuItem('Remove')
newmenu.append(item_remove)
item_remove.connect("button-press-event", self.disappear)
newmenu.show_all()
newmenu.popup(None, None, None, event.button, event.time)
def find_connect_node(self, newid):
# Create new DNS server
classname = self.__class__.__name__
neigh = self.gui.search_for_node_with_class(classname, "name", newid)
if neigh == None:
# Create a new DNS server instance
neigh = self.gui.get_new_node(classname, "name", newid, self.x, self.y)
self.gui.connect(self, neigh)
def find_neighbors(self, widget, event):
out = self.runProcess([self.find_neighbors_script])
for newid in str(out).strip().split():
self.find_connect_node(newid)
def disappear(self, widget, event):
self.ipaddr.disappear()
super(DNS_server, self).disappear()
# vim: set et sts=4 sw=4: