search through websites

This commit is contained in:
usmannasir
2019-02-22 09:19:16 +05:00
parent b3dbd36dc9
commit 114bab218f
7 changed files with 175 additions and 1 deletions

View File

@@ -364,6 +364,11 @@ class ACLManager:
return websiteNames return websiteNames
@staticmethod
def searchWebsiteObjects(userID, searchTerm):
admin = Administrator.objects.get(pk=userID)
return Websites.objects.filter(admin=admin, domain__istartswith=searchTerm)
@staticmethod @staticmethod
def findWebsiteObjects(currentACL, userID): def findWebsiteObjects(currentACL, userID):

View File

@@ -249,6 +249,19 @@ class WebsiteManager:
final_json = json.dumps(final_dic) final_json = json.dumps(final_dic)
return HttpResponse(final_json) return HttpResponse(final_json)
def searchWebsites(self, userID = None, data = None):
try:
currentACL = ACLManager.loadedACL(userID)
json_data = self.searchWebsitesJson(userID, data['patternAdded'])
pagination = self.websitePagination(currentACL, userID)
final_dic = {'status': 1, 'listWebSiteStatus': 1, 'error_message': "None", "data": json_data, 'pagination': pagination}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
except BaseException, msg:
dic = {'status': 1, 'listWebSiteStatus': 0, 'error_message': str(msg)}
json_data = json.dumps(dic)
return HttpResponse(json_data)
def getFurtherAccounts(self, userID = None, data = None): def getFurtherAccounts(self, userID = None, data = None):
try: try:
currentACL = ACLManager.loadedACL(userID) currentACL = ACLManager.loadedACL(userID)
@@ -2019,6 +2032,40 @@ Host gitlab.com
json_data = json.dumps(data_ret) json_data = json.dumps(data_ret)
return HttpResponse(json_data) return HttpResponse(json_data)
def searchWebsitesJson(self, userID, searchTerm):
websites = ACLManager.searchWebsiteObjects(userID, searchTerm)
json_data = "["
checker = 0
try:
ipFile = "/etc/cyberpanel/machineIP"
f = open(ipFile)
ipData = f.read()
ipAddress = ipData.split('\n', 1)[0]
except BaseException, msg:
logging.CyberCPLogFileWriter.writeToFile("Failed to read machine IP, error:" + str(msg))
ipAddress = "192.168.100.1"
for items in websites:
if items.state == 0:
state = "Suspended"
else:
state = "Active"
dic = {'domain': items.domain, 'adminEmail': items.adminEmail, 'ipAddress': ipAddress,
'admin': items.admin.userName, 'package': items.package.packageName, 'state': state}
if checker == 0:
json_data = json_data + json.dumps(dic)
checker = 1
else:
json_data = json_data + ',' + json.dumps(dic)
json_data = json_data + ']'
return json_data
def findWebsitesJson(self, currentACL, userID, pageNumber): def findWebsitesJson(self, currentACL, userID, pageNumber):
finalPageNumber = ((pageNumber * 10)) - 10 finalPageNumber = ((pageNumber * 10)) - 10
endPageNumber = finalPageNumber + 10 endPageNumber = finalPageNumber + 10

View File

@@ -338,6 +338,60 @@ app.controller('listWebsites', function ($scope, $http) {
}; };
$scope.cyberPanelLoading = true;
$scope.searchWebsites = function () {
$scope.cyberPanelLoading = false;
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};
var data = {
patternAdded: $scope.patternAdded
};
dataurl = "/websites/searchWebsites";
$http.post(dataurl, data, config).then(ListInitialData, cantLoadInitialData);
function ListInitialData(response) {
$scope.cyberPanelLoading = true;
if (response.data.listWebSiteStatus === 1) {
var finalData = JSON.parse(response.data.data);
$scope.WebSitesList = finalData;
$("#listFail").hide();
}
else {
new PNotify({
title: 'Operation Failed!',
text: response.data.error_message,
type: 'error'
});
}
}
function cantLoadInitialData(response) {
$scope.cyberPanelLoading = true;
new PNotify({
title: 'Operation Failed!',
text: 'Connect disrupted, refresh the page.',
type: 'error'
});
}
};
}); });
/* Java script code to list accounts ends here */ /* Java script code to list accounts ends here */

