Browse Source

Confined configuration pages to subnet

Thomas Johnson 1 year ago
parent
commit
ab0ea312dd
1 changed files with 35 additions and 0 deletions
  1. 35
    0
      pluto.py

+ 35
- 0
pluto.py View File

@@ -13,6 +13,9 @@ def init_globals():
13 13
     for cls in type.__subclasses__(DBObject):
14 14
         setattr(g, cls.__name__, cls)
15 15
 
16
+def ip_okay(ip):
17
+    return ip.startswith("128.153.144.") or ip.startswith("128.153.145.") or ip.startswith("128.153.146.")
18
+
16 19
 app.jinja_env.filters['ctime'] = time.ctime
17 20
 app.jinja_env.filters['jloads'] = jloads
18 21
 app.jinja_env.filters['hloads'] = header_loads
@@ -25,6 +28,8 @@ def error_404(error):
25 28
 
26 29
 @app.route('/')
27 30
 def root():
31
+    if not ip_okay(request.remote_addr):
32
+        return render_template('404.html', entity='page'), 404
28 33
     return render_template('index.html')
29 34
 
30 35
 @app.route('/hook', methods=['GET', 'POST'])
@@ -37,20 +42,28 @@ def hook():
37 42
 
38 43
 @app.route('/logs')
39 44
 def logs():
45
+    if not ip_okay(request.remote_addr):
46
+        return render_template('404.html', entity='page'), 404
40 47
     n = request.values.get('n', 10)
41 48
     return render_template('logs.html', logs=Log.most_recent(n), n=n)
42 49
 
43 50
 @app.route('/debuglogs', methods=['GET', 'POST'])
44 51
 def debuglogs():
52
+    if not ip_okay(request.remote_addr):
53
+        return render_template('404.html', entity='page'), 404
45 54
     n = request.values.get('n', 10)
46 55
     return render_template('debuglogs.html', logs=DebugLog.most_recent(n), n=n)
47 56
 
48 57
 @app.route('/hooks')
49 58
 def hooks():
59
+    if not ip_okay(request.remote_addr):
60
+        return render_template('404.html', entity='page'), 404
50 61
     return render_template('hooks.html', hooks=Hook.all())
51 62
 
52 63
 @app.route('/hooks/new', methods=['GET', 'POST'])
53 64
 def hooks_new():
65
+    if not ip_okay(request.remote_addr):
66
+        return render_template('404.html', entity='page'), 404
54 67
     if request.method == 'POST':
55 68
         hook = Hook.create(
56 69
             request.values['name'], None,  # FIXME no author yet
@@ -62,6 +75,8 @@ def hooks_new():
62 75
 
63 76
 @app.route('/hook/<int:hookid>')
64 77
 def hook_obj(hookid):
78
+    if not ip_okay(request.remote_addr):
79
+        return render_template('404.html', entity='page'), 404
65 80
     try:
66 81
         hook = Hook.get_one(rowid=hookid)
67 82
     except NoSuchEntity:
@@ -72,6 +87,8 @@ def hook_obj(hookid):
72 87
 
73 88
 @app.route('/hook/<int:hookid>/edit', methods=['GET', 'POST'])
74 89
 def hook_edit(hookid):
90
+    if not ip_okay(request.remote_addr):
91
+        return render_template('404.html', entity='page'), 404
75 92
     try:
76 93
         hook = Hook.get_one(rowid=hookid)
77 94
     except NoSuchEntity:
@@ -88,6 +105,8 @@ def hook_edit(hookid):
88 105
     
89 106
 @app.route('/hook/<int:hookid>/newcond', methods=['GET', 'POST'])
90 107
 def hook_new_cond(hookid):
108
+    if not ip_okay(request.remote_addr):
109
+        return render_template('404.html', entity='page'), 404
91 110
     try:
92 111
         hook = Hook.get_one(rowid=hookid)
93 112
     except NoSuchEntity:
@@ -106,6 +125,8 @@ def hook_new_cond(hookid):
106 125
 
107 126
 @app.route('/hook/<int:hookid>/newact', methods=['GET', 'POST'])
108 127
 def hook_new_act(hookid):
128
+    if not ip_okay(request.remote_addr):
129
+        return render_template('404.html', entity='page'), 404
109 130
     try:
110 131
         hook = Hook.get_one(rowid=hookid)
111 132
     except NoSuchEntity:
@@ -122,6 +143,8 @@ def hook_new_act(hookid):
122 143
 
123 144
 @app.route('/hook/<int:hookid>/delete', methods=['GET', 'POST'])
124 145
 def hook_delete(hookid):
146
+    if not ip_okay(request.remote_addr):
147
+        return render_template('404.html', entity='page'), 404
125 148
     try:
126 149
         hook = Hook.get_one(rowid=hookid)
127 150
     except NoSuchEntity:
@@ -135,6 +158,8 @@ def hook_delete(hookid):
135 158
 
136 159
 @app.route('/cond/<int:condid>')
137 160
 def cond_obj(condid):
161
+    if not ip_okay(request.remote_addr):
162
+        return render_template('404.html', entity='page'), 404
138 163
     try:
139 164
         cond = Condition.get_one(rowid=condid)
140 165
     except NoSuchEntity:
@@ -145,6 +170,8 @@ def cond_obj(condid):
145 170
 
146 171
 @app.route('/cond/<int:condid>/edit', methods=['GET', 'POST'])
147 172
 def cond_edit(condid):
173
+    if not ip_okay(request.remote_addr):
174
+        return render_template('404.html', entity='page'), 404
148 175
     try:
149 176
         cond = Condition.get_one(rowid=condid)
150 177
     except NoSuchEntity:
@@ -167,6 +194,8 @@ def cond_edit(condid):
167 194
 
168 195
 @app.route('/cond/<int:condid>/delete', methods=['GET', 'POST'])
169 196
 def cond_delete(condid):
197
+    if not ip_okay(request.remote_addr):
198
+        return render_template('404.html', entity='page'), 404
170 199
     try:
171 200
         cond = Condition.get_one(rowid=condid)
172 201
     except NoSuchEntity:
@@ -180,6 +209,8 @@ def cond_delete(condid):
180 209
 
181 210
 @app.route('/act/<int:actid>')
182 211
 def act_obj(actid):
212
+    if not ip_okay(request.remote_addr):
213
+        return render_template('404.html', entity='page'), 404
183 214
     try:
184 215
         act = Action.get_one(rowid=actid)
185 216
     except NoSuchEntity:
@@ -190,6 +221,8 @@ def act_obj(actid):
190 221
 
191 222
 @app.route('/act/<int:actid>/edit', methods=['GET', 'POST'])
192 223
 def act_edit(actid):
224
+    if not ip_okay(request.remote_addr):
225
+        return render_template('404.html', entity='page'), 404
193 226
     try:
194 227
         act = Action.get_one(rowid=actid)
195 228
     except NoSuchEntity:
@@ -207,6 +240,8 @@ def act_edit(actid):
207 240
 
208 241
 @app.route('/act/<int:actid>/delete', methods=['GET', 'POST'])
209 242
 def act_delete(actid):
243
+    if not ip_okay(request.remote_addr):
244
+        return render_template('404.html', entity='page'), 404
210 245
     try:
211 246
         act = Action.get_one(rowid=actid)
212 247
     except NoSuchEntity:

Loading…
Cancel
Save