mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2026-02-28 01:10:44 +01:00
Initial Commit
This commit is contained in:
0
databases/__init__.py
Normal file
0
databases/__init__.py
Normal file
BIN
databases/__init__.pyc
Normal file
BIN
databases/__init__.pyc
Normal file
Binary file not shown.
9
databases/admin.py
Normal file
9
databases/admin.py
Normal file
@@ -0,0 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.contrib import admin
|
||||
import models
|
||||
# Register your models here.
|
||||
|
||||
|
||||
admin.site.register(models.Databases)
|
||||
BIN
databases/admin.pyc
Normal file
BIN
databases/admin.pyc
Normal file
Binary file not shown.
8
databases/apps.py
Normal file
8
databases/apps.py
Normal file
@@ -0,0 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class DatabasesConfig(AppConfig):
|
||||
name = 'databases'
|
||||
0
databases/migrations/__init__.py
Normal file
0
databases/migrations/__init__.py
Normal file
12
databases/models.py
Normal file
12
databases/models.py
Normal file
@@ -0,0 +1,12 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models
|
||||
from websiteFunctions.models import Websites
|
||||
|
||||
# Create your models here.
|
||||
|
||||
class Databases(models.Model):
|
||||
website = models.ForeignKey(Websites)
|
||||
dbName = models.CharField(max_length=50,unique=True)
|
||||
dbUser = models.CharField(max_length=50, unique=True)
|
||||
BIN
databases/models.pyc
Normal file
BIN
databases/models.pyc
Normal file
Binary file not shown.
442
databases/static/databases/databases.js
Normal file
442
databases/static/databases/databases.js
Normal file
@@ -0,0 +1,442 @@
|
||||
/**
|
||||
* Created by usman on 8/6/17.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* Java script code to create database */
|
||||
app.controller('createDatabase', function($scope,$http,getwebsitenameFilter) {
|
||||
|
||||
$scope.createDatabaseLoading = true;
|
||||
$scope.dbDetails = true;
|
||||
$scope.databaseCreationFailed = true;
|
||||
$scope.databaseCreated = true;
|
||||
$scope.couldNotConnect = true;
|
||||
|
||||
|
||||
$scope.showDetailsBoxes = function(){
|
||||
$scope.dbDetails = false;
|
||||
};
|
||||
|
||||
|
||||
$scope.createDatabase = function(){
|
||||
|
||||
$scope.createDatabaseLoading = false;
|
||||
$scope.dbDetails = false;
|
||||
$scope.databaseCreationFailed = true;
|
||||
$scope.databaseCreated = true;
|
||||
$scope.couldNotConnect = true;
|
||||
|
||||
|
||||
var databaseWebsite = $scope.databaseWebsite;
|
||||
var dbName = $scope.dbName;
|
||||
var dbUsername = $scope.dbUsername;
|
||||
var dbPassword = $scope.dbPassword;
|
||||
|
||||
var url = "/dataBases/submitDBCreation";
|
||||
|
||||
|
||||
var data = {
|
||||
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 = 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
});
|
||||
/* Java script code to create database ends here */
|
||||
|
||||
/* Java script code to delete database */
|
||||
|
||||
app.controller('deleteDatabase', 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;
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
});
|
||||
/* Java script code to delete database ends here */
|
||||
|
||||
|
||||
|
||||
/* Java script code to list databases */
|
||||
|
||||
|
||||
app.controller('listDBs', 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;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
|
||||
/* Java script code to list database ends here */
|
||||
111
databases/templates/databases/createDatabase.html
Normal file
111
databases/templates/databases/createDatabase.html
Normal file
@@ -0,0 +1,111 @@
|
||||
{% extends "baseTemplate/index.html" %}
|
||||
{% load i18n %}
|
||||
{% block title %}{% trans "Create New Database - 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="createDatabase" class="panel">
|
||||
<div class="panel-body">
|
||||
<h3 class="title-hero">
|
||||
{% trans "Create Database" %} <img ng-hide="createDatabaseLoading" 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 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 ng-hide="dbDetails" class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans "Database Name" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<input name="dom" type="text" class="form-control" ng-model="dbName" required>
|
||||
</div>
|
||||
<div class="current-pack">{$databaseWebsite|getwebsitename$}_{$ dbName $}</div>
|
||||
</div>
|
||||
|
||||
<div ng-hide="dbDetails" class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans "User Name" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<input type="text" name="email" class="form-control" ng-model="dbUsername" required>
|
||||
</div>
|
||||
<div class="current-pack">{$databaseWebsite|getwebsitename$}_{$ dbUsername $}</div>
|
||||
</div>
|
||||
|
||||
<div ng-hide="dbDetails" class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans "Password" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<input type="password" name="email" class="form-control" ng-model="dbPassword" required>
|
||||
</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>
|
||||
|
||||
</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 %}
|
||||
96
databases/templates/databases/deleteDatabase.html
Normal file
96
databases/templates/databases/deleteDatabase.html
Normal file
@@ -0,0 +1,96 @@
|
||||
{% extends "baseTemplate/index.html" %}
|
||||
{% load i18n %}
|
||||
{% block title %}{% trans "Delete Database - 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 "Delete Database" %}</h2>
|
||||
<p>{% trans "Delete an existing database on this page." %}</p>
|
||||
</div>
|
||||
|
||||
<div ng-controller="deleteDatabase" class="panel">
|
||||
<div class="panel-body">
|
||||
<h3 class="title-hero">
|
||||
{% 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">
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans "Select Website" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<select ng-change="fetchDatabases()" ng-model="databaseWebsite" class="form-control">
|
||||
{% for items in websitesList %}
|
||||
<option>{{ items }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div ng-hide="fetchedDatabases" class="form-group">
|
||||
<label class="col-sm-3 control-label">{% trans "Select Database" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<select ng-model="selectedDB" class="form-control">
|
||||
<option ng-repeat="db in dbnames track by $index">{$ db.dbName $}</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<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>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label"></label>
|
||||
<div class="col-sm-4">
|
||||
<div ng-hide="databaseDeletionFailed" class="alert alert-danger">
|
||||
<p>{% trans "Error message:" %} {$ errorMessage $}</p>
|
||||
</div>
|
||||
|
||||
<div ng-hide="databaseDeleted" class="alert alert-success">
|
||||
<p>{% trans "Database deleted 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 %}
|
||||
86
databases/templates/databases/index.html
Normal file
86
databases/templates/databases/index.html
Normal file
@@ -0,0 +1,86 @@
|
||||
{% extends "baseTemplate/index.html" %}
|
||||
{% load i18n %}
|
||||
{% block title %}{% trans "Database Functions - 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 "Database Functions" %}</h2>
|
||||
<p>{% trans "Create, edit and delete databases on this page." %}</p>
|
||||
</div>
|
||||
|
||||
<div class="panel">
|
||||
<div class="panel-body">
|
||||
<h3 class="title-hero">
|
||||
{% trans "Available Functions" %}
|
||||
</h3>
|
||||
|
||||
<div class="example-box-wrapper">
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<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>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="col-md-6">
|
||||
<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>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<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>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="col-md-6">
|
||||
<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>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
121
databases/templates/databases/listDataBases.html
Normal file
121
databases/templates/databases/listDataBases.html
Normal file
@@ -0,0 +1,121 @@
|
||||
{% extends "baseTemplate/index.html" %}
|
||||
{% load i18n %}
|
||||
{% 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">
|
||||
</div>
|
||||
|
||||
<div ng-hide="canNotChangePassword" class="alert alert-danger">
|
||||
<p>{% trans "Cannot change password for " %}<strong>{$ dbUsername $}</strong>, 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>
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
6
databases/tests.py
Normal file
6
databases/tests.py
Normal file
@@ -0,0 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
17
databases/urls.py
Normal file
17
databases/urls.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from django.conf.urls import url
|
||||
import views
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', views.loadDatabaseHome, name='loadDatabaseHome'),
|
||||
url(r'^createDatabase', views.createDatabase, name='createDatabase'),
|
||||
url(r'^submitDBCreation', views.submitDBCreation, name='submitDBCreation'),
|
||||
url(r'^deleteDatabase', views.deleteDatabase, name='deleteDatabase'),
|
||||
url(r'^fetchDatabases', views.fetchDatabases, name='fetchDatabases'),
|
||||
|
||||
|
||||
url(r'^submitDatabaseDeletion', views.submitDatabaseDeletion, name='submitDatabaseDeletion'),
|
||||
|
||||
url(r'^listDBs', views.listDBs, name='listDBs'),
|
||||
|
||||
url(r'^changePassword', views.changePassword, name='changePassword'),
|
||||
]
|
||||
348
databases/views.py
Normal file
348
databases/views.py
Normal file
@@ -0,0 +1,348 @@
|
||||
# -*- 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 loginSystem.views import loadLoginPage
|
||||
from models import Databases
|
||||
import json
|
||||
import shlex
|
||||
import subprocess
|
||||
# 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))
|
||||
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def createDatabase(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
try:
|
||||
admin = Administrator.objects.get(pk=request.session['userID'])
|
||||
|
||||
if admin.type == 1:
|
||||
websites = Websites.objects.all()
|
||||
websitesName = []
|
||||
|
||||
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 = []
|
||||
|
||||
for items in websites:
|
||||
websitesName.append(items.domain)
|
||||
|
||||
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']
|
||||
try:
|
||||
if request.method == 'POST':
|
||||
|
||||
|
||||
data = json.loads(request.body)
|
||||
databaseWebsite = data['databaseWebsite']
|
||||
dbName = data['dbName']
|
||||
dbUsername = data['dbUsername']
|
||||
dbPassword = data['dbPassword']
|
||||
|
||||
webUsername = databaseWebsite.replace("-","")
|
||||
|
||||
|
||||
webUsername = webUsername.split('.')[0]
|
||||
|
||||
dbName = webUsername+"_"+dbName
|
||||
dbUsername = webUsername+"_"+dbUsername
|
||||
|
||||
if len(dbName) > 16 or len(dbUsername) > 16:
|
||||
data_ret = {'createDBStatus': 0,
|
||||
'error_message': "Length of Database name or Database user should be 16 at max."}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
website = Websites.objects.get(domain=databaseWebsite)
|
||||
|
||||
if website.package.dataBases == 0:
|
||||
pass
|
||||
elif website.package.dataBases > website.databases_set.all().count():
|
||||
pass
|
||||
else:
|
||||
data_ret = {'createDBStatus': 0, 'error_message': "Maximum database limit reached for this website."}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
if Databases.objects.filter(dbName=dbName).exists() or Databases.objects.filter(dbUser=dbUsername).exists() :
|
||||
data_ret = {'createDBStatus': 0,
|
||||
'error_message': "This database or user is already taken."}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
result = mysqlUtilities.createDatabase(dbName, dbUsername, dbPassword)
|
||||
|
||||
if result == 1:
|
||||
pass
|
||||
else:
|
||||
data_ret = {'createDBStatus': 0,
|
||||
'error_message': result}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
db = Databases(website=website,dbName=dbName,dbUser=dbUsername)
|
||||
db.save()
|
||||
|
||||
data_ret = {'createDBStatus': 1, 'error_message': "None"}
|
||||
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)
|
||||
|
||||
|
||||
def deleteDatabase(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
try:
|
||||
|
||||
admin = Administrator.objects.get(pk=request.session['userID'])
|
||||
|
||||
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))
|
||||
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def fetchDatabases(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
try:
|
||||
|
||||
data = json.loads(request.body)
|
||||
|
||||
databaseWebsite = data['databaseWebsite']
|
||||
|
||||
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']
|
||||
try:
|
||||
if request.method == 'POST':
|
||||
|
||||
|
||||
data = json.loads(request.body)
|
||||
dbName = data['dbName']
|
||||
|
||||
|
||||
databaseToBeDeleted = Databases.objects.get(dbName=dbName)
|
||||
result = mysqlUtilities.deleteDatabase(dbName,databaseToBeDeleted.dbUser)
|
||||
|
||||
if result == 1:
|
||||
data_ret = {'deleteStatus': 1, 'error_message': "None"}
|
||||
databaseToBeDeleted.delete()
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
else:
|
||||
data_ret = {'deleteStatus': 0, 'error_message': result}
|
||||
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=request.session['userID'])
|
||||
|
||||
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))
|
||||
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
|
||||
def changePassword(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
try:
|
||||
if request.method == 'POST':
|
||||
|
||||
|
||||
|
||||
data = json.loads(request.body)
|
||||
userName = data['dbUserName']
|
||||
dbPassword = data['dbPassword']
|
||||
|
||||
passFile = "/etc/cyberpanel/mysqlPassword"
|
||||
|
||||
f = open(passFile)
|
||||
data = f.read()
|
||||
password = data.split('\n', 1)[0]
|
||||
|
||||
|
||||
passwordCMD = "use mysql;SET PASSWORD FOR '" + userName + "'@'localhost' = PASSWORD('" + dbPassword + "');FLUSH PRIVILEGES;"
|
||||
|
||||
command = 'mysql -u root -p' + password + ' -e "' + passwordCMD + '"'
|
||||
cmd = shlex.split(command)
|
||||
res = subprocess.call(cmd)
|
||||
|
||||
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)
|
||||
|
||||
|
||||
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)}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
except KeyError,msg:
|
||||
data_ret = {'changePasswordStatus': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
Reference in New Issue
Block a user