1 | #!/usr/local/bin/python |
---|
2 | |
---|
3 | import sys |
---|
4 | import os |
---|
5 | import os.path |
---|
6 | import re |
---|
7 | |
---|
8 | import gtk |
---|
9 | |
---|
10 | import ABAC |
---|
11 | import Creddy |
---|
12 | |
---|
13 | class principal_tree(gtk.TreeView): |
---|
14 | def __init__(self, policy, title): |
---|
15 | gtk.TreeView.__init__(self, gtk.TreeStore(str, str, str)) |
---|
16 | self.principals = set() |
---|
17 | self.creds = { } |
---|
18 | self.policy = policy |
---|
19 | |
---|
20 | self.append_column(gtk.TreeViewColumn("Principal", |
---|
21 | gtk.CellRendererText(), text=0)) |
---|
22 | self.append_column(gtk.TreeViewColumn(title, gtk.CellRendererText(), |
---|
23 | text=1, background=2)) |
---|
24 | |
---|
25 | self.recalc(); |
---|
26 | |
---|
27 | def recalc(self): |
---|
28 | ts = self.get_model() |
---|
29 | ts.clear() |
---|
30 | self.principals = set() |
---|
31 | self.creds = { } |
---|
32 | row = { } |
---|
33 | for c in self.policy.credentials(): |
---|
34 | p = self.selector(c) |
---|
35 | if p : |
---|
36 | if p not in self.creds: |
---|
37 | self.creds[p] = [] |
---|
38 | self.creds[p].append(c) |
---|
39 | |
---|
40 | for k, p in self.policy.principal_items(): |
---|
41 | ri = ts.append(None, [p, '', 'white']) |
---|
42 | row[k] = ri |
---|
43 | |
---|
44 | for p, cred in self.creds.items(): |
---|
45 | if p in row: |
---|
46 | cstr = [ self.printer(c) for c in cred ] |
---|
47 | cstr.sort() |
---|
48 | for c in cstr: |
---|
49 | ts.append(row[p], [ "", c, '#a5a5ff']) |
---|
50 | |
---|
51 | |
---|
52 | class principal_issued_tree(principal_tree): |
---|
53 | def __init__(self, policy): |
---|
54 | principal_tree.__init__(self, policy, "Attributes Issued") |
---|
55 | |
---|
56 | |
---|
57 | def selector(self, c): |
---|
58 | if c.tail().is_principal(): |
---|
59 | return c.head().principal() |
---|
60 | else: |
---|
61 | return None |
---|
62 | |
---|
63 | def printer(self, c): |
---|
64 | return "%s issued to %s" % ( |
---|
65 | self.policy.replace_keyids(c.head().string()), |
---|
66 | self.policy.replace_keyids(c.tail().string())) |
---|
67 | |
---|
68 | |
---|
69 | class principal_rules_tree(principal_tree): |
---|
70 | def __init__(self, policy): |
---|
71 | principal_tree.__init__(self, policy, "Rules Issued") |
---|
72 | |
---|
73 | |
---|
74 | def selector(self, c): |
---|
75 | if not c.tail().is_principal(): |
---|
76 | return c.head().principal() |
---|
77 | else: |
---|
78 | return None |
---|
79 | |
---|
80 | def printer(self, c): |
---|
81 | return self.policy.translate_cred(c) |
---|
82 | |
---|
83 | class principal_assigned_tree(principal_tree): |
---|
84 | def __init__(self, policy): |
---|
85 | principal_tree.__init__(self, policy, "Attributes Held") |
---|
86 | |
---|
87 | def selector(self, c): |
---|
88 | if c.tail().is_principal(): |
---|
89 | return c.tail().string() |
---|
90 | else: |
---|
91 | return None |
---|
92 | |
---|
93 | def printer(self, c): |
---|
94 | return "%s" % self.policy.replace_keyids(c.head().string()) |
---|
95 | |
---|
96 | class principal_attribute_tree_base(gtk.TreeView): |
---|
97 | def __init__(self, policy): |
---|
98 | gtk.TreeView.__init__(self, gtk.TreeStore(str, str, str, str)) |
---|
99 | self.principals = set() |
---|
100 | self.creds = { } |
---|
101 | self.policy = policy |
---|
102 | |
---|
103 | self.append_column(gtk.TreeViewColumn("Principal", |
---|
104 | gtk.CellRendererText(), text=0, background=2)) |
---|
105 | self.append_column(gtk.TreeViewColumn("Attributes", |
---|
106 | gtk.CellRendererText(), text=1, background=3)) |
---|
107 | |
---|
108 | self.recalc() |
---|
109 | |
---|
110 | def recalc(self): |
---|
111 | ts = self.get_model() |
---|
112 | ts.clear() |
---|
113 | row = { } |
---|
114 | attrs = set() |
---|
115 | for c in self.policy.credentials(): |
---|
116 | if self.selector(c): |
---|
117 | attrs.add(c.head().string()) |
---|
118 | |
---|
119 | for k, p in self.policy.principal_items(): |
---|
120 | ri = ts.append(None, [p, "", 'white', 'white']) |
---|
121 | row[k] = ri |
---|
122 | |
---|
123 | for a in attrs: |
---|
124 | for p in self.policy.principal_keyids(): |
---|
125 | ok, proof = self.policy.query(a, p) |
---|
126 | if ok: |
---|
127 | pi = ts.append(row[p], |
---|
128 | ["", self.policy.replace_keyids(a), 'white', |
---|
129 | '#a5a5ff']) |
---|
130 | for c in proof: |
---|
131 | ts.append(pi, |
---|
132 | ["", self.policy.translate_cred(c), 'white', |
---|
133 | '#ffa5a5']) |
---|
134 | |
---|
135 | class principal_attribute_tree(principal_attribute_tree_base): |
---|
136 | def selector(self, c): |
---|
137 | return True |
---|
138 | |
---|
139 | class principal_action_tree(principal_attribute_tree_base): |
---|
140 | def selector(self, c): |
---|
141 | return c.head().string() in self.policy.actions |
---|
142 | |
---|
143 | class attribute_principal_tree_base(gtk.TreeView): |
---|
144 | def __init__(self, policy): |
---|
145 | gtk.TreeView.__init__(self, gtk.TreeStore(str, str, str, str)) |
---|
146 | self.creds = { } |
---|
147 | self.policy = policy |
---|
148 | |
---|
149 | self.append_column(gtk.TreeViewColumn("Attributes", |
---|
150 | gtk.CellRendererText(), text=0, background=2)) |
---|
151 | self.append_column(gtk.TreeViewColumn("Principal", |
---|
152 | gtk.CellRendererText(), text=1, background=3)) |
---|
153 | |
---|
154 | self.recalc() |
---|
155 | |
---|
156 | def recalc(self): |
---|
157 | ts = self.get_model() |
---|
158 | ts.clear() |
---|
159 | row = { } |
---|
160 | principals = set() |
---|
161 | attrs = set() |
---|
162 | for c in self.policy.credentials(): |
---|
163 | if self.selector(c): |
---|
164 | attrs.add(c.head().string()) |
---|
165 | |
---|
166 | for a in attrs: |
---|
167 | ri = ts.append(None, [self.policy.replace_keyids(a), |
---|
168 | "", 'white', 'white']) |
---|
169 | row[a] = ri |
---|
170 | |
---|
171 | for a in attrs: |
---|
172 | for p in self.policy.principal_keyids(): |
---|
173 | ok, proof = self.policy.query(a, p) |
---|
174 | if ok: |
---|
175 | pi = ts.append(row[a], |
---|
176 | ["", self.policy.replace_keyids(p), 'white', |
---|
177 | '#a5a5ff']) |
---|
178 | for c in proof: |
---|
179 | ts.append(pi, |
---|
180 | ["", self.policy.translate_cred(c), 'white', |
---|
181 | '#ffa5a5']) |
---|
182 | |
---|
183 | class attribute_principal_tree(attribute_principal_tree_base): |
---|
184 | def selector(self, c): |
---|
185 | return True |
---|
186 | |
---|
187 | class action_principal_tree(attribute_principal_tree_base): |
---|
188 | def selector(self, c): |
---|
189 | return c.head().string() in self.policy.actions |
---|