View File

@@ -338,6 +338,60 @@ app.controller('listWebsites', function ($scope, $http) {
}; };
$scope.cyberPanelLoading = true;
$scope.searchWebsites = function () {
$scope.cyberPanelLoading = false;
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};
var data = {
patternAdded: $scope.patternAdded
};
dataurl = "/websites/searchWebsites";
$http.post(dataurl, data, config).then(ListInitialData, cantLoadInitialData);
function ListInitialData(response) {
$scope.cyberPanelLoading = true;
if (response.data.listWebSiteStatus === 1) {
var finalData = JSON.parse(response.data.data);
$scope.WebSitesList = finalData;
$("#listFail").hide();
}
else {
new PNotify({
title: 'Operation Failed!',
text: response.data.error_message,
type: 'error'
});
}
}
function cantLoadInitialData(response) {
$scope.cyberPanelLoading = true;
new PNotify({
title: 'Operation Failed!',
text: 'Connect disrupted, refresh the page.',
type: 'error'
});
}
};
}); });
/* Java script code to list accounts ends here */ /* Java script code to list accounts ends here */

View File

@@ -21,6 +21,11 @@
<p>{% trans "On this page you can launch, list, modify and delete websites from your server." %}</p> <p>{% trans "On this page you can launch, list, modify and delete websites from your server." %}</p>
</div> </div>
<div class="col-sm-12" style="padding: 0px; box-shadow: 0px 0px 1px 0px #888888; margin-bottom: 2%">
<input ng-change="searchWebsites()" placeholder="Search..." ng-model="patternAdded" name="dom" type="text"
class="form-control" required>
</div>
<div ng-repeat="web in WebSitesList track by $index" class="panel col-md-12" <div ng-repeat="web in WebSitesList track by $index" class="panel col-md-12"
style="padding: 0px; box-shadow: 0px 0px 1px 0px #888888;"> style="padding: 0px; box-shadow: 0px 0px 1px 0px #888888;">
<div class=""> <div class="">

View File

@@ -17,6 +17,7 @@ urlpatterns = [
url(r'^submitWebsiteCreation$', views.submitWebsiteCreation, name='submitWebsiteCreation'), url(r'^submitWebsiteCreation$', views.submitWebsiteCreation, name='submitWebsiteCreation'),
url(r'^submitWebsiteDeletion$', views.submitWebsiteDeletion, name='submitWebsiteDeletion'), url(r'^submitWebsiteDeletion$', views.submitWebsiteDeletion, name='submitWebsiteDeletion'),
url(r'^submitWebsiteListing$', views.getFurtherAccounts, name='submitWebsiteListing'), url(r'^submitWebsiteListing$', views.getFurtherAccounts, name='submitWebsiteListing'),
url(r'^searchWebsites$', views.searchWebsites, name='searchWebsites'),
url(r'^submitWebsiteModification$', views.deleteWebsite, name='submitWebsiteModification'), url(r'^submitWebsiteModification$', views.deleteWebsite, name='submitWebsiteModification'),
url(r'^submitWebsiteStatus$', views.submitWebsiteStatus, name='submitWebsiteStatus'), url(r'^submitWebsiteStatus$', views.submitWebsiteStatus, name='submitWebsiteStatus'),

View File

@@ -108,6 +108,14 @@ def fetchDomains(request):
except KeyError: except KeyError:
return redirect(loadLoginPage) return redirect(loadLoginPage)
def searchWebsites(request):
try:
userID = request.session['userID']
wm = WebsiteManager()
return wm.searchWebsites(userID, json.loads(request.body))
except KeyError:
return redirect(loadLoginPage)
def getFurtherAccounts(request): def getFurtherAccounts(request):
try: try:
userID = request.session['userID'] userID = request.session['userID']