mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2026-05-06 18:26:15 +02:00
push changes
This commit is contained in:
261
databases/databaseManager.py
Normal file
261
databases/databaseManager.py
Normal file
@@ -0,0 +1,261 @@
|
||||
#!/usr/local/CyberCP/bin/python2
|
||||
import os.path
|
||||
import sys
|
||||
import django
|
||||
sys.path.append('/usr/local/CyberCP')
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
|
||||
django.setup()
|
||||
from django.shortcuts import render, redirect
|
||||
from django.http import HttpResponse
|
||||
import json
|
||||
from plogical.acl import ACLManager
|
||||
import plogical.CyberCPLogFileWriter as logging
|
||||
from plogical.mysqlUtilities import mysqlUtilities
|
||||
from websiteFunctions.models import Websites
|
||||
from databases.models import Databases
|
||||
import argparse
|
||||
from loginSystem.models import Administrator
|
||||
import plogical.randomPassword as randomPassword
|
||||
|
||||
class DatabaseManager:
|
||||
|
||||
def loadDatabaseHome(self, request = None, userID = None):
|
||||
try:
|
||||
return render(request, 'databases/index.html')
|
||||
except BaseException, msg:
|
||||
return HttpResponse(str(msg))
|
||||
|
||||
def phpMyAdmin(self, request = None, userID = None):
|
||||
try:
|
||||
return render(request, 'databases/phpMyAdmin.html')
|
||||
except BaseException, msg:
|
||||
return HttpResponse(str(msg))
|
||||
|
||||
def createDatabase(self, request = None, userID = None):
|
||||
try:
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
if ACLManager.currentContextPermission(currentACL, 'createDatabase') == 0:
|
||||
return ACLManager.loadError()
|
||||
|
||||
websitesName = ACLManager.findAllSites(currentACL, userID)
|
||||
|
||||
return render(request, 'databases/createDatabase.html', {'websitesList': websitesName})
|
||||
except BaseException, msg:
|
||||
return HttpResponse(str(msg))
|
||||
|
||||
def submitDBCreation(self, userID = None, data = None, rAPI = None):
|
||||
try:
|
||||
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
if ACLManager.currentContextPermission(currentACL, 'createDatabase') == 0:
|
||||
return ACLManager.loadErrorJson('createDBStatus', 0)
|
||||
|
||||
databaseWebsite = data['databaseWebsite']
|
||||
dbName = data['dbName']
|
||||
dbUsername = data['dbUsername']
|
||||
dbPassword = data['dbPassword']
|
||||
webUsername = data['webUserName']
|
||||
|
||||
if ACLManager.checkOwnership(databaseWebsite, admin, currentACL) == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson()
|
||||
|
||||
if rAPI == None:
|
||||
dbName = webUsername + "_" + dbName
|
||||
dbUsername = webUsername + "_" + dbUsername
|
||||
|
||||
result = mysqlUtilities.submitDBCreation(dbName, dbUsername, dbPassword, databaseWebsite)
|
||||
|
||||
if result[0] == 1:
|
||||
data_ret = {'status': 1, 'createDBStatus': 1, 'error_message': "None"}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
else:
|
||||
data_ret = {'status': 0, 'createDBStatus': 0, 'error_message': result[1]}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
except BaseException, msg:
|
||||
data_ret = {'status': 0, 'createDBStatus': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
def deleteDatabase(self, request = None, userID = None):
|
||||
try:
|
||||
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
if ACLManager.currentContextPermission(currentACL, 'deleteDatabase') == 0:
|
||||
return ACLManager.loadError()
|
||||
|
||||
websitesName = ACLManager.findAllSites(currentACL, userID)
|
||||
|
||||
return render(request, 'databases/deleteDatabase.html', {'websitesList': websitesName})
|
||||
except BaseException, msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
||||
return HttpResponse(str(msg))
|
||||
|
||||
def fetchDatabases(self, userID = None, data = None):
|
||||
try:
|
||||
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
if ACLManager.currentContextPermission(currentACL, 'deleteDatabase') == 0:
|
||||
return ACLManager.loadErrorJson('fetchStatus', 0)
|
||||
|
||||
databaseWebsite = data['databaseWebsite']
|
||||
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
if ACLManager.checkOwnership(databaseWebsite, admin, currentACL) == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson()
|
||||
|
||||
website = Websites.objects.get(domain=databaseWebsite)
|
||||
databases = Databases.objects.filter(website=website)
|
||||
|
||||
json_data = "["
|
||||
checker = 0
|
||||
|
||||
for items in databases:
|
||||
dic = {'id': items.pk,
|
||||
'dbName': items.dbName,
|
||||
'dbUser': items.dbUser, }
|
||||
|
||||
if checker == 0:
|
||||
json_data = json_data + json.dumps(dic)
|
||||
checker = 1
|
||||
else:
|
||||
json_data = json_data + ',' + json.dumps(dic)
|
||||
|
||||
json_data = json_data + ']'
|
||||
|
||||
final_json = json.dumps({'status': 1, 'fetchStatus': 1, 'error_message': "None", "data": json_data})
|
||||
|
||||
return HttpResponse(final_json)
|
||||
except BaseException, msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
||||
final_json = json.dumps({'status': 0, 'fetchStatus': 0, 'error_message': str(msg)})
|
||||
return HttpResponse(final_json)
|
||||
|
||||
def submitDatabaseDeletion(self, userID = None, data = None):
|
||||
try:
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
if ACLManager.currentContextPermission(currentACL, 'deleteDatabase') == 0:
|
||||
return ACLManager.loadErrorJson('deleteStatus', 0)
|
||||
|
||||
dbName = data['dbName']
|
||||
db = Databases.objects.get(dbName=dbName)
|
||||
|
||||
if ACLManager.checkOwnership(db.website.domain, admin, currentACL) == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson()
|
||||
|
||||
result = mysqlUtilities.submitDBDeletion(dbName)
|
||||
|
||||
if result[0] == 1:
|
||||
data_ret = {'status': 1, 'deleteStatus': 1, 'error_message': "None"}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
else:
|
||||
data_ret = {'status': 0, 'deleteStatus': 0, 'error_message': result[1]}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
except BaseException, msg:
|
||||
data_ret = {'status': 0, 'deleteStatus': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
def listDBs(self, request = None, userID = None):
|
||||
try:
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
if ACLManager.currentContextPermission(currentACL, 'listDatabases') == 0:
|
||||
return ACLManager.loadError()
|
||||
|
||||
websitesName = ACLManager.findAllSites(currentACL, userID)
|
||||
|
||||
return render(request, 'databases/listDataBases.html', {'websiteList': websitesName})
|
||||
except BaseException, msg:
|
||||
return HttpResponse(str(msg))
|
||||
|
||||
def changePassword(self, userID = None, data = None):
|
||||
try:
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if ACLManager.currentContextPermission(currentACL, 'listDatabases') == 0:
|
||||
return ACLManager.loadErrorJson('changePasswordStatus', 0)
|
||||
|
||||
userName = data['dbUserName']
|
||||
dbPassword = data['dbPassword']
|
||||
|
||||
db = Databases.objects.get(dbUser=userName)
|
||||
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
if ACLManager.checkOwnership(db.website.domain, admin, currentACL) == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson()
|
||||
|
||||
|
||||
res = mysqlUtilities.changePassword(userName, dbPassword)
|
||||
|
||||
if res == 0:
|
||||
data_ret = {'status': 0, 'changePasswordStatus': 0,'error_message': "Please see CyberPanel main log file."}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
data_ret = {'status': 1, 'changePasswordStatus': 1, 'error_message': "None"}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
except BaseException, msg:
|
||||
data_ret = {'status': 0, 'changePasswordStatus': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
@staticmethod
|
||||
def generatePHPMYAdminData(userID):
|
||||
try:
|
||||
|
||||
admin = Administrator.objects.get(id=userID)
|
||||
path = '/etc/cyberpanel/' + admin.userName
|
||||
|
||||
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
websiteOBJs = ACLManager.findWebsiteObjects(currentACL, userID)
|
||||
finalUserPassword = randomPassword.generate_pass()
|
||||
|
||||
writeToFile = open(path, 'w')
|
||||
writeToFile.write(finalUserPassword)
|
||||
writeToFile.close()
|
||||
|
||||
mysqlUtilities.createDBUser(admin.userName, finalUserPassword)
|
||||
mysqlUtilities.changePassword(admin.userName, finalUserPassword)
|
||||
|
||||
for webs in websiteOBJs:
|
||||
for db in webs.databases_set.all():
|
||||
mysqlUtilities.allowGlobalUserAccess(admin.userName, db.dbName)
|
||||
|
||||
print "1," + finalUserPassword
|
||||
|
||||
except BaseException, msg:
|
||||
print "0," + str(msg)
|
||||
|
||||
def main():
|
||||
|
||||
parser = argparse.ArgumentParser(description='CyberPanel Installer')
|
||||
parser.add_argument('function', help='Specific a function to call!')
|
||||
|
||||
parser.add_argument('--userID', help='Logged in user ID')
|
||||
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.function == "generatePHPMYAdminData":
|
||||
DatabaseManager.generatePHPMYAdminData(int(args.userID))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -9,4 +9,4 @@ from websiteFunctions.models import Websites
|
||||
class Databases(models.Model):
|
||||
website = models.ForeignKey(Websites)
|
||||
dbName = models.CharField(max_length=50,unique=True)
|
||||
dbUser = models.CharField(max_length=50, unique=True)
|
||||
dbUser = models.CharField(max_length=50)
|
||||
|
||||
36
databases/pluginManager.py
Normal file
36
databases/pluginManager.py
Normal file
@@ -0,0 +1,36 @@
|
||||
from signals import *
|
||||
from plogical.pluginManagerGlobal import pluginManagerGlobal
|
||||
|
||||
class pluginManager:
|
||||
|
||||
@staticmethod
|
||||
def preCreateDatabase(request):
|
||||
return pluginManagerGlobal.globalPlug(request, preCreateDatabase)
|
||||
|
||||
@staticmethod
|
||||
def postCreateDatabase(request, response):
|
||||
return pluginManagerGlobal.globalPlug(request, postCreateDatabase, response)
|
||||
|
||||
@staticmethod
|
||||
def preSubmitDBCreation(request):
|
||||
return pluginManagerGlobal.globalPlug(request, preSubmitDBCreation)
|
||||
|
||||
@staticmethod
|
||||
def postSubmitDBCreation(request, response):
|
||||
return pluginManagerGlobal.globalPlug(request, postSubmitDBCreation, response)
|
||||
|
||||
@staticmethod
|
||||
def preSubmitDatabaseDeletion(request):
|
||||
return pluginManagerGlobal.globalPlug(request, preSubmitDatabaseDeletion)
|
||||
|
||||
@staticmethod
|
||||
def postSubmitDatabaseDeletion(request, response):
|
||||
return pluginManagerGlobal.globalPlug(request, postSubmitDatabaseDeletion, response)
|
||||
|
||||
@staticmethod
|
||||
def preChangePassword(request):
|
||||
return pluginManagerGlobal.globalPlug(request, preChangePassword)
|
||||
|
||||
@staticmethod
|
||||
def postChangePassword(request, response):
|
||||
return pluginManagerGlobal.globalPlug(request, postChangePassword, response)
|
||||
28
databases/signals.py
Normal file
28
databases/signals.py
Normal file
@@ -0,0 +1,28 @@
|
||||
# The world is a prison for the believer.
|
||||
|
||||
from django.dispatch import Signal
|
||||
|
||||
## This event is fired before CyberPanel core load the create database template, this special event is used
|
||||
## to create a beautiful names official plugin. Actual FTP account creation happens with event named preSubmitDBCreation and postSubmitDBCreation.
|
||||
preCreateDatabase = Signal(providing_args=["request"])
|
||||
|
||||
## See preCreateDatabase
|
||||
postCreateDatabase = Signal(providing_args=["request", "response"])
|
||||
|
||||
## This event is fired before CyberPanel core start creation of a database.
|
||||
preSubmitDBCreation = Signal(providing_args=["request"])
|
||||
|
||||
## This event is fired after CyberPanel core finished creation of a database.
|
||||
postSubmitDBCreation = Signal(providing_args=["request", "response"])
|
||||
|
||||
## This event is fired before CyberPanel core start deletion of a database
|
||||
preSubmitDatabaseDeletion = Signal(providing_args=["request"])
|
||||
|
||||
## This event is fired after CyberPanel core finished deletion of a database.
|
||||
postSubmitDatabaseDeletion = Signal(providing_args=["request", "response"])
|
||||
|
||||
## This event is fired before CyberPanel core start to change a database password.
|
||||
preChangePassword = Signal(providing_args=["request"])
|
||||
|
||||
## This event is fired after CyberPanel core finished changing database password.
|
||||
postChangePassword = Signal(providing_args=["request", "response"])
|
||||
@@ -3,113 +3,114 @@
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* Java script code to create database */
|
||||
app.controller('createDatabase', function($scope,$http) {
|
||||
app.controller('createDatabase', function ($scope, $http) {
|
||||
|
||||
$scope.createDatabaseLoading = true;
|
||||
$scope.dbDetails = true;
|
||||
$scope.databaseCreationFailed = true;
|
||||
$scope.databaseCreated = true;
|
||||
$scope.couldNotConnect = true;
|
||||
$scope.generatedPasswordView = true;
|
||||
|
||||
|
||||
$scope.showDetailsBoxes = function(){
|
||||
$scope.showDetailsBoxes = function () {
|
||||
$scope.dbDetails = false;
|
||||
};
|
||||
|
||||
$scope.createDatabase = function () {
|
||||
|
||||
$scope.createDatabase = function(){
|
||||
$scope.createDatabaseLoading = false;
|
||||
$scope.dbDetails = false;
|
||||
$scope.databaseCreationFailed = true;
|
||||
$scope.databaseCreated = true;
|
||||
$scope.couldNotConnect = true;
|
||||
|
||||
$scope.createDatabaseLoading = false;
|
||||
|
||||
var databaseWebsite = $scope.databaseWebsite;
|
||||
var dbName = $scope.dbName;
|
||||
var dbUsername = $scope.dbUsername;
|
||||
var dbPassword = $scope.dbPassword;
|
||||
var webUserName = "";
|
||||
|
||||
// getting website username
|
||||
|
||||
webUserName = databaseWebsite.replace(/-/g, '');
|
||||
webUserName = webUserName.split(".")[0];
|
||||
|
||||
if (webUserName.length > 5) {
|
||||
webUserName = webUserName.substring(0, 4);
|
||||
}
|
||||
|
||||
var url = "/dataBases/submitDBCreation";
|
||||
|
||||
|
||||
var data = {
|
||||
webUserName: webUserName,
|
||||
databaseWebsite: databaseWebsite,
|
||||
dbName: dbName,
|
||||
dbUsername: dbUsername,
|
||||
dbPassword: dbPassword
|
||||
};
|
||||
|
||||
var config = {
|
||||
headers: {
|
||||
'X-CSRFToken': getCookie('csrftoken')
|
||||
}
|
||||
};
|
||||
|
||||
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
|
||||
|
||||
|
||||
function ListInitialDatas(response) {
|
||||
|
||||
|
||||
if (response.data.createDBStatus == 1) {
|
||||
|
||||
$scope.createDatabaseLoading = true;
|
||||
$scope.dbDetails = false;
|
||||
$scope.databaseCreationFailed = true;
|
||||
$scope.databaseCreated = true;
|
||||
$scope.databaseCreated = false;
|
||||
$scope.couldNotConnect = true;
|
||||
|
||||
|
||||
var databaseWebsite = $scope.databaseWebsite;
|
||||
var dbName = $scope.dbName;
|
||||
var dbUsername = $scope.dbUsername;
|
||||
var dbPassword = $scope.dbPassword;
|
||||
var webUserName = "";
|
||||
}
|
||||
|
||||
// getting website username
|
||||
|
||||
webUserName = databaseWebsite.replace("-", "");
|
||||
|
||||
webUserName = webUserName.split(".")[0];
|
||||
|
||||
if(webUserName.length > 5){
|
||||
webUserName = webUserName.substring(0,4);
|
||||
}
|
||||
|
||||
var url = "/dataBases/submitDBCreation";
|
||||
else {
|
||||
|
||||
|
||||
var data = {
|
||||
webUserName:webUserName,
|
||||
databaseWebsite:databaseWebsite,
|
||||
dbName:dbName,
|
||||
dbUsername:dbUsername,
|
||||
dbPassword:dbPassword,
|
||||
};
|
||||
|
||||
var config = {
|
||||
headers : {
|
||||
'X-CSRFToken': getCookie('csrftoken')
|
||||
}
|
||||
};
|
||||
|
||||
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
|
||||
$scope.createDatabaseLoading = true;
|
||||
$scope.dbDetails = false;
|
||||
$scope.databaseCreationFailed = false;
|
||||
$scope.databaseCreated = true;
|
||||
$scope.couldNotConnect = true;
|
||||
$scope.errorMessage = response.data.error_message;
|
||||
|
||||
|
||||
function ListInitialDatas(response) {
|
||||
}
|
||||
|
||||
|
||||
if(response.data.createDBStatus == 1){
|
||||
|
||||
$scope.createDatabaseLoading = true;
|
||||
$scope.dbDetails = false;
|
||||
$scope.databaseCreationFailed = true;
|
||||
$scope.databaseCreated = false;
|
||||
$scope.couldNotConnect = true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
$scope.createDatabaseLoading = true;
|
||||
$scope.dbDetails = false;
|
||||
$scope.databaseCreationFailed = false;
|
||||
$scope.databaseCreated = true;
|
||||
$scope.couldNotConnect = true;
|
||||
$scope.errorMessage = response.data.error_message;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
function cantLoadInitialDatas(response) {
|
||||
|
||||
$scope.createDatabaseLoading = true;
|
||||
$scope.dbDetails = true;
|
||||
$scope.databaseCreationFailed = true;
|
||||
$scope.databaseCreated = true;
|
||||
$scope.couldNotConnect = false;
|
||||
}
|
||||
}
|
||||
|
||||
function cantLoadInitialDatas(response) {
|
||||
|
||||
$scope.createDatabaseLoading = true;
|
||||
$scope.dbDetails = true;
|
||||
$scope.databaseCreationFailed = true;
|
||||
$scope.databaseCreated = true;
|
||||
$scope.couldNotConnect = false;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
$scope.generatePassword = function () {
|
||||
$scope.generatedPasswordView = false;
|
||||
$scope.dbPassword = randomPassword(12);
|
||||
};
|
||||
|
||||
$scope.usePassword = function () {
|
||||
$scope.generatedPasswordView = true;
|
||||
};
|
||||
|
||||
});
|
||||
@@ -117,7 +118,7 @@ app.controller('createDatabase', function($scope,$http) {
|
||||
|
||||
/* Java script code to delete database */
|
||||
|
||||
app.controller('deleteDatabase', function($scope,$http) {
|
||||
app.controller('deleteDatabase', function ($scope, $http) {
|
||||
|
||||
$scope.deleteDatabaseLoading = true;
|
||||
$scope.fetchedDatabases = true;
|
||||
@@ -126,153 +127,147 @@ app.controller('deleteDatabase', function($scope,$http) {
|
||||
$scope.couldNotConnect = true;
|
||||
|
||||
|
||||
$scope.fetchDatabases = function(){
|
||||
$scope.fetchDatabases = function () {
|
||||
|
||||
$scope.deleteDatabaseLoading = false;
|
||||
$scope.fetchedDatabases = true;
|
||||
$scope.deleteDatabaseLoading = false;
|
||||
$scope.fetchedDatabases = true;
|
||||
$scope.databaseDeletionFailed = true;
|
||||
$scope.databaseDeleted = true;
|
||||
$scope.couldNotConnect = true;
|
||||
|
||||
|
||||
var databaseWebsite = $scope.databaseWebsite;
|
||||
|
||||
var url = "/dataBases/fetchDatabases";
|
||||
|
||||
|
||||
var data = {
|
||||
databaseWebsite: databaseWebsite,
|
||||
};
|
||||
|
||||
var config = {
|
||||
headers: {
|
||||
'X-CSRFToken': getCookie('csrftoken')
|
||||
}
|
||||
};
|
||||
|
||||
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
|
||||
|
||||
|
||||
function ListInitialDatas(response) {
|
||||
|
||||
|
||||
if (response.data.fetchStatus == 1) {
|
||||
|
||||
|
||||
$scope.dbnames = JSON.parse(response.data.data);
|
||||
|
||||
|
||||
$scope.deleteDatabaseLoading = true;
|
||||
$scope.fetchedDatabases = false;
|
||||
$scope.databaseDeletionFailed = true;
|
||||
$scope.databaseDeleted = true;
|
||||
$scope.couldNotConnect = true;
|
||||
|
||||
|
||||
var databaseWebsite = $scope.databaseWebsite;
|
||||
}
|
||||
|
||||
var url = "/dataBases/fetchDatabases";
|
||||
else {
|
||||
$scope.deleteDatabaseLoading = true;
|
||||
$scope.fetchedDatabases = true;
|
||||
$scope.databaseDeletionFailed = false;
|
||||
$scope.databaseDeleted = true;
|
||||
$scope.couldNotConnect = true;
|
||||
|
||||
|
||||
var data = {
|
||||
databaseWebsite:databaseWebsite,
|
||||
};
|
||||
|
||||
var config = {
|
||||
headers : {
|
||||
'X-CSRFToken': getCookie('csrftoken')
|
||||
}
|
||||
};
|
||||
|
||||
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
|
||||
$scope.errorMessage = response.data.error_message;
|
||||
|
||||
|
||||
function ListInitialDatas(response) {
|
||||
}
|
||||
|
||||
|
||||
if(response.data.fetchStatus == 1){
|
||||
}
|
||||
|
||||
function cantLoadInitialDatas(response) {
|
||||
|
||||
$scope.deleteDatabaseLoading = true;
|
||||
$scope.fetchedDatabases = true;
|
||||
$scope.databaseDeletionFailed = true;
|
||||
$scope.databaseDeleted = true;
|
||||
$scope.couldNotConnect = false;
|
||||
|
||||
|
||||
$scope.dbnames = JSON.parse(response.data.data);
|
||||
|
||||
|
||||
$scope.deleteDatabaseLoading = true;
|
||||
$scope.fetchedDatabases = false;
|
||||
$scope.databaseDeletionFailed = true;
|
||||
$scope.databaseDeleted = true;
|
||||
$scope.couldNotConnect = true;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
$scope.deleteDatabaseLoading = true;
|
||||
$scope.fetchedDatabases = true;
|
||||
$scope.databaseDeletionFailed = false;
|
||||
$scope.databaseDeleted = true;
|
||||
$scope.couldNotConnect = true;
|
||||
|
||||
|
||||
|
||||
$scope.errorMessage = response.data.error_message;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
function cantLoadInitialDatas(response) {
|
||||
|
||||
$scope.deleteDatabaseLoading = true;
|
||||
$scope.fetchedDatabases = true;
|
||||
$scope.databaseDeletionFailed = true;
|
||||
$scope.databaseDeleted = true;
|
||||
$scope.couldNotConnect = false;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$scope.deleteDatabase = function(){
|
||||
$scope.deleteDatabase = function () {
|
||||
|
||||
$scope.deleteDatabaseLoading = false;
|
||||
$scope.fetchedDatabases = true;
|
||||
$scope.deleteDatabaseLoading = false;
|
||||
$scope.fetchedDatabases = true;
|
||||
$scope.databaseDeletionFailed = true;
|
||||
$scope.databaseDeleted = true;
|
||||
$scope.couldNotConnect = true;
|
||||
|
||||
|
||||
var databaseWebsite = $scope.databaseWebsite;
|
||||
|
||||
var url = "/dataBases/submitDatabaseDeletion";
|
||||
|
||||
|
||||
var data = {
|
||||
dbName: $scope.selectedDB,
|
||||
};
|
||||
|
||||
var config = {
|
||||
headers: {
|
||||
'X-CSRFToken': getCookie('csrftoken')
|
||||
}
|
||||
};
|
||||
|
||||
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
|
||||
|
||||
|
||||
function ListInitialDatas(response) {
|
||||
|
||||
|
||||
if (response.data.deleteStatus == 1) {
|
||||
|
||||
|
||||
$scope.deleteDatabaseLoading = true;
|
||||
$scope.fetchedDatabases = false;
|
||||
$scope.databaseDeletionFailed = true;
|
||||
$scope.databaseDeleted = false;
|
||||
$scope.couldNotConnect = true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
else {
|
||||
$scope.deleteDatabaseLoading = true;
|
||||
$scope.fetchedDatabases = true;
|
||||
$scope.databaseDeletionFailed = false;
|
||||
$scope.databaseDeleted = true;
|
||||
$scope.couldNotConnect = true;
|
||||
|
||||
|
||||
var databaseWebsite = $scope.databaseWebsite;
|
||||
|
||||
var url = "/dataBases/submitDatabaseDeletion";
|
||||
$scope.errorMessage = response.data.error_message;
|
||||
|
||||
|
||||
var data = {
|
||||
dbName:$scope.selectedDB,
|
||||
};
|
||||
|
||||
var config = {
|
||||
headers : {
|
||||
'X-CSRFToken': getCookie('csrftoken')
|
||||
}
|
||||
};
|
||||
|
||||
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
|
||||
}
|
||||
|
||||
|
||||
function ListInitialDatas(response) {
|
||||
}
|
||||
|
||||
function cantLoadInitialDatas(response) {
|
||||
|
||||
$scope.deleteDatabaseLoading = true;
|
||||
$scope.fetchedDatabases = true;
|
||||
$scope.databaseDeletionFailed = true;
|
||||
$scope.databaseDeleted = true;
|
||||
$scope.couldNotConnect = false;
|
||||
|
||||
|
||||
if(response.data.deleteStatus == 1){
|
||||
|
||||
|
||||
$scope.deleteDatabaseLoading = true;
|
||||
$scope.fetchedDatabases = false;
|
||||
$scope.databaseDeletionFailed = true;
|
||||
$scope.databaseDeleted = false;
|
||||
$scope.couldNotConnect = true;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
$scope.deleteDatabaseLoading = true;
|
||||
$scope.fetchedDatabases = true;
|
||||
$scope.databaseDeletionFailed = false;
|
||||
$scope.databaseDeleted = true;
|
||||
$scope.couldNotConnect = true;
|
||||
|
||||
|
||||
|
||||
$scope.errorMessage = response.data.error_message;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
function cantLoadInitialDatas(response) {
|
||||
|
||||
$scope.deleteDatabaseLoading = true;
|
||||
$scope.fetchedDatabases = true;
|
||||
$scope.databaseDeletionFailed = true;
|
||||
$scope.databaseDeleted = true;
|
||||
$scope.couldNotConnect = false;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -281,11 +276,10 @@ app.controller('deleteDatabase', function($scope,$http) {
|
||||
/* Java script code to delete database ends here */
|
||||
|
||||
|
||||
|
||||
/* Java script code to list databases */
|
||||
|
||||
|
||||
app.controller('listDBs', function($scope,$http) {
|
||||
app.controller('listDBs', function ($scope, $http) {
|
||||
|
||||
$scope.recordsFetched = true;
|
||||
$scope.passwordChanged = true;
|
||||
@@ -299,157 +293,204 @@ app.controller('listDBs', function($scope,$http) {
|
||||
var globalDBUsername = "";
|
||||
|
||||
$scope.fetchDBs = function () {
|
||||
populateCurrentRecords();
|
||||
populateCurrentRecords();
|
||||
};
|
||||
|
||||
$scope.changePassword = function (dbUsername) {
|
||||
$scope.recordsFetched = true;
|
||||
$scope.passwordChanged = true;
|
||||
$scope.canNotChangePassword = true;
|
||||
$scope.couldNotConnect = true;
|
||||
$scope.dbLoading = true;
|
||||
$scope.dbAccounts = false;
|
||||
$scope.changePasswordBox = false;
|
||||
$scope.notificationsBox = true;
|
||||
$scope.dbUsername = dbUsername;
|
||||
$scope.recordsFetched = true;
|
||||
$scope.passwordChanged = true;
|
||||
$scope.canNotChangePassword = true;
|
||||
$scope.couldNotConnect = true;
|
||||
$scope.dbLoading = true;
|
||||
$scope.dbAccounts = false;
|
||||
$scope.changePasswordBox = false;
|
||||
$scope.notificationsBox = true;
|
||||
$scope.dbUsername = dbUsername;
|
||||
|
||||
|
||||
globalDBUsername = dbUsername;
|
||||
globalDBUsername = dbUsername;
|
||||
|
||||
};
|
||||
|
||||
$scope.changePasswordBtn = function () {
|
||||
|
||||
$scope.dbLoading = false;
|
||||
$scope.passwordChanged = true;
|
||||
$scope.dbLoading = false;
|
||||
$scope.passwordChanged = true;
|
||||
|
||||
|
||||
url = "/dataBases/changePassword";
|
||||
url = "/dataBases/changePassword";
|
||||
|
||||
var data = {
|
||||
dbUserName:globalDBUsername,
|
||||
dbPassword: $scope.dbPassword,
|
||||
};
|
||||
var data = {
|
||||
dbUserName: globalDBUsername,
|
||||
dbPassword: $scope.dbPassword,
|
||||
};
|
||||
|
||||
var config = {
|
||||
headers : {
|
||||
'X-CSRFToken': getCookie('csrftoken')
|
||||
}
|
||||
};
|
||||
var config = {
|
||||
headers: {
|
||||
'X-CSRFToken': getCookie('csrftoken')
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
|
||||
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
|
||||
|
||||
|
||||
function ListInitialDatas(response) {
|
||||
function ListInitialDatas(response) {
|
||||
|
||||
|
||||
if(response.data.changePasswordStatus == 1){
|
||||
$scope.notificationsBox = false;
|
||||
$scope.passwordChanged = false;
|
||||
$scope.dbLoading = true;
|
||||
$scope.domainFeteched = $scope.selectedDomain;
|
||||
if (response.data.changePasswordStatus == 1) {
|
||||
$scope.notificationsBox = false;
|
||||
$scope.passwordChanged = false;
|
||||
$scope.dbLoading = true;
|
||||
$scope.domainFeteched = $scope.selectedDomain;
|
||||
|
||||
}
|
||||
else{
|
||||
$scope.notificationsBox = false;
|
||||
$scope.canNotChangePassword = false;
|
||||
$scope.dbLoading = true;
|
||||
$scope.canNotChangePassword = false;
|
||||
$scope.errorMessage = response.data.error_message;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$scope.notificationsBox = false;
|
||||
$scope.canNotChangePassword = false;
|
||||
$scope.dbLoading = true;
|
||||
$scope.canNotChangePassword = false;
|
||||
$scope.errorMessage = response.data.error_message;
|
||||
}
|
||||
|
||||
}
|
||||
function cantLoadInitialDatas(response) {
|
||||
$scope.notificationsBox = false;
|
||||
$scope.couldNotConnect = false;
|
||||
$scope.dbLoading = true;
|
||||
}
|
||||
|
||||
}
|
||||
function cantLoadInitialDatas(response) {
|
||||
$scope.notificationsBox = false;
|
||||
$scope.couldNotConnect = false;
|
||||
$scope.dbLoading = true;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
function populateCurrentRecords() {
|
||||
$scope.recordsFetched = true;
|
||||
$scope.passwordChanged = true;
|
||||
$scope.canNotChangePassword = true;
|
||||
$scope.couldNotConnect = true;
|
||||
$scope.dbLoading = false;
|
||||
$scope.dbAccounts = true;
|
||||
$scope.changePasswordBox = true;
|
||||
$scope.notificationsBox = true;
|
||||
|
||||
var selectedDomain = $scope.selectedDomain;
|
||||
|
||||
url = "/dataBases/fetchDatabases";
|
||||
|
||||
var data = {
|
||||
databaseWebsite: selectedDomain,
|
||||
};
|
||||
|
||||
var config = {
|
||||
headers: {
|
||||
'X-CSRFToken': getCookie('csrftoken')
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
function populateCurrentRecords(){
|
||||
$scope.recordsFetched = true;
|
||||
$scope.passwordChanged = true;
|
||||
$scope.canNotChangePassword = true;
|
||||
$scope.couldNotConnect = true;
|
||||
$scope.dbLoading = false;
|
||||
$scope.dbAccounts = true;
|
||||
$scope.changePasswordBox = true;
|
||||
$scope.notificationsBox = true;
|
||||
|
||||
var selectedDomain = $scope.selectedDomain;
|
||||
|
||||
url = "/dataBases/fetchDatabases";
|
||||
|
||||
var data = {
|
||||
databaseWebsite:selectedDomain,
|
||||
};
|
||||
|
||||
var config = {
|
||||
headers : {
|
||||
'X-CSRFToken': getCookie('csrftoken')
|
||||
}
|
||||
};
|
||||
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
|
||||
|
||||
|
||||
|
||||
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
|
||||
function ListInitialDatas(response) {
|
||||
|
||||
|
||||
function ListInitialDatas(response) {
|
||||
if (response.data.fetchStatus == 1) {
|
||||
|
||||
$scope.records = JSON.parse(response.data.data);
|
||||
|
||||
|
||||
if(response.data.fetchStatus == 1){
|
||||
$scope.recordsFetched = false;
|
||||
$scope.passwordChanged = true;
|
||||
$scope.canNotChangePassword = true;
|
||||
$scope.couldNotConnect = true;
|
||||
$scope.dbLoading = true;
|
||||
$scope.dbAccounts = false;
|
||||
$scope.changePasswordBox = true;
|
||||
$scope.notificationsBox = false;
|
||||
|
||||
$scope.records = JSON.parse(response.data.data);
|
||||
$scope.domainFeteched = $scope.selectedDomain;
|
||||
|
||||
}
|
||||
else {
|
||||
$scope.recordsFetched = true;
|
||||
$scope.passwordChanged = true;
|
||||
$scope.canNotChangePassword = true;
|
||||
$scope.couldNotConnect = true;
|
||||
$scope.dbLoading = true;
|
||||
$scope.dbAccounts = true;
|
||||
$scope.changePasswordBox = true;
|
||||
$scope.notificationsBox = true;
|
||||
|
||||
$scope.recordsFetched = false;
|
||||
$scope.passwordChanged = true;
|
||||
$scope.canNotChangePassword = true;
|
||||
$scope.couldNotConnect = true;
|
||||
$scope.dbLoading = true;
|
||||
$scope.dbAccounts = false;
|
||||
$scope.changePasswordBox = true;
|
||||
$scope.notificationsBox = false;
|
||||
$scope.errorMessage = response.data.error_message;
|
||||
}
|
||||
|
||||
$scope.domainFeteched = $scope.selectedDomain;
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
$scope.recordsFetched = true;
|
||||
$scope.passwordChanged = true;
|
||||
$scope.canNotChangePassword = true;
|
||||
$scope.couldNotConnect = true;
|
||||
$scope.dbLoading = true;
|
||||
$scope.dbAccounts = true;
|
||||
$scope.changePasswordBox = true;
|
||||
$scope.notificationsBox = true;
|
||||
function cantLoadInitialDatas(response) {
|
||||
$scope.recordsFetched = true;
|
||||
$scope.passwordChanged = true;
|
||||
$scope.canNotChangePassword = true;
|
||||
$scope.couldNotConnect = false;
|
||||
$scope.dbLoading = true;
|
||||
$scope.dbAccounts = true;
|
||||
$scope.changePasswordBox = true;
|
||||
$scope.notificationsBox = true;
|
||||
|
||||
$scope.errorMessage = response.data.error_message;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
function cantLoadInitialDatas(response) {
|
||||
$scope.recordsFetched = true;
|
||||
$scope.passwordChanged = true;
|
||||
$scope.canNotChangePassword = true;
|
||||
$scope.couldNotConnect = false;
|
||||
$scope.dbLoading = true;
|
||||
$scope.dbAccounts = true;
|
||||
$scope.changePasswordBox = true;
|
||||
$scope.notificationsBox = true;
|
||||
}
|
||||
|
||||
}
|
||||
////
|
||||
|
||||
};
|
||||
$scope.generatedPasswordView = true;
|
||||
|
||||
$scope.generatePassword = function () {
|
||||
$scope.generatedPasswordView = false;
|
||||
$scope.dbPassword = randomPassword(12);
|
||||
};
|
||||
|
||||
$scope.usePassword = function () {
|
||||
$scope.generatedPasswordView = true;
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
|
||||
/* Java script code to list database ends here */
|
||||
/* Java script code to list database ends here */
|
||||
|
||||
|
||||
app.controller('phpMyAdmin', function ($scope, $http, $window) {
|
||||
|
||||
function setupPHPMYAdminSession() {
|
||||
|
||||
url = "/dataBases/setupPHPMYAdminSession";
|
||||
|
||||
var data = {};
|
||||
|
||||
var config = {
|
||||
headers: {
|
||||
'X-CSRFToken': getCookie('csrftoken')
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
|
||||
|
||||
|
||||
function ListInitialDatas(response) {
|
||||
|
||||
|
||||
if (response.data.status === 1) {
|
||||
$window.location.href = '/phpmyadmin';
|
||||
}
|
||||
else {}
|
||||
|
||||
}
|
||||
|
||||
function cantLoadInitialDatas(response) {}
|
||||
|
||||
}
|
||||
setupPHPMYAdminSession();
|
||||
|
||||
});
|
||||
@@ -15,14 +15,12 @@
|
||||
|
||||
<div ng-controller="createDatabase" class="panel">
|
||||
<div class="panel-body">
|
||||
<h3 class="title-hero">
|
||||
<h3 class="content-box-header">
|
||||
{% trans "Create Database" %} <img ng-hide="createDatabaseLoading" src="{% static 'images/loading.gif' %}">
|
||||
</h3>
|
||||
<div class="example-box-wrapper">
|
||||
|
||||
|
||||
<form class="form-horizontal bordered-row">
|
||||
|
||||
<form class="form-horizontal bordered-row panel-body">
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans "Select Website" %}</label>
|
||||
@@ -59,14 +57,26 @@
|
||||
<div class="col-sm-6">
|
||||
<input type="password" name="email" class="form-control" ng-model="dbPassword" required>
|
||||
</div>
|
||||
<div class="col-sm-3">
|
||||
<button type="button" ng-click="generatePassword()" class="btn btn-primary">{% trans "Generate" %}</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div ng-hide="generatedPasswordView" class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans "Generated Password" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<input type="text" name="email" class="form-control" ng-model="dbPassword" required>
|
||||
</div>
|
||||
<div class="col-sm-3">
|
||||
<button type="button" ng-click="usePassword()" class="btn btn-primary">{% trans "Use" %}</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div ng-hide="dbDetails" class="form-group">
|
||||
<label class="col-sm-3 control-label"></label>
|
||||
<div class="col-sm-4">
|
||||
<button type="button" ng-click="createDatabase()" class="btn btn-primary btn-lg btn-block">{% trans "Create Database" %}</button>
|
||||
|
||||
<button type="button" ng-click="createDatabase()" class="btn btn-primary btn-lg">{% trans "Create Database" %}</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -108,4 +118,4 @@
|
||||
</div>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
{% endblock %}
|
||||
|
||||
@@ -15,14 +15,12 @@
|
||||
|
||||
<div ng-controller="deleteDatabase" class="panel">
|
||||
<div class="panel-body">
|
||||
<h3 class="title-hero">
|
||||
<h3 class="content-box-header">
|
||||
{% trans "Delete Database" %} <img ng-hide="deleteDatabaseLoading" src="{% static 'images/loading.gif' %}">
|
||||
</h3>
|
||||
<div class="example-box-wrapper">
|
||||
|
||||
|
||||
<form action="/" class="form-horizontal bordered-row">
|
||||
|
||||
<form action="/" class="form-horizontal bordered-row panel-body">
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans "Select Website" %}</label>
|
||||
@@ -50,13 +48,11 @@
|
||||
<div ng-hide="fetchedDatabases" class="form-group">
|
||||
<label class="col-sm-3 control-label"></label>
|
||||
<div class="col-sm-4">
|
||||
<button type="button" ng-click="deleteDatabase()" class="btn btn-primary btn-lg btn-block">{% trans "Delete Database" %}</button>
|
||||
<button type="button" ng-click="deleteDatabase()" class="btn btn-primary btn-lg">{% trans "Delete Database" %}</button>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label"></label>
|
||||
<div class="col-sm-4">
|
||||
@@ -93,4 +89,4 @@
|
||||
</div>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
{% endblock %}
|
||||
|
||||
@@ -13,61 +13,55 @@
|
||||
<p>{% trans "Create, edit and delete databases on this page." %}</p>
|
||||
</div>
|
||||
|
||||
<div class="panel">
|
||||
<div class="panel col-md-11">
|
||||
<div class="panel-body">
|
||||
<h3 class="title-hero">
|
||||
<h3 class="content-box-header">
|
||||
{% trans "Available Functions" %}
|
||||
</h3>
|
||||
|
||||
<div class="example-box-wrapper">
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="col-md-3 btn-min-width">
|
||||
<a href="{% url 'createDatabase' %}" title="{% trans 'Create Database' %}" class="tile-box tile-box-shortcut btn-primary">
|
||||
<div class="tile-header">
|
||||
{% trans "Create Database" %}
|
||||
</div>
|
||||
<div class="tile-content-wrapper">
|
||||
<i class="glyph-icon icon-dashboard"></i>
|
||||
<i class="fa fa-plus-square"></i>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="col-md-6">
|
||||
<div class="col-md-3 btn-min-width">
|
||||
<a href="{% url 'deleteDatabase' %}" title="{% trans 'Delete Database' %}" class="tile-box tile-box-shortcut btn-primary">
|
||||
<div class="tile-header">
|
||||
{% trans "Delete Database" %}
|
||||
</div>
|
||||
<div class="tile-content-wrapper">
|
||||
<i class="glyph-icon icon-dashboard"></i>
|
||||
<i class="fa fa-edit"></i>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="col-md-3 btn-min-width">
|
||||
<a href="{% url 'listDBs' %}" title="{% trans 'List Databases' %}" class="tile-box tile-box-shortcut btn-primary">
|
||||
<div class="tile-header">
|
||||
{% trans "List Databases" %}
|
||||
</div>
|
||||
<div class="tile-content-wrapper">
|
||||
<i class="glyph-icon icon-dashboard"></i>
|
||||
<i class="fa fa-list-ul"></i>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="col-md-6">
|
||||
<div class="col-md-3 btn-min-width">
|
||||
<a target="_blank" href="/phpmyadmin/index.php" title="{% trans 'PHPMYAdmin' %}" class="tile-box tile-box-shortcut btn-primary">
|
||||
<div class="tile-header">
|
||||
{% trans "PHPMYAdmin" %}
|
||||
</div>
|
||||
<div class="tile-content-wrapper">
|
||||
<i class="glyph-icon icon-dashboard"></i>
|
||||
<i class="fa fa-code"></i>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
@@ -83,4 +77,4 @@
|
||||
</div>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
{% endblock %}
|
||||
|
||||
@@ -3,120 +3,137 @@
|
||||
{% block title %}{% trans "List Databases - CyberPanel" %}{% endblock %}
|
||||
{% block content %}
|
||||
|
||||
{% load static %}
|
||||
{% get_current_language as LANGUAGE_CODE %}
|
||||
<!-- Current language: {{ LANGUAGE_CODE }} -->
|
||||
|
||||
|
||||
<div class="container">
|
||||
<div id="page-title">
|
||||
<h2>{% trans "List Databases" %}</h2>
|
||||
<p>{% trans "List Databases or change their passwords." %}</p>
|
||||
</div>
|
||||
<div ng-controller="listDBs" class="panel">
|
||||
<div class="panel-body">
|
||||
<h3 class="title-hero">
|
||||
{% trans "List Databases" %} <img ng-hide="dbLoading" src="{% static 'images/loading.gif' %}">
|
||||
</h3>
|
||||
<div class="example-box-wrapper">
|
||||
|
||||
|
||||
<form action="/" class="form-horizontal bordered-row">
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans "Select Domain" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<select ng-change="fetchDBs()" ng-model="selectedDomain" class="form-control">
|
||||
{% for items in websiteList %}
|
||||
<option>{{ items }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div ng-hide="notificationsBox" class="form-group">
|
||||
|
||||
|
||||
<label class="col-sm-3 control-label"></label>
|
||||
<div class="col-sm-4">
|
||||
|
||||
<div ng-hide="recordsFetched" class="alert alert-success">
|
||||
<p>{% trans "Records successfully fetched for" %} <strong>{$ domainFeteched $}</strong></p>
|
||||
</div>
|
||||
|
||||
<div ng-hide="passwordChanged" class="alert alert-success">
|
||||
{% trans "Password changed for: " %} <strong>{$ dbUsername $}</strong>
|
||||
</div>
|
||||
|
||||
<div ng-hide="canNotChangePassword" class="alert alert-danger">
|
||||
<p>{% trans "Cannot change password for " %}<strong>{$ dbUsername $}</strong>, {% trans "Error message:" %} {$ errorMessage $}</p>
|
||||
</div>
|
||||
|
||||
|
||||
<div ng-hide="couldNotConnect" class="alert alert-danger">
|
||||
<p>{% trans "Could Not Connect to server. Please refresh this page" %}</p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div ng-hide="changePasswordBox" class="form-group">
|
||||
<label class="col-sm-3 control-label">{$ dbUsername $}</label>
|
||||
<div class="col-sm-6">
|
||||
<input name="dom" type="password" class="form-control" ng-model="dbPassword" required>
|
||||
</div>
|
||||
|
||||
<div style="margin-top: 1%" class="col-sm-6 col-md-offset-3">
|
||||
<button type="button" ng-click="changePasswordBtn()" class="btn btn-primary btn-lg btn-block">{% trans "Change Password" %}</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!------ List of records --------------->
|
||||
|
||||
<div ng-hide="dbAccounts" class="form-group">
|
||||
|
||||
<div class="col-sm-12">
|
||||
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{% trans "ID" %}</th>
|
||||
<th>{% trans "Database Name" %}</th>
|
||||
<th>{% trans "Database User" %}</th>
|
||||
<th>{% trans "Password" %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="record in records track by $index">
|
||||
<td ng-bind="record.id"></td>
|
||||
<td ng-bind="record.dbName"></td>
|
||||
<td ng-bind="record.dbUser"></td>
|
||||
<td><button type="button" ng-click="changePassword(record.dbUser)" class="btn ra-100 btn-purple">{% trans "Change" %}</button></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!------ List of records --------------->
|
||||
|
||||
|
||||
|
||||
</form>
|
||||
|
||||
|
||||
{% load static %}
|
||||
{% get_current_language as LANGUAGE_CODE %}
|
||||
<!-- Current language: {{ LANGUAGE_CODE }} -->
|
||||
|
||||
|
||||
<div class="container">
|
||||
<div id="page-title">
|
||||
<h2>{% trans "List Databases" %}</h2>
|
||||
<p>{% trans "List Databases or change their passwords." %}</p>
|
||||
</div>
|
||||
<div ng-controller="listDBs" class="panel">
|
||||
<div class="panel-body">
|
||||
<h3 class="content-box-header">
|
||||
{% trans "List Databases" %} <img ng-hide="dbLoading" src="{% static 'images/loading.gif' %}">
|
||||
</h3>
|
||||
<div class="example-box-wrapper">
|
||||
|
||||
<form action="/" class="form-horizontal bordered-row panel-body">
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans "Select Domain" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<select ng-change="fetchDBs()" ng-model="selectedDomain" class="form-control">
|
||||
{% for items in websiteList %}
|
||||
<option>{{ items }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div ng-hide="notificationsBox" class="form-group">
|
||||
|
||||
|
||||
<label class="col-sm-3 control-label"></label>
|
||||
<div class="col-sm-6">
|
||||
|
||||
<div ng-hide="recordsFetched" class="alert alert-success">
|
||||
<p>{% trans "Records successfully fetched for" %} <strong>{$ domainFeteched
|
||||
$}</strong></p>
|
||||
</div>
|
||||
|
||||
<div ng-hide="passwordChanged" class="alert alert-success">
|
||||
{% trans "Password changed for: " %} <strong>{$ dbUsername $}</strong>
|
||||
</div>
|
||||
|
||||
<div ng-hide="canNotChangePassword" class="alert alert-danger">
|
||||
<p>{% trans "Cannot change password for " %}<strong>{$ dbUsername
|
||||
$}</strong>, {% trans "Error message:" %} {$ errorMessage $}</p>
|
||||
</div>
|
||||
|
||||
|
||||
<div ng-hide="couldNotConnect" class="alert alert-danger">
|
||||
<p>{% trans "Could Not Connect to server. Please refresh this page" %}</p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div ng-hide="changePasswordBox" class="form-group">
|
||||
<label class="col-sm-3 control-label">{$ dbUsername $}</label>
|
||||
<div class="col-sm-6">
|
||||
<input name="dom" type="password" class="form-control" ng-model="dbPassword" required>
|
||||
</div>
|
||||
|
||||
<div class="col-sm-3">
|
||||
<button type="button" ng-click="generatePassword()"
|
||||
class="btn btn-primary">{% trans "Generate" %}</button>
|
||||
</div>
|
||||
|
||||
<label ng-hide="generatedPasswordView" style="margin-top: 1%" class="col-sm-3 control-label">{% trans "Generated Password" %}</label>
|
||||
<div ng-hide="generatedPasswordView" style="margin-top: 1%" class="col-sm-6">
|
||||
<input name="dom" type="text" class="form-control" ng-model="dbPassword" required>
|
||||
</div>
|
||||
|
||||
<div ng-hide="generatedPasswordView" style="margin-top: 1%" class="col-sm-3">
|
||||
<button type="button" ng-click="usePassword()"
|
||||
class="btn btn-primary">{% trans "Use" %}</button>
|
||||
</div>
|
||||
|
||||
|
||||
<div style="margin-top: 1%" class="col-sm-6 col-md-offset-3">
|
||||
<button type="button" ng-click="changePasswordBtn()"
|
||||
class="btn btn-primary btn-lg">{% trans "Change Password" %}</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!------ List of records --------------->
|
||||
|
||||
<div ng-hide="dbAccounts" class="form-group">
|
||||
|
||||
<div class="col-sm-12">
|
||||
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{% trans "ID" %}</th>
|
||||
<th>{% trans "Database Name" %}</th>
|
||||
<th>{% trans "Database User" %}</th>
|
||||
<th>{% trans "Password" %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="record in records track by $index">
|
||||
<td ng-bind="record.id"></td>
|
||||
<td ng-bind="record.dbName"></td>
|
||||
<td ng-bind="record.dbUser"></td>
|
||||
<td>
|
||||
<button type="button" ng-click="changePassword(record.dbUser)"
|
||||
class="btn ra-100 btn-purple">{% trans "Change" %}</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!------ List of records --------------->
|
||||
|
||||
|
||||
</form>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
{% endblock %}
|
||||
|
||||
73
databases/templates/databases/phpMyAdmin.html
Normal file
73
databases/templates/databases/phpMyAdmin.html
Normal file
@@ -0,0 +1,73 @@
|
||||
{% extends "baseTemplate/index.html" %}
|
||||
{% load i18n %}
|
||||
{% block title %}{% trans "phpMyAdmin - CyberPanel" %}{% endblock %}
|
||||
{% block content %}
|
||||
|
||||
{% load static %}
|
||||
{% get_current_language as LANGUAGE_CODE %}
|
||||
<!-- Current language: {{ LANGUAGE_CODE }} -->
|
||||
|
||||
<div class="container">
|
||||
<div id="page-title">
|
||||
<h2>{% trans "Create Database" %}</h2>
|
||||
<p>{% trans "Create a new database on this page." %}</p>
|
||||
</div>
|
||||
|
||||
<div ng-controller="phpMyAdmin" class="panel">
|
||||
<div class="panel-body">
|
||||
<h3 class="content-box-header">
|
||||
{% trans "Create Database" %} <img ng-hide="createDatabaseLoading" src="{% static 'images/loading.gif' %}">
|
||||
</h3>
|
||||
<div class="example-box-wrapper">
|
||||
|
||||
<form class="form-horizontal bordered-row panel-body">
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans "Select Website" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<select ng-change="showDetailsBoxes()" ng-model="databaseWebsite" class="form-control">
|
||||
{% for items in websitesList %}
|
||||
<option>{{ items }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label"></label>
|
||||
<div class="col-sm-4">
|
||||
<div ng-hide="databaseCreationFailed" class="alert alert-danger">
|
||||
<p>{% trans "Cannot create database. Error message:" %} {$ errorMessage $}</p>
|
||||
</div>
|
||||
|
||||
<div ng-hide="databaseCreated" class="alert alert-success">
|
||||
<p>{% trans "Database created successfully." %}</p>
|
||||
</div>
|
||||
|
||||
|
||||
<div ng-hide="couldNotConnect" class="alert alert-danger">
|
||||
<p>{% trans "Could not connect to server. Please refresh this page." %}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</form>
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
@@ -14,4 +14,6 @@ urlpatterns = [
|
||||
url(r'^listDBs', views.listDBs, name='listDBs'),
|
||||
|
||||
url(r'^changePassword', views.changePassword, name='changePassword'),
|
||||
url(r'^phpMyAdmin$', views.phpMyAdmin, name='phpMyAdmin'),
|
||||
url(r'^setupPHPMYAdminSession$', views.setupPHPMYAdminSession, name='setupPHPMYAdminSession'),
|
||||
]
|
||||
@@ -1,340 +1,157 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.shortcuts import render,redirect
|
||||
from django.http import HttpResponse
|
||||
from loginSystem.models import Administrator
|
||||
from websiteFunctions.models import Websites
|
||||
import plogical.CyberCPLogFileWriter as logging
|
||||
from plogical.mysqlUtilities import mysqlUtilities
|
||||
from django.shortcuts import redirect, HttpResponse
|
||||
from loginSystem.views import loadLoginPage
|
||||
from models import Databases
|
||||
from databaseManager import DatabaseManager
|
||||
from pluginManager import pluginManager
|
||||
import json
|
||||
import shlex
|
||||
import subprocess
|
||||
from plogical.processUtilities import ProcessUtilities
|
||||
from loginSystem.models import Administrator
|
||||
import CyberCP.settings as settings
|
||||
# Create your views here.
|
||||
|
||||
|
||||
def loadDatabaseHome(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
try:
|
||||
return render(request, 'databases/index.html')
|
||||
except BaseException, msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
||||
return HttpResponse(str(msg))
|
||||
|
||||
userID = request.session['userID']
|
||||
dm = DatabaseManager()
|
||||
return dm.loadDatabaseHome(request, userID)
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def createDatabase(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
try:
|
||||
admin = Administrator.objects.get(pk=val)
|
||||
result = pluginManager.preCreateDatabase(request)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
if admin.type == 1:
|
||||
websites = Websites.objects.all()
|
||||
websitesName = []
|
||||
userID = request.session['userID']
|
||||
dm = DatabaseManager()
|
||||
coreResult = dm.createDatabase(request, userID)
|
||||
|
||||
for items in websites:
|
||||
websitesName.append(items.domain)
|
||||
else:
|
||||
if admin.type == 2:
|
||||
websites = Websites.objects.filter(admin=admin)
|
||||
admins = Administrator.objects.filter(owner=admin.pk)
|
||||
websitesName = []
|
||||
result = pluginManager.postCreateDatabase(request, coreResult)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
for items in websites:
|
||||
websitesName.append(items.domain)
|
||||
return coreResult
|
||||
|
||||
for items in admins:
|
||||
webs = Websites.objects.filter(admin=items)
|
||||
|
||||
for web in webs:
|
||||
websitesName.append(web.domain)
|
||||
else:
|
||||
websitesName = []
|
||||
websites = Websites.objects.filter(admin=admin)
|
||||
for items in websites:
|
||||
websitesName.append(items.domain)
|
||||
|
||||
|
||||
return render(request, 'databases/createDatabase.html', {'websitesList':websitesName})
|
||||
except BaseException, msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
||||
return HttpResponse(str(msg))
|
||||
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
|
||||
def submitDBCreation(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
admin = Administrator.objects.get(pk=val)
|
||||
try:
|
||||
if request.method == 'POST':
|
||||
userID = request.session['userID']
|
||||
|
||||
data = json.loads(request.body)
|
||||
databaseWebsite = data['databaseWebsite']
|
||||
dbName = data['dbName']
|
||||
dbUsername = data['dbUsername']
|
||||
dbPassword = data['dbPassword']
|
||||
webUsername = data['webUserName']
|
||||
result = pluginManager.preSubmitDBCreation(request)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
if admin.type != 1:
|
||||
website = Websites.objects.get(domain=databaseWebsite)
|
||||
if website.admin != admin:
|
||||
dic = {'createDBStatus': 0, 'error_message': "Only administrator can view this page."}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
dm = DatabaseManager()
|
||||
coreResult = dm.submitDBCreation(userID, json.loads(request.body))
|
||||
|
||||
dbName = webUsername+"_"+dbName
|
||||
dbUsername = webUsername+"_"+dbUsername
|
||||
result = pluginManager.postSubmitDBCreation(request, coreResult)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
result = mysqlUtilities.submitDBCreation(dbName, dbUsername, dbPassword, databaseWebsite)
|
||||
|
||||
if result[0] == 1:
|
||||
data_ret = {'createDBStatus': 1, 'error_message': "None"}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
else:
|
||||
data_ret = {'createDBStatus': 0, 'error_message': result[1]}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
except BaseException,msg:
|
||||
data_ret = {'createDBStatus': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
except KeyError,msg:
|
||||
data_ret = {'createDBStatus': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
return coreResult
|
||||
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def deleteDatabase(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
try:
|
||||
|
||||
admin = Administrator.objects.get(pk=val)
|
||||
|
||||
if admin.type == 1:
|
||||
websites = Websites.objects.all()
|
||||
websitesName = []
|
||||
|
||||
for items in websites:
|
||||
websitesName.append(items.domain)
|
||||
else:
|
||||
if admin.type == 2:
|
||||
websites = admin.websites_set.all()
|
||||
admins = Administrator.objects.filter(owner=admin.pk)
|
||||
websitesName = []
|
||||
|
||||
for items in websites:
|
||||
websitesName.append(items.domain)
|
||||
|
||||
for items in admins:
|
||||
webs = items.websites_set.all()
|
||||
|
||||
for web in webs:
|
||||
websitesName.append(web.domain)
|
||||
else:
|
||||
websitesName = []
|
||||
websites = Websites.objects.filter(admin=admin)
|
||||
for items in websites:
|
||||
websitesName.append(items.domain)
|
||||
|
||||
|
||||
return render(request, 'databases/deleteDatabase.html', {'websitesList':websitesName})
|
||||
except BaseException, msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
||||
return HttpResponse(str(msg))
|
||||
|
||||
userID = request.session['userID']
|
||||
dm = DatabaseManager()
|
||||
return dm.deleteDatabase(request, userID)
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def fetchDatabases(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
admin = Administrator.objects.get(pk=val)
|
||||
try:
|
||||
|
||||
data = json.loads(request.body)
|
||||
|
||||
databaseWebsite = data['databaseWebsite']
|
||||
|
||||
if admin.type != 1:
|
||||
website = Websites.objects.get(domain=databaseWebsite)
|
||||
if website.admin != admin:
|
||||
dic = {'fetchStatus': 0, 'error_message': "Only administrator can view this page."}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
website = Websites.objects.get(domain=databaseWebsite)
|
||||
|
||||
|
||||
databases = Databases.objects.filter(website=website)
|
||||
|
||||
json_data = "["
|
||||
checker = 0
|
||||
|
||||
for items in databases:
|
||||
dic = { 'id':items.pk,
|
||||
'dbName': items.dbName,
|
||||
'dbUser': items.dbUser,}
|
||||
|
||||
if checker == 0:
|
||||
json_data = json_data + json.dumps(dic)
|
||||
checker = 1
|
||||
else:
|
||||
json_data = json_data + ',' + json.dumps(dic)
|
||||
|
||||
json_data = json_data + ']'
|
||||
|
||||
final_json = json.dumps({'fetchStatus': 1, 'error_message': "None", "data": json_data})
|
||||
|
||||
return HttpResponse(final_json)
|
||||
except BaseException, msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
||||
final_json = json.dumps({'fetchStatus': 0, 'error_message': str(msg)})
|
||||
return HttpResponse(final_json)
|
||||
|
||||
except KeyError:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
||||
final_json = json.dumps({'fetchStatus': 0, 'error_message': "Not logged in."})
|
||||
return HttpResponse(final_json)
|
||||
|
||||
|
||||
def submitDatabaseDeletion(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
admin = Administrator.objects.get(pk=val)
|
||||
try:
|
||||
if request.method == 'POST':
|
||||
|
||||
|
||||
data = json.loads(request.body)
|
||||
dbName = data['dbName']
|
||||
|
||||
if admin.type != 1:
|
||||
db = Databases.objects.get(dbName=dbName)
|
||||
if db.website.admin != admin:
|
||||
dic = {'deleteStatus': 0, 'error_message': "Only administrator can view this page."}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
result = mysqlUtilities.submitDBDeletion(dbName)
|
||||
|
||||
if result[0] == 1:
|
||||
data_ret = {'deleteStatus': 1, 'error_message': "None"}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
else:
|
||||
data_ret = {'deleteStatus': 0, 'error_message': result[1]}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
|
||||
except BaseException,msg:
|
||||
data_ret = {'deleteStatus': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
except KeyError,msg:
|
||||
data_ret = {'deleteStatus': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
|
||||
def listDBs(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
try:
|
||||
admin = Administrator.objects.get(pk=val)
|
||||
|
||||
if admin.type == 1:
|
||||
websites = Websites.objects.all()
|
||||
websitesName = []
|
||||
|
||||
for items in websites:
|
||||
websitesName.append(items.domain)
|
||||
else:
|
||||
if admin.type == 2:
|
||||
websites = admin.websites_set.all()
|
||||
admins = Administrator.objects.filter(owner=admin.pk)
|
||||
websitesName = []
|
||||
|
||||
for items in websites:
|
||||
websitesName.append(items.domain)
|
||||
|
||||
for items in admins:
|
||||
webs = items.websites_set.all()
|
||||
|
||||
for web in webs:
|
||||
websitesName.append(web.domain)
|
||||
else:
|
||||
websitesName = []
|
||||
websites = Websites.objects.filter(admin=admin)
|
||||
for items in websites:
|
||||
websitesName.append(items.domain)
|
||||
|
||||
return render(request, 'databases/listDataBases.html', {'websiteList':websitesName})
|
||||
except BaseException, msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
||||
return HttpResponse(str(msg))
|
||||
|
||||
userID = request.session['userID']
|
||||
dm = DatabaseManager()
|
||||
return dm.fetchDatabases(userID, json.loads(request.body))
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def submitDatabaseDeletion(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
result = pluginManager.preSubmitDatabaseDeletion(request)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
dm = DatabaseManager()
|
||||
coreResult = dm.submitDatabaseDeletion(userID, json.loads(request.body))
|
||||
|
||||
result = pluginManager.postSubmitDatabaseDeletion(request, coreResult)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
return coreResult
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def listDBs(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
dm = DatabaseManager()
|
||||
return dm.listDBs(request, userID)
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def changePassword(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
admin = Administrator.objects.get(pk=val)
|
||||
try:
|
||||
if request.method == 'POST':
|
||||
userID = request.session['userID']
|
||||
|
||||
data = json.loads(request.body)
|
||||
userName = data['dbUserName']
|
||||
dbPassword = data['dbPassword']
|
||||
result = pluginManager.preChangePassword(request)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
if admin.type != 1:
|
||||
db = Databases.objects.get(dbName=userName)
|
||||
if db.website.admin != admin:
|
||||
dic = {'changePasswordStatus': 0, 'error_message': "Only administrator can view this page."}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
dm = DatabaseManager()
|
||||
coreResult = dm.changePassword(userID, json.loads(request.body))
|
||||
|
||||
passFile = "/etc/cyberpanel/mysqlPassword"
|
||||
result = pluginManager.postChangePassword(request, coreResult)
|
||||
if result != 200:
|
||||
return result
|
||||
|
||||
f = open(passFile)
|
||||
data = f.read()
|
||||
password = data.split('\n', 1)[0]
|
||||
return coreResult
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def phpMyAdmin(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
dm = DatabaseManager()
|
||||
return dm.phpMyAdmin(request, userID)
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
passwordCMD = "use mysql;SET PASSWORD FOR '" + userName + "'@'localhost' = PASSWORD('" + dbPassword + "');FLUSH PRIVILEGES;"
|
||||
def setupPHPMYAdminSession(request):
|
||||
try:
|
||||
|
||||
command = 'sudo mysql -u root -p' + password + ' -e "' + passwordCMD + '"'
|
||||
cmd = shlex.split(command)
|
||||
res = subprocess.call(cmd)
|
||||
userID = request.session['userID']
|
||||
admin = Administrator.objects.get(id = userID)
|
||||
|
||||
if res == 1:
|
||||
data_ret = {'changePasswordStatus': 0, 'error_message': "Please see CyberPanel main log file."}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
execPath = "/usr/local/CyberCP/bin/python2 /usr/local/CyberCP/databases/databaseManager.py"
|
||||
execPath = execPath + " generatePHPMYAdminData --userID " + str(userID)
|
||||
|
||||
output = ProcessUtilities.outputExecutioner(execPath)
|
||||
|
||||
data_ret = {'changePasswordStatus': 1, 'error_message': "None"}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
except BaseException,msg:
|
||||
data_ret = {'changePasswordStatus': 0, 'error_message': str(msg)}
|
||||
if output.find("1,") > -1:
|
||||
request.session['PMA_single_signon_user'] = admin.userName
|
||||
request.session['PMA_single_signon_password'] = output.split(',')[1]
|
||||
data_ret = {'status': 1}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
except KeyError,msg:
|
||||
data_ret = {'changePasswordStatus': 0, 'error_message': str(msg)}
|
||||
else:
|
||||
data_ret = {'status': 1}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
|
||||
except BaseException, msg:
|
||||
data_ret = {'status': 0, 'createDBStatus': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
Reference in New Issue
Block a user