Database App

This commit is contained in:
Zarak Khan
2024-01-12 20:22:49 +05:00
parent 58d11cce81
commit 039e9592ff
9 changed files with 1193 additions and 36 deletions

View File

@@ -12,6 +12,8 @@
<script src="{% static 'baseTemplate/angularjs.1.6.5.js' %}"></script>
<script src="{% static 'baseTemplate/jquery.3.2.1.js' %}"></script>
<link rel="stylesheet" type="text/css" href="{% static 'baseTemplate/custom-js/pnotify.custom.min.css' %}">
<link type="text/css" href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css"
rel="stylesheet"/>
</head>
<body>
@@ -531,22 +533,22 @@
</div>
<ul id="dropdown-example-5" class="hidden py-2 space-y-2">
<li>
<a href="#"
<a href="{% url 'createDatabaseV2' %}"
class="flex items-center w-full text-base font-normal text-white transition duration-75 rounded-lg group hover:bg-cyan-400 dark:text-white dark:hover:bg-gray-700 pl-11">
Create Database</a>
</li>
<li>
<a href="#"
<a href="{% url 'listDBsV2' %}"
class="flex items-center w-full text-base font-normal text-white transition duration-75 rounded-lg group hover:bg-cyan-400 dark:text-white dark:hover:bg-gray-700 pl-11">
List Database</a>
</li>
<li>
<a href="#"
<a href="{% url 'deleteDatabaseV2' %}"
class="flex items-center w-full text-base font-normal text-white transition duration-75 rounded-lg group hover:bg-cyan-400 dark:text-white dark:hover:bg-gray-700 pl-11">
Delete Database</a>
</li>
<li>
<a href="#"
<a href="{% url 'phpMyAdminV2' %}"
class="flex items-center w-full text-base font-normal text-white transition duration-75 rounded-lg group hover:bg-cyan-400 dark:text-white dark:hover:bg-gray-700 pl-11">
PHPMYAdmin</a>
</li>
@@ -1665,11 +1667,13 @@
<!-- Connecting JS -->
{#<script src="homepage.js"></script>#}
<script src="https://cdnjs.cloudflare.com/ajax/libs/qrious/4.0.2/qrious.js"></script>
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
<script src="{% static 'baseTemplate/custom-js/pnotify.custom.min.js' %}"></script>
<script src="{% static 'baseTemplate/newBase.js' %}"></script>
<script src="{% static 'websiteFunctions/websiteFunctionsV2.js' %}"></script>
<script src="{% static 'userManagment/userManagementV2.js' %}"></script>
<script src="{% static 'packages/packagesV2.js' %}"></script>
<script src="{% static 'databases/databasesV2.js' %}"></script>
</body>
</html>

View File

@@ -2,6 +2,7 @@
import os.path
import sys
import django
sys.path.append('/usr/local/CyberCP')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
django.setup()
@@ -18,28 +19,40 @@ import plogical.randomPassword as randomPassword
from plogical.httpProc import httpProc
from backup.models import DBUsers
class DatabaseManager:
class DatabaseManager:
REMOTE_ACCESS = 'remote_access'
def loadDatabaseHome(self, request = None, userID = None):
def loadDatabaseHome(self, request=None, userID=None):
template = 'databases/index.html'
proc = httpProc(request, template, None, 'createDatabase')
return proc.render()
def phpMyAdmin(self, request = None, userID = None):
def phpMyAdmin(self, request=None, userID=None):
template = 'databases/phpMyAdmin.html'
proc = httpProc(request, template, None, 'createDatabase')
return proc.render()
def createDatabase(self, request = None, userID = None):
def phpMyAdminV2(self, request=None, userID=None):
template = 'databases/phpMyAdminV2.html'
proc = httpProc(request, template, None, 'createDatabase')
return proc.render()
def createDatabase(self, request=None, userID=None):
currentACL = ACLManager.loadedACL(userID)
websitesName = ACLManager.findAllSites(currentACL, userID)
template = 'databases/createDatabase.html'
proc = httpProc(request, template, {'websitesList': websitesName}, 'createDatabase')
return proc.render()
def submitDBCreation(self, userID = None, data = None, rAPI = None):
def createDatabaseV2(self, request=None, userID=None):
currentACL = ACLManager.loadedACL(userID)
websitesName = ACLManager.findAllSites(currentACL, userID)
template = 'databases/createDatabaseV2.html'
proc = httpProc(request, template, {'websitesList': websitesName}, 'createDatabase')
return proc.render()
def submitDBCreation(self, userID=None, data=None, rAPI=None):
try:
currentACL = ACLManager.loadedACL(userID)
@@ -77,14 +90,21 @@ class DatabaseManager:
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
def deleteDatabase(self, request = None, userID = None):
def deleteDatabase(self, request=None, userID=None):
currentACL = ACLManager.loadedACL(userID)
websitesName = ACLManager.findAllSites(currentACL, userID)
template = 'databases/deleteDatabase.html'
proc = httpProc(request, template, {'websitesList': websitesName}, 'deleteDatabase')
return proc.render()
def fetchDatabases(self, userID = None, data = None):
def deleteDatabaseV2(self, request=None, userID=None):
currentACL = ACLManager.loadedACL(userID)
websitesName = ACLManager.findAllSites(currentACL, userID)
template = 'databases/deleteDatabaseV2.html'
proc = httpProc(request, template, {'websitesList': websitesName}, 'deleteDatabase')
return proc.render()
def fetchDatabases(self, userID=None, data=None):
try:
currentACL = ACLManager.loadedACL(userID)
@@ -126,7 +146,7 @@ class DatabaseManager:
final_json = json.dumps({'status': 0, 'fetchStatus': 0, 'error_message': str(msg)})
return HttpResponse(final_json)
def submitDatabaseDeletion(self, userID = None, data = None):
def submitDatabaseDeletion(self, userID=None, data=None):
try:
currentACL = ACLManager.loadedACL(userID)
admin = Administrator.objects.get(pk=userID)
@@ -157,14 +177,21 @@ class DatabaseManager:
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
def listDBs(self, request = None, userID = None):
def listDBs(self, request=None, userID=None):
currentACL = ACLManager.loadedACL(userID)
AllWebsites = ACLManager.findAllSites(currentACL, userID)
template = 'databases/listDataBases.html'
proc = httpProc(request, template, {'AllWebsites': AllWebsites}, 'listDatabases')
return proc.render()
def changePassword(self, userID = None, data = None):
def listDBsV2(self, request=None, userID=None):
currentACL = ACLManager.loadedACL(userID)
AllWebsites = ACLManager.findAllSites(currentACL, userID)
template = 'databases/listDataBasesV2.html'
proc = httpProc(request, template, {'AllWebsites': AllWebsites}, 'listDatabases')
return proc.render()
def changePassword(self, userID=None, data=None):
try:
currentACL = ACLManager.loadedACL(userID)
@@ -192,7 +219,8 @@ class DatabaseManager:
res = mysqlUtilities.changePassword(userName, dbPassword, None, host)
if res == 0:
data_ret = {'status': 0, 'changePasswordStatus': 0,'error_message': "Please see CyberPanel main log file."}
data_ret = {'status': 0, 'changePasswordStatus': 0,
'error_message': "Please see CyberPanel main log file."}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
@@ -205,7 +233,7 @@ class DatabaseManager:
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
def remoteAccess(self, userID = None, data = None):
def remoteAccess(self, userID=None, data=None):
try:
currentACL = ACLManager.loadedACL(userID)
@@ -234,11 +262,11 @@ class DatabaseManager:
return HttpResponse(json_data)
except BaseException as msg:
data_ret = {'status': 0,'error_message': str(msg)}
data_ret = {'status': 0, 'error_message': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
def allowRemoteIP(self, userID = None, data = None):
def allowRemoteIP(self, userID=None, data=None):
try:
currentACL = ACLManager.loadedACL(userID)
@@ -269,14 +297,14 @@ class DatabaseManager:
meta.value = json.dumps(metaData)
meta.save()
except:
DBMeta(database=db[0], value = json.dumps(metaData), key=DatabaseManager.REMOTE_ACCESS).save()
DBMeta(database=db[0], value=json.dumps(metaData), key=DatabaseManager.REMOTE_ACCESS).save()
data_ret = {'status': 1}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except BaseException as msg:
data_ret = {'status': 0,'error_message': str(msg)}
data_ret = {'status': 0, 'error_message': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
@@ -287,7 +315,6 @@ class DatabaseManager:
admin = Administrator.objects.get(id=userID)
path = '/etc/cyberpanel/' + admin.userName
currentACL = ACLManager.loadedACL(userID)
websiteOBJs = ACLManager.findWebsiteObjects(currentACL, userID)
finalUserPassword = randomPassword.generate_pass()
@@ -308,14 +335,13 @@ class DatabaseManager:
except BaseException as msg:
print("0," + str(msg))
def main():
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":
@@ -323,4 +349,4 @@ def main():
if __name__ == "__main__":
main()
main()

View File

@@ -0,0 +1,601 @@
newapp.controller('createDatabaseV2', function ($scope, $http) {
$(document).ready(function () {
$(".dbDetails").hide();
$(".generatedPasswordDetails").hide();
$('#create-database-select').select2();
});
$('#create-database-select').on('select2:select', function (e) {
var data = e.params.data;
$scope.databaseWebsite = data.text;
$(".dbDetails").show();
$("#domainDatabase").text(getWebsiteName(data.text));
$("#domainUsername").text(getWebsiteName(data.text));
});
$scope.showDetailsBoxes = function () {
$scope.dbDetails = false;
}
$scope.createDatabaseLoading = true;
$scope.createDatabase = function () {
$scope.createDatabaseLoading = false;
$scope.dbDetails = 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;
new PNotify({
title: 'Success!',
text: 'Database successfully created.',
type: 'success'
});
} else {
$scope.createDatabaseLoading = true;
$scope.dbDetails = false;
new PNotify({
title: 'Operation Failed!',
text: response.data.error_message,
type: 'error'
});
}
}
function cantLoadInitialDatas(response) {
$scope.createDatabaseLoading = true;
$scope.dbDetails = true;
new PNotify({
title: 'Operation Failed!',
text: 'Could not connect to server, please refresh this page',
type: 'error'
});
}
};
$scope.generatePassword = function () {
$(".generatedPasswordDetails").show();
$scope.dbPassword = randomPassword(16);
};
$scope.usePassword = function () {
$(".generatedPasswordDetails").hide();
};
});
function getWebsiteName(domain) {
if (domain !== undefined) {
domain = domain.replace(/-/g, '');
var domainName = domain.split(".");
var finalDomainName = domainName[0];
if (finalDomainName.length > 5) {
finalDomainName = finalDomainName.substring(0, 4);
}
return finalDomainName;
}
}
newapp.controller('deleteDatabaseV2', function ($scope, $http) {
$scope.deleteDatabaseLoading = true;
$scope.fetchedDatabases = true;
$scope.databaseDeletionFailed = true;
$scope.databaseDeleted = true;
$scope.couldNotConnect = true;
$scope.fetchDatabases = function () {
$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;
} 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.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;
$scope.errorMessage = response.data.error_message;
}
}
function cantLoadInitialDatas(response) {
$scope.deleteDatabaseLoading = true;
$scope.fetchedDatabases = true;
$scope.databaseDeletionFailed = true;
$scope.databaseDeleted = true;
$scope.couldNotConnect = false;
}
};
});
newapp.controller('listDBsV2', function ($scope, $http) {
$scope.recordsFetched = true;
$scope.passwordChanged = true;
$scope.canNotChangePassword = true;
$scope.couldNotConnect = true;
$scope.dbLoading = true;
$scope.dbAccounts = true;
$scope.changePasswordBox = true;
$scope.notificationsBox = true;
var globalDBUsername = "";
$scope.fetchDBs = function () {
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;
globalDBUsername = dbUsername;
};
$scope.changePasswordBtn = function () {
$scope.dbLoading = false;
$scope.passwordChanged = true;
url = "/dataBases/changePassword";
var data = {
dbUserName: globalDBUsername,
dbPassword: $scope.dbPassword,
};
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
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;
}
}
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')
}
};
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
if (response.data.fetchStatus == 1) {
$scope.records = JSON.parse(response.data.data);
$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.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.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(16);
};
$scope.usePassword = function () {
$scope.generatedPasswordView = true;
};
$scope.remoteAccess = function (userName) {
$scope.dbUsername = userName;
$scope.dbLoading = false;
url = "/dataBases/remoteAccess";
var data = {
dbUserName: $scope.dbUsername
};
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
$scope.dbLoading = true;
if (response.data.status === 1) {
$scope.dbHost = response.data.dbHost;
} else {
new PNotify({
title: 'Operation Failed!',
text: response.data.error_message,
type: 'error'
});
}
}
function cantLoadInitialDatas(response) {
new PNotify({
title: 'Operation Failed!',
text: 'Could not connect to server, please refresh this page',
type: 'error'
});
$scope.dbLoading = true;
}
};
$scope.allowRemoteIP = function () {
$scope.dbLoading = false;
url = "/dataBases/allowRemoteIP";
var data = {
dbUserName: $scope.dbUsername,
remoteIP: $scope.remoteIP
};
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
$scope.dbLoading = true;
if (response.data.status === 1) {
$scope.remoteAccess($scope.dbUsername);
new PNotify({
title: 'Success',
text: 'Changes applied.',
type: 'success'
});
} else {
new PNotify({
title: 'Operation Failed!',
text: response.data.error_message,
type: 'error'
});
}
}
function cantLoadInitialDatas(response) {
new PNotify({
title: 'Operation Failed!',
text: 'Could not connect to server, please refresh this page',
type: 'error'
});
$scope.dbLoading = true;
}
};
});
newapp.controller('phpMyAdminV2', function ($scope, $http, $window) {
$scope.cyberPanelLoading = true;
$scope.generateAccess = function () {
$scope.cyberPanelLoading = false;
url = "/dataBases/generateAccess";
var data = {};
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
$scope.cyberPanelLoading = true;
if (response.data.status === 1) {
var rUrl = '/phpmyadmin/phpmyadminsignin.php?username=' + response.data.username + '&token=' + response.data.token;
$window.location.href = rUrl;
} else {
}
}
function cantLoadInitialDatas(response) {
$scope.cyberPanelLoading = true;
}
}
});

