Skip to content

Commit e40fca9

Browse files
committed
Feature: allow user to disable session ip check
1 parent dd3a551 commit e40fca9

File tree

8 files changed

+72
-9
lines changed

8 files changed

+72
-9
lines changed

CyberCP/secMiddleware.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,24 @@
22
import json
33
from django.shortcuts import HttpResponse
44
import re
5+
from loginSystem.models import Administrator
56

67
class secMiddleware:
78

9+
HIGH = 0
10+
LOW = 1
11+
812
def __init__(self, get_response):
913
self.get_response = get_response
1014

1115
def __call__(self, request):
1216
try:
1317
uID = request.session['userID']
18+
admin = Administrator.objects.get(pk=uID)
1419
ipAddr = request.META.get('REMOTE_ADDR')
1520

1621
if ipAddr.find('.') > -1:
17-
if request.session['ipAddr'] == ipAddr:
22+
if request.session['ipAddr'] == ipAddr or admin.securityLevel == secMiddleware.LOW:
1823
pass
1924
else:
2025
del request.session['userID']
@@ -27,7 +32,7 @@ def __call__(self, request):
2732
else:
2833
ipAddr = request.META.get('REMOTE_ADDR').split(':')[:3]
2934

30-
if request.session['ipAddr'] == ipAddr:
35+
if request.session['ipAddr'] == ipAddr or admin.securityLevel == secMiddleware.LOW:
3136
pass
3237
else:
3338
del request.session['userID']

loginSystem/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class Administrator(models.Model):
8585
owner = models.IntegerField(default=1)
8686
token = models.CharField(max_length=500, default='None')
8787
api = models.IntegerField(default=0)
88+
securityLevel = models.IntegerField(default=0)
8889

8990
initWebsitesLimit = models.IntegerField(default=0)
9091
acl = models.ForeignKey(ACL, default=1)

plogical/upgrade.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,11 @@ def applyLoginSystemMigrations():
553553
except:
554554
pass
555555

556+
try:
557+
cursor.execute('ALTER TABLE loginSystem_administrator ADD securityLevel integer')
558+
except:
559+
pass
560+
556561
try:
557562
cursor.execute('ALTER TABLE loginSystem_administrator ADD api integer')
558563
except:

upgrade.sh

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
## Then run it like below.
77
## /usr/local/CyberCP/upgrade.sh
88

9-
cd /usr/local/CyberCP && python manage.py collectstatic --no-input
9+
cd /usr/local/CyberCP && /usr/local/CyberCP/bin/python2 manage.py collectstatic --no-input
1010
rm -rf /usr/local/CyberCP/public/static/*
1111
cp -R /usr/local/CyberCP/static/* /usr/local/CyberCP/public/static/
1212
find /usr/local/CyberCP -type d -exec chmod 0755 {} \;

userManagment/static/userManagment/userManagment.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ app.controller('createUserCtr', function ($scope, $http) {
4242
selectedACL: selectedACL,
4343
websitesLimit: websitesLimits,
4444
userName: userName,
45-
password: password
45+
password: password,
46+
securityLevel: $scope.securityLevel
4647
};
4748

4849
var config = {
@@ -171,6 +172,7 @@ app.controller('modifyUser', function ($scope, $http) {
171172
$scope.firstName = userDetails.firstName;
172173
$scope.lastName = userDetails.lastName;
173174
$scope.email = userDetails.email;
175+
$scope.secLevel = userDetails.securityLevel;
174176

175177
$scope.userModificationLoading = true;
176178
$scope.acctDetailsFetched = false;
@@ -181,6 +183,7 @@ app.controller('modifyUser', function ($scope, $http) {
181183
$scope.detailsFetched = false;
182184
$scope.userAccountsLimit = true;
183185
$scope.websitesLimit = true;
186+
184187
} else {
185188
$scope.userModificationLoading = true;
186189
$scope.acctDetailsFetched = true;
@@ -248,7 +251,8 @@ app.controller('modifyUser', function ($scope, $http) {
248251
firstName: firstName,
249252
lastName: lastName,
250253
email: email,
251-
password: password
254+
password: password,
255+
securityLevel: $scope.securityLevel
252256
};
253257

254258
var config = {

userManagment/templates/userManagment/createUser.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,17 @@ <h3 class="content-box-header">
102102
</div>
103103
</div>
104104

105+
106+
<div ng-hide="acctDetailsFetched" class="form-group">
107+
<label class="col-sm-3 control-label">{% trans "Security Level" %}</label>
108+
<div class="col-sm-6">
109+
<select ng-change="fetchUserDetails()" ng-model="securityLevel" class="form-control">
110+
<option>HIGH</option>
111+
<option>LOW</option>
112+
</select>
113+
</div>
114+
</div>
115+
105116
<div class="form-group">
106117
<label class="col-sm-3 control-label"></label>
107118
<div class="col-sm-4">

userManagment/templates/userManagment/modifyUser.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,20 @@ <h3 class="content-box-header">
8181
</div>
8282

8383

84+
<div ng-hide="acctDetailsFetched" class="form-group">
85+
<label class="col-sm-3 control-label">{% trans "Security Level" %}</label>
86+
<div class="col-sm-6">
87+
<select ng-change="fetchUserDetails()" ng-model="securityLevel" class="form-control">
88+
<option>HIGH</option>
89+
<option>LOW</option>
90+
</select>
91+
</div>
92+
<div class="col-sm-3">
93+
Currently: {$ secLevel $}
94+
</div>
95+
</div>
96+
97+
8498
<div ng-hide="acctDetailsFetched" class="form-group">
8599
<label class="col-sm-3 control-label"></label>
86100
<div class="col-sm-4">

userManagment/views.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from plogical import CyberCPLogFileWriter as logging
1111
from plogical.acl import ACLManager
1212
from plogical.virtualHostUtilities import virtualHostUtilities
13+
from CyberCP.secMiddleware import secMiddleware
1314

1415
# Create your views here.
1516

@@ -138,6 +139,7 @@ def submitUserCreation(request):
138139
password = data['password']
139140
websitesLimit = data['websitesLimit']
140141
selectedACL = data['selectedACL']
142+
securityLevel = data['securityLevel']
141143

142144
selectedACL = ACL.objects.get(name=selectedACL)
143145

@@ -146,6 +148,11 @@ def submitUserCreation(request):
146148
else:
147149
type = 3
148150

151+
if securityLevel == 'LOW':
152+
securityLevel = secMiddleware.LOW
153+
else:
154+
securityLevel = secMiddleware.HIGH
155+
149156
token = hashPassword.generateToken(userName, password)
150157
password = hashPassword.hash_password(password)
151158
currentAdmin = Administrator.objects.get(pk=userID)
@@ -168,7 +175,8 @@ def submitUserCreation(request):
168175
initWebsitesLimit=websitesLimit,
169176
owner=currentAdmin.pk,
170177
acl=selectedACL,
171-
token=token
178+
token=token,
179+
securityLevel=securityLevel,
172180
)
173181
newAdmin.save()
174182

@@ -183,7 +191,8 @@ def submitUserCreation(request):
183191
initWebsitesLimit=websitesLimit,
184192
owner=currentAdmin.pk,
185193
acl=selectedACL,
186-
token=token
194+
token=token,
195+
securityLevel=securityLevel,
187196
)
188197
newAdmin.save()
189198
elif currentACL['createNewUser'] == 1:
@@ -197,7 +206,8 @@ def submitUserCreation(request):
197206
initWebsitesLimit=websitesLimit,
198207
owner=currentAdmin.pk,
199208
acl=selectedACL,
200-
token=token
209+
token=token,
210+
securityLevel=securityLevel,
201211
)
202212
newAdmin.save()
203213
else:
@@ -261,14 +271,21 @@ def fetchUserDetails(request):
261271
email = user.email
262272

263273
websitesLimit = user.initWebsitesLimit
274+
securityLevel = ''
275+
276+
if user.securityLevel == secMiddleware.LOW:
277+
securityLevel = 'Low'
278+
else:
279+
securityLevel = 'High'
264280

265281
userDetails = {
266282
"id": user.id,
267283
"firstName": firstName,
268284
"lastName": lastName,
269285
"email": email,
270286
"acl": user.acl.name,
271-
"websitesLimit": websitesLimit
287+
"websitesLimit": websitesLimit,
288+
"securityLevel": securityLevel
272289
}
273290

274291
data_ret = {'fetchStatus': 1, 'error_message': 'None', "userDetails": userDetails}
@@ -296,6 +313,7 @@ def saveModifications(request):
296313
firstName = data['firstName']
297314
lastName = data['lastName']
298315
email = data['email']
316+
securityLevel = data['securityLevel']
299317

300318
user = Administrator.objects.get(userName=accountUsername)
301319

@@ -323,6 +341,11 @@ def saveModifications(request):
323341
user.token = token
324342
user.type = 0
325343

344+
if securityLevel == 'LOW':
345+
user.securityLevel = secMiddleware.LOW
346+
else:
347+
user.securityLevel = secMiddleware.HIGH
348+
326349
user.save()
327350

328351
data_ret = {'status': 1, 'saveStatus': 1, 'error_message': 'None'}

0 commit comments

Comments
 (0)