Skip to content
Permalink
Browse files
add/delete firewall rule via api
  • Loading branch information
usmannasir committed Jul 29, 2020
1 parent f8efe73 commit 2abb1f84ed09a0e8cd83e9a07fecf0c759ac589e
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
@@ -5,6 +5,8 @@
url(r'^createWebsite', views.createWebsite, name='createWebsiteAPI'),
url(r'^deleteWebsite', views.deleteWebsite, name='deleteWebsiteAPI'),
url(r'^submitWebsiteStatus', views.submitWebsiteStatus, name='submitWebsiteStatusAPI'),
url(r'^deleteFirewallRule$', views.deleteFirewallRule, name='deleteFirewallRule'),
url(r'^addFirewallRule$', views.addFirewallRule, name='addFirewallRule'),

url(r'^verifyConn', views.verifyConn, name='verifyConnAPI'),

@@ -85,7 +85,6 @@ def getPackagesListAPI(request):
data_ret = {"status": 0,'error_message': "Could not authorize access to API"}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)


@csrf_exempt
def getUserInfo(request):
@@ -672,3 +671,69 @@ def submitUserCreation(request):
data_ret = {'changeStatus': 0, 'error_message': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)

@csrf_exempt
def addFirewallRule(request):
try:
if request.method == 'POST':

data = json.loads(request.body)

adminUser = data['adminUser']
adminPass = data['adminPass']

admin = Administrator.objects.get(userName=adminUser)

if admin.api == 0:
data_ret = {"status": 0, 'error_message': "API Access Disabled."}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)

if hashPassword.check_password(admin.password, adminPass):
from firewall.firewallManager import FirewallManager

fm = FirewallManager()
return fm.addRule(admin.pk, json.loads(request.body))
else:
data_ret = {"status": 0,
'error_message': "Could not authorize access to API"}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)

except BaseException as msg:
data_ret = {'submitUserDeletion': 0, 'error_message': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)

@csrf_exempt
def deleteFirewallRule(request):
try:
if request.method == 'POST':

data = json.loads(request.body)

adminUser = data['adminUser']
adminPass = data['adminPass']

admin = Administrator.objects.get(userName=adminUser)

if admin.api == 0:
data_ret = {"status": 0, 'error_message': "API Access Disabled."}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)

if hashPassword.check_password(admin.password, adminPass):
from firewall.firewallManager import FirewallManager

fm = FirewallManager()
return fm.deleteRule(admin.pk, json.loads(request.body))
else:
data_ret = {"status": 0,
'error_message': "Could not authorize access to API"}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)

except BaseException as msg:
data_ret = {'submitUserDeletion': 0, 'error_message': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)

0 comments on commit 2abb1f8

Please sign in to comment.