View File

@@ -0,0 +1,96 @@
{% extends "baseTemplate/newBase.html" %}
{% load i18n %}
{% block titleNew %}{% trans "Home - CyberPanel" %}{% endblock %}
{% block newContent %}
{% load static %}
<div ng-controller="createDatabaseV2" class="p-8">
<div>
<p class="text-4xl font-bold">Create Database</p>
<p class="text-xs text-gray-600 py-2 font-semibold">Create a new database on this page.</p>
</div>
<div>
<div class="py-4">
<p class="text-xl font-bold">Create Database</p>
<img ng-hide="createDatabaseLoading" src="{% static 'images/loading.gif' %}">
</div>
<hr>
<div>
<div class="flex mt-4 py-2 px-6">
<div>
<p class="font-semibold w-60">Select Website</p>
</div>
<div>
<select id="create-database-select" ng-model="databaseWebsite"
class="w-80 bg-gray-100 rounded px-2 py-1">
{% for items in websitesList %}
<option>{{ items }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="flex py-2 px-6 dbDetails">
<div>
<p class="font-semibold w-60">Database Name</p>
</div>
<div>
<input name="dom" type="text" class="w-80 bg-gray-100 rounded px-2 py-1" ng-model="dbName"
required>
</div>
<div class="text-orange-500 font-semibold ml-3">
<p><span id="domainDatabase"></span>_{$ dbName $}</p>
</div>
</div>
<div class="flex py-2 px-6 dbDetails">
<div>
<p class="font-semibold w-60">Username</p>
</div>
<div>
<input type="text" name="email" class="w-80 bg-gray-100 rounded px-2 py-1" ng-model="dbUsername"
required>
</div>
<div class="text-orange-500 font-semibold ml-3"><p><span id="domainUsername"></span>_{$ dbUsername
$}</p></div>
</div>
<div class="flex py-2 px-6 dbDetails">
<div>
<p class="font-semibold w-60">Password</p>
</div>
<div>
<input type="password" name="email" class="w-80 bg-gray-100 rounded px-2 py-1"
ng-model="dbPassword" required>
</div>
<div class="w-80 ml-4">
<button ng-click="generatePassword()" class="bg-orange-500 text-white font-semibold px-2 py-1">
Generate
</button>
</div>
</div>
<div>
<div class="flex py-2 px-6 generatedPasswordDetails">
<div>
<p class="font-semibold w-60">Generated Password</p>
</div>
<div>
<input type="text" name="email" class="w-80 bg-gray-100 rounded px-2 py-1"
ng-model="dbPassword" required>
</div>
<div class="w-80 ml-4">
<button ng-click="usePassword()"
class="bg-orange-500 text-white font-semibold px-2 py-1">
Use
</button>
</div>
</div>
</div>
<div class="flex justify-center mt-6 dbDetails">
<button ng-click="createDatabase()" class="bg-orange-500 text-white font-bold px-4 py-2 text-xl">
Create Database
</button>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@@ -0,0 +1,71 @@
{% extends "baseTemplate/newBase.html" %}
{% load i18n %}
{% block titleNew %}{% trans "Home - CyberPanel" %}{% endblock %}
{% block newContent %}
{% load static %}
<div ng-controller="deleteDatabaseV2" class="p-8">
<div>
<p class="text-4xl font-bold">Delete Database</p>
<p class="text-xs text-gray-600 py-2 font-semibold">Delete an existing database on this page.</p>
</div>
<div>
<div class="py-4">
<p class="text-xl font-bold">Delete Database</p>
<img ng-hide="deleteDatabaseLoading" src="{% static 'images/loading.gif' %}">
</div>
<hr>
<div>
<div class="flex mt-4 py-2 px-6">
<div>
<p class="font-semibold w-60">Select Website</p>
</div>
<div>
<select ng-change="fetchDatabases()" ng-model="databaseWebsite"
class="w-80 bg-gray-100 rounded px-2 py-1">
{% for items in websitesList %}
<option>{{ items }}</option>
{% endfor %}
</select>
</div>
</div>
<div ng-hide="fetchedDatabases" class="flex mt-4 py-2 px-6">
<div>
<p class="font-semibold w-60">Select Database</p>
</div>
<div>
<select ng-model="selectedDB" class="w-80 bg-gray-100 rounded px-2 py-1">
<option ng-repeat="db in dbnames track by $index">{$ db.dbName $}</option>
</select>
</div>
</div>
<div ng-hide="fetchedDatabases" class="flex justify-center mt-6">
<button ng-click="deleteDatabase()"
class="bg-orange-500 text-white font-bold px-4 py-2 text-xl">
Delete Database
</button>
</div>
<div class="mt-4">
<label class="col-sm-3 control-label"></label>
<div>
<div ng-hide="databaseDeleted"
class="flex justify-center bg-green-500 px-2 rounded-lg py-1 font-semibold">
<p>{% trans "Database deleted successfully." %}</p>
</div>
<div ng-hide="databaseDeletionFailed"
class="flex justify-center bg-red-500 rounded-lg text-white px-2 py-1 font-semibold">
<p>{% trans "Error message:" %} {$ errorMessage $}</p>
</div>
<div ng-hide="couldNotConnect"
class="flex justify-center bg-red-500 rounded-lg text-white px-2 py-1 font-semibold">
<p>{% trans "Could not connect to server. Please refresh this page." %}</p>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@@ -0,0 +1,260 @@
{% extends "baseTemplate/newBase.html" %}
{% load i18n %}
{% block titleNew %}{% trans "Home - CyberPanel" %}{% endblock %}
{% block newContent %}
{% load static %}
<div ng-controller="listDBsV2" class="p-8">
<div class="flex lg:flex-row justify-between items-center sm:flex-col">
<div>
<p class="text-4xl font-bold">List Database</p>
<p class="text-xs text-gray-600 py-2 font-semibold">List databases or change their passwords.</p>
</div>
</div>
<div class="py-4">
<p class="text-xl font-bold">List Database</p>
<img ng-hide="dbLoading" src="{% static 'images/loading.gif' %}">
</div>
<hr>
<div class="flex mt-4 py-2 px-6">
<div>
<p class="font-semibold w-60">Select Domain</p>
</div>
<div>
<select ng-change="fetchDBs()" ng-model="selectedDomain" class="w-80 bg-gray-100 rounded px-2 py-1">
{% for items in AllWebsites %}
<option>{{ items }}</option>
{% endfor %}
</select>
</div>
</div>
<hr>
<div ng-hide="notificationsBox" class="py-4">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-6">
<div ng-hide="recordsFetched"
class="flex justify-center bg-green-500 px-2 rounded-lg py-1 font-semibold">
<p>{% trans "Records successfully fetched for" %} <strong>{$ domainFeteched
$}</strong></p>
</div>
<div ng-hide="passwordChanged"
class="flex justify-center bg-green-500 px-2 rounded-lg py-1 font-semibold">
{% trans "Password changed for: " %} <strong>{$ dbUsername $}</strong>
</div>
<div ng-hide="canNotChangePassword"
class="flex justify-center bg-red-500 rounded-lg text-white px-2 py-1 font-semibold">
<p>{% trans "Cannot change password for " %}<strong>{$ dbUsername
$}</strong>, {% trans "Error message:" %} {$ errorMessage $}</p>
</div>
<div ng-hide="couldNotConnect"
class="flex justify-center bg-red-500 rounded-lg text-white px-2 py-1 font-semibold">
<p>{% trans "Could Not Connect to server. Please refresh this page" %}</p>
</div>
</div>
</div>
<hr>
<div ng-hide="changePasswordBox" class="mb-3">
<div class="flex py-2 px-6 dbDetails">
<div>
<p class="font-semibold w-60">{$ dbUsername $}</p>
</div>
<div>
<input name="dom" type="password" class="w-80 bg-gray-100 rounded px-2 py-1" ng-model="dbPassword"
required>
</div>
<div class="w-80 ml-4">
<button ng-click="generatePassword()" class="bg-orange-500 text-white font-semibold px-2 py-1">
Generate
</button>
</div>
</div>
<div>
<div ng-hide="generatedPasswordView" class="flex py-2 px-6">
<div>
<p class="font-semibold w-60">Generated Password</p>
</div>
<div>
<input name="dom" type="text" class="w-80 bg-gray-100 rounded px-2 py-1" ng-model="dbPassword"
required>
</div>
<div class="w-80 ml-4">
<button ng-click="usePassword()"
class="bg-orange-500 text-white font-semibold px-2 py-1">
Use
</button>
</div>
</div>
</div>
<div class="flex justify-center mt-6">
<button ng-click="changePasswordBtn()"
class="bg-orange-500 text-white font-bold px-4 py-2 text-xl">
Change Password
</button>
</div>
</div>
<hr>
<div class="relative py-5 overflow-x-auto">
<table class="w-full text-sm text-left rtl:text-right">
<thead>
<tr>
<th scope="col" class="px-6 py-3">
ID
</th>
<th scope="col" class="px-6 py-3">
Database Name
</th>
<th scope="col" class="px-6 py-3">
Database User
</th>
<th scope="col" class="px-6 py-3">
Password
</th>
<th scope="col" class="px-6 py-3">
Remote Access
</th>
</tr>
</thead>
<tbody ng-repeat="record in records track by $index"
class="border shadow-lg py-3 px-6 rounded-b-lg">
<tr>
<td ng-bind="record.id" class="px-6 py-4">
</td>
<td ng-bind="record.dbName" class="px-6 py-4">
</td>
<td ng-bind="record.dbUser" class="px-6 py-4">
</td>
<td class="px-6 py-4">
<button type="button" ng-click="changePassword(record.dbUser)"
class="bg-orange-500 text-white font-semibold px-2 py-1">{% trans "Change" %}</button>
</td>
<td class="px-6 py-4">
<button ng-click="remoteAccess(record.dbUser)" data-toggle="modal"
data-target="#remoteAccess" type="button"
class="bg-orange-500 text-white font-semibold px-2 py-1">{% trans "Manage" %}</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
{# <div>#}
{# <button ng-click="deleteUserInitial(record.name)" data-modal-target="DeleteListUser"#}
{# data-modal-toggle="DeleteListUser"#}
{# class="bg-orange-500 px-2 py-1 text-white"#}
{# type="button">#}
{# Delete#}
{# </button>#}
{##}
{# <div id="DeleteListUser" tabindex="-1"#}
{# class="hidden overflow-y-auto overflow-x-hidden fixed top-0 right-0 left-0 z-50 justify-center items-center w-full md:inset-0 h-[calc(100%-1rem)] max-h-full">#}
{# <div class="relative p-4 w-full max-w-md max-h-full">#}
{# <div class="relative bg-white rounded-lg shadow dark:bg-gray-700">#}
{# <button type="button" data-modal-toggle="DeleteListUser"#}
{# class="absolute top-3 end-2.5 text-gray-400 bg-transparent hover:bg-gray-200 hover:text-gray-900 rounded-lg text-sm w-8 h-8 ms-auto inline-flex justify-center items-center dark:hover:bg-gray-600 dark:hover:text-white"#}
{# data-modal-hide="DeleteListUser">#}
{# <svg class="w-3 h-3" aria-hidden="true"#}
{# xmlns="http://www.w3.org/2000/svg" fill="none"#}
{# viewBox="0 0 14 14">#}
{# <path stroke="currentColor" stroke-linecap="round"#}
{# stroke-linejoin="round" stroke-width="2"#}
{# d="m1 1 6 6m0 0 6 6M7 7l6-6M7 7l-6 6"/>#}
{# </svg>#}
{# <span class="sr-only">Close modal</span>#}
{# </button>#}
{# <div class="p-4 md:p-5 text-center">#}
{# <svg class="mx-auto mb-4 text-gray-400 w-12 h-12 dark:text-gray-200"#}
{# aria-hidden="true"#}
{# xmlns="http://www.w3.org/2000/svg" fill="none"#}
{# viewBox="0 0 20 20">#}
{# <path stroke="currentColor" stroke-linecap="round"#}
{# stroke-linejoin="round" stroke-width="2"#}
{# d="M10 11V6m0 8h.01M19 10a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z"/>#}
{# </svg>#}
{# <h3 class="mb-5 text-lg font-normal text-gray-500 dark:text-gray-400">#}
{# Are you sure you want to#}
{# delete this user {$ UserToDelete $} ?</h3>#}
{# <button ng-click="deleteUserFinal()" data-modal-hide="DeleteListUser" type="button"#}
{# data-modal-toggle="DeleteListUser"#}
{# class="text-white bg-red-600 hover:bg-red-800 focus:ring-4 focus:outline-none focus:ring-red-300 dark:focus:ring-red-800 font-medium rounded-lg text-sm inline-flex items-center px-5 py-2.5 text-center me-2">#}
{# Yes, I'm sure#}
{# </button>#}
{# <button data-modal-hide="DeleteListUser" type="button"#}
{# data-modal-toggle="DeleteListUser"#}
{# class="text-gray-500 bg-white hover:bg-gray-100 focus:ring-4 focus:outline-none focus:ring-gray-200 rounded-lg border border-gray-200 text-sm font-medium px-5 py-2.5 hover:text-gray-900 focus:z-10 dark:bg-gray-700 dark:text-gray-300 dark:border-gray-500 dark:hover:text-white dark:hover:bg-gray-600 dark:focus:ring-gray-600">#}
{# No, cancel#}
{# </button>#}
{# </div>#}
{# </div>#}
{# </div>#}
{# </div>#}
{# </div>#}
{# <div>#}
{# <button ng-click="editInitial(record.name)" data-modal-target="EditListUser"#}
{# data-modal-toggle="EditListUser"#}
{# class="bg-orange-500 px-2 py-1 text-white"#}
{# type="button">#}
{# Edit#}
{# </button>#}
{##}
{# <div id="EditListUser" tabindex="-1"#}
{# class="hidden overflow-y-auto overflow-x-hidden fixed top-0 right-0 left-0 z-50 justify-center items-center w-full md:inset-0 h-[calc(100%-1rem)] max-h-full">#}
{# <div>#}
{# <div class="relative bg-white rounded-lg shadow dark:bg-gray-700">#}
{# <h2 class="px-4 py-4 font-bold text-xl">Edit Users</h2>#}
{# <button type="button" data-modal-toggle="EditListUser"#}
{# class="absolute top-3 end-2.5 text-gray-400 bg-transparent hover:bg-gray-200 hover:text-gray-900 rounded-lg text-sm w-8 h-8 ms-auto inline-flex justify-center items-center dark:hover:bg-gray-600 dark:hover:text-white"#}
{# data-modal-hide="EditListUser">#}
{# <svg class="w-3 h-3" aria-hidden="true"#}
{# xmlns="http://www.w3.org/2000/svg" fill="none"#}
{# viewBox="0 0 14 14">#}
{# <path stroke="currentColor" stroke-linecap="round"#}
{# stroke-linejoin="round" stroke-width="2"#}
{# d="m1 1 6 6m0 0 6 6M7 7l6-6M7 7l-6 6"/>#}
{# </svg>#}
{# <span class="sr-only">Close modal</span>#}
{# </button>#}
{# <div class="p-4">#}
{# <div ng-hide="installationDetailsForm" class="flex mt-4 py-2 px-6">#}
{# <div>#}
{# <p class="font-semibold w-60">Name</p>#}
{# </div>#}
{# <div>#}
{# <input name="name" type="text" class="w-80 bg-gray-100 rounded px-2 py-1"#}
{# ng-model="name" readonly>#}
{# </div>#}
{# </div>#}
{# <div class="flex py-2 px-6">#}
{# <div>#}
{# <p class="font-semibold w-60">New Owner</p>#}
{# </div>#}
{# <div>#}
{# <select ng-change="saveResellerChanges()"#}
{# ng-model="$parent.newOwner"#}
{# class="w-80 bg-gray-100 rounded px-2 py-1">#}
{# {% for items in resellerPrivUsers %}#}
{# <option>{{ items }}</option>#}
{# {% endfor %}#}
{# </select>#}
{# </div>#}
{# </div>#}
{# <div class="flex py-2 px-6">#}
{# <div>#}
{# <p class="font-semibold w-60">Select ACL</p>#}
{# </div>#}
{# <div>#}
{# <select ng-change="changeACLFunc()"#}
{# ng-model="$parent.selectedACL"#}
{# class="w-80 bg-gray-100 rounded px-2 py-1">#}
{# {% for items in aclNames %}#}
{# <option>{{ items }}</option>#}
{# {% endfor %}#}
{# </select>#}
{# </div>#}
{# </div>#}
{# </div>#}
{# </div>#}
{# </div>#}
{# </div>#}
{# </div>#}
{% endblock %}

View File

@@ -0,0 +1,42 @@
{% extends "baseTemplate/newBase.html" %}
{% load i18n %}
{% block titleNew %}{% trans "Home - CyberPanel" %}{% endblock %}
{% block newContent %}
{% load static %}
<div ng-controller="phpMyAdminV2" class="p-8">
<div>
<p class="text-4xl font-bold">PHPMYAdmin</p>
<p class="text-xs text-gray-600 py-2 font-semibold">Access your databases via PHPMYAdmin</p>
</div>
<div>
<div class="py-4">
<p class="text-xl font-bold">PHPMYAdmin</p>
<p>Auto-login for PHPMYAdmin is now supported. Click the button below to generate auto-access for
PHPMYAdmin</p>
</div>
<hr>
<div>
<div class="mt-4 py-2 px-6">
<div>
<a ng-click="generateAccess()" href="#">
<button id="phpMyAdminlogin"
class="bg-orange-500 text-white font-bold px-4 py-2 text-xl">
Access Now
</button>
<img ng-hide="cyberPanelLoading" src="{% static 'images/loading.gif' %}">
</a>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function () {
$(function () {
$('#phpMyAdminlogin').click();
});
});
</script>
</div>
{% endblock %}

View File

@@ -4,19 +4,22 @@ from . import views
urlpatterns = [
url(r'^$', views.loadDatabaseHome, name='loadDatabaseHome'),
url(r'^createDatabase', views.createDatabase, name='createDatabase'),
url(r'^V2/createDatabaseV2', views.createDatabaseV2, name='createDatabaseV2'),
url(r'^submitDBCreation', views.submitDBCreation, name='submitDBCreation'),
url(r'^deleteDatabase', views.deleteDatabase, name='deleteDatabase'),
url(r'^V2/deleteDatabaseV2', views.deleteDatabaseV2, name='deleteDatabaseV2'),
url(r'^fetchDatabases', views.fetchDatabases, name='fetchDatabases'),
url(r'^submitDatabaseDeletion', views.submitDatabaseDeletion, name='submitDatabaseDeletion'),
url(r'^listDBs', views.listDBs, name='listDBs'),
url(r'^V2/listDBsV2', views.listDBsV2, name='listDBsV2'),
url(r'^changePassword$', views.changePassword, name='changePassword'),
url(r'^remoteAccess$', views.remoteAccess, name='remoteAccess'),
url(r'^allowRemoteIP$', views.allowRemoteIP, name='allowRemoteIP'),
url(r'^phpMyAdmin$', views.phpMyAdmin, name='phpMyAdmin'),
url(r'^V2/phpMyAdminV2$', views.phpMyAdminV2, name='phpMyAdminV2'),
url(r'^generateAccess$', views.generateAccess, name='generateAccess'),
url(r'^fetchDetailsPHPMYAdmin$', views.fetchDetailsPHPMYAdmin, name='fetchDetailsPHPMYAdmin'),
]
]

View File

@@ -14,6 +14,8 @@ from plogical import randomPassword
from cryptography.fernet import Fernet
from plogical.mysqlUtilities import mysqlUtilities
from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging
# Create your views here.
def loadDatabaseHome(request):
@@ -24,6 +26,7 @@ def loadDatabaseHome(request):
except KeyError:
return redirect(loadLoginPage)
def createDatabase(request):
try:
result = pluginManager.preCreateDatabase(request)
@@ -39,10 +42,31 @@ def createDatabase(request):
return result
return coreResult
except KeyError:
return redirect(loadLoginPage)
def createDatabaseV2(request):
try:
result = pluginManager.preCreateDatabase(request)
if result != 200:
return result
userID = request.session['userID']
dm = DatabaseManager()
coreResult = dm.createDatabaseV2(request, userID)
result = pluginManager.postCreateDatabase(request, coreResult)
if result != 200:
return result
return coreResult
except KeyError:
return redirect(loadLoginPage)
def submitDBCreation(request):
try:
userID = request.session['userID']
@@ -63,6 +87,7 @@ def submitDBCreation(request):
except KeyError:
return redirect(loadLoginPage)
def deleteDatabase(request):
try:
userID = request.session['userID']
@@ -71,6 +96,16 @@ def deleteDatabase(request):
except KeyError:
return redirect(loadLoginPage)
def deleteDatabaseV2(request):
try:
userID = request.session['userID']
dm = DatabaseManager()
return dm.deleteDatabaseV2(request, userID)
except KeyError:
return redirect(loadLoginPage)
def fetchDatabases(request):
try:
userID = request.session['userID']
@@ -79,6 +114,7 @@ def fetchDatabases(request):
except KeyError:
return redirect(loadLoginPage)
def submitDatabaseDeletion(request):
try:
userID = request.session['userID']
@@ -97,6 +133,7 @@ def submitDatabaseDeletion(request):
except KeyError:
return redirect(loadLoginPage)
def listDBs(request):
try:
userID = request.session['userID']
@@ -105,6 +142,16 @@ def listDBs(request):
except KeyError:
return redirect(loadLoginPage)
def listDBsV2(request):
try:
userID = request.session['userID']
dm = DatabaseManager()
return dm.listDBsV2(request, userID)
except KeyError:
return redirect(loadLoginPage)
def changePassword(request):
try:
userID = request.session['userID']
@@ -124,6 +171,7 @@ def changePassword(request):
except KeyError:
return redirect(loadLoginPage)
def remoteAccess(request):
try:
userID = request.session['userID']
@@ -135,6 +183,7 @@ def remoteAccess(request):
except KeyError:
return redirect(loadLoginPage)
def allowRemoteIP(request):
try:
userID = request.session['userID']
@@ -146,6 +195,7 @@ def allowRemoteIP(request):
except KeyError:
return redirect(loadLoginPage)
def phpMyAdmin(request):
try:
userID = request.session['userID']
@@ -153,13 +203,19 @@ def phpMyAdmin(request):
return dm.phpMyAdmin(request, userID)
except KeyError:
return redirect(loadLoginPage)
def phpMyAdminV2(request):
try:
userID = request.session['userID']
dm = DatabaseManager()
return dm.phpMyAdminV2(request, userID)
except KeyError:
return redirect(loadLoginPage)
def generateAccess(request):
try:
userID = request.session['userID']
admin = Administrator.objects.get(id = userID)
admin = Administrator.objects.get(id=userID)
currentACL = ACLManager.loadedACL(userID)
## if user ACL is admin login as root
@@ -181,13 +237,12 @@ def generateAccess(request):
password = randomPassword.generate_pass()
token = randomPassword.generate_pass()
GlobalUserDB(username=admin.userName, password=password,token=token).save()
GlobalUserDB(username=admin.userName, password=password, token=token).save()
data_ret = {'status': 1, 'token': token, 'username': admin.userName}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
keySavePath = '/home/cyberpanel/phpmyadmin_%s' % (admin.userName)
try:
GlobalUserDB.objects.get(username=admin.userName).delete()
@@ -237,18 +292,17 @@ def generateAccess(request):
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
def fetchDetailsPHPMYAdmin(request):
try:
userID = request.session['userID']
admin = Administrator.objects.get(id = userID)
admin = Administrator.objects.get(id=userID)
currentACL = ACLManager.loadedACL(userID)
token = request.GET.get('token')
username = request.GET.get('username')
if username != admin.userName:
return redirect(loadLoginPage)
@@ -268,7 +322,7 @@ def fetchDetailsPHPMYAdmin(request):
password = jsonData['mysqlpassword']
returnURL = '/phpmyadmin/phpmyadminsignin.php?username=%s&password=%s' % (
mysqluser, password)
mysqluser, password)
return redirect(returnURL)
except BaseException:
@@ -302,4 +356,4 @@ def fetchDetailsPHPMYAdmin(request):
except BaseException as 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)