mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-08 06:16:08 +01:00
finish allow remote access for db user
This commit is contained in:
@@ -12,13 +12,15 @@ from plogical.acl import ACLManager
|
|||||||
import plogical.CyberCPLogFileWriter as logging
|
import plogical.CyberCPLogFileWriter as logging
|
||||||
from plogical.mysqlUtilities import mysqlUtilities
|
from plogical.mysqlUtilities import mysqlUtilities
|
||||||
from websiteFunctions.models import Websites
|
from websiteFunctions.models import Websites
|
||||||
from databases.models import Databases
|
from databases.models import Databases, DBMeta
|
||||||
import argparse
|
import argparse
|
||||||
from loginSystem.models import Administrator
|
from loginSystem.models import Administrator
|
||||||
import plogical.randomPassword as randomPassword
|
import plogical.randomPassword as randomPassword
|
||||||
|
|
||||||
class DatabaseManager:
|
class DatabaseManager:
|
||||||
|
|
||||||
|
REMOTE_ACCESS = 'remote_access'
|
||||||
|
|
||||||
def loadDatabaseHome(self, request = None, userID = None):
|
def loadDatabaseHome(self, request = None, userID = None):
|
||||||
try:
|
try:
|
||||||
return render(request, 'databases/index.html')
|
return render(request, 'databases/index.html')
|
||||||
@@ -223,7 +225,6 @@ class DatabaseManager:
|
|||||||
return ACLManager.loadErrorJson('changePasswordStatus', 0)
|
return ACLManager.loadErrorJson('changePasswordStatus', 0)
|
||||||
|
|
||||||
userName = data['dbUserName']
|
userName = data['dbUserName']
|
||||||
dbPassword = data['dbPassword']
|
|
||||||
|
|
||||||
db = Databases.objects.filter(dbUser=userName)
|
db = Databases.objects.filter(dbUser=userName)
|
||||||
|
|
||||||
@@ -233,20 +234,57 @@ class DatabaseManager:
|
|||||||
else:
|
else:
|
||||||
return ACLManager.loadErrorJson()
|
return ACLManager.loadErrorJson()
|
||||||
|
|
||||||
|
try:
|
||||||
res = mysqlUtilities.changePassword(userName, dbPassword)
|
meta = DBMeta.objects.get(database=db[0], key=DatabaseManager.REMOTE_ACCESS)
|
||||||
|
data_ret = {'status': 1, 'dbHost': json.loads(meta.value)['remoteIP']}
|
||||||
if res == 0:
|
|
||||||
data_ret = {'status': 0, 'changePasswordStatus': 0,'error_message': "Please see CyberPanel main log file."}
|
|
||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
data_ret = {'status': 1, 'changePasswordStatus': 1, 'error_message': "None"}
|
except BaseException as msg:
|
||||||
|
data_ret = {'status': 1, 'dbHost': 'localhost'}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
except BaseException as 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):
|
||||||
|
try:
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
|
||||||
|
if ACLManager.currentContextPermission(currentACL, 'listDatabases') == 0:
|
||||||
|
return ACLManager.loadErrorJson('changePasswordStatus', 0)
|
||||||
|
|
||||||
|
userName = data['dbUserName']
|
||||||
|
remoteIP = data['remoteIP']
|
||||||
|
|
||||||
|
db = Databases.objects.filter(dbUser=userName)
|
||||||
|
|
||||||
|
admin = Administrator.objects.get(pk=userID)
|
||||||
|
if ACLManager.checkOwnership(db[0].website.domain, admin, currentACL) == 1:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
return ACLManager.loadErrorJson()
|
||||||
|
|
||||||
|
mysqlUtilities.allowRemoteAccess(db[0].dbName, userName, remoteIP)
|
||||||
|
|
||||||
|
metaData = {'remoteIP': remoteIP}
|
||||||
|
|
||||||
|
try:
|
||||||
|
meta = DBMeta.objects.get(database=db[0], key=DatabaseManager.REMOTE_ACCESS)
|
||||||
|
meta.value = json.dumps(metaData)
|
||||||
|
meta.save()
|
||||||
|
except:
|
||||||
|
DBMeta(database=db[0], value = json.dumps(metaData), key=DatabaseManager.REMOTE_ACCESS).save()
|
||||||
|
|
||||||
|
data_ret = {'status': 1}
|
||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
except BaseException as msg:
|
except BaseException as msg:
|
||||||
data_ret = {'status': 0, 'changePasswordStatus': 0, 'error_message': str(msg)}
|
data_ret = {'status': 0,'error_message': str(msg)}
|
||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
|||||||
@@ -457,18 +457,13 @@ app.controller('listDBs', function ($scope, $http) {
|
|||||||
$scope.remoteAccess = function (userName) {
|
$scope.remoteAccess = function (userName) {
|
||||||
|
|
||||||
$scope.dbUsername = userName;
|
$scope.dbUsername = userName;
|
||||||
alert($scope.dbUsername);
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
$scope.dbLoading = false;
|
$scope.dbLoading = false;
|
||||||
$scope.passwordChanged = true;
|
|
||||||
|
|
||||||
|
|
||||||
url = "/dataBases/changePassword";
|
url = "/dataBases/remoteAccess";
|
||||||
|
|
||||||
var data = {
|
var data = {
|
||||||
dbUserName: globalDBUsername,
|
dbUserName: $scope.dbUsername
|
||||||
dbPassword: $scope.dbPassword,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var config = {
|
var config = {
|
||||||
@@ -477,33 +472,89 @@ app.controller('listDBs', function ($scope, $http) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
|
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
|
||||||
|
|
||||||
|
|
||||||
function ListInitialDatas(response) {
|
function ListInitialDatas(response) {
|
||||||
|
$scope.dbLoading = true;
|
||||||
|
|
||||||
|
if (response.data.status === 1) {
|
||||||
|
|
||||||
if (response.data.changePasswordStatus == 1) {
|
$scope.dbHost = response.data.dbHost;
|
||||||
$scope.notificationsBox = false;
|
|
||||||
$scope.passwordChanged = false;
|
|
||||||
$scope.dbLoading = true;
|
|
||||||
$scope.domainFeteched = $scope.selectedDomain;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$scope.notificationsBox = false;
|
new PNotify({
|
||||||
$scope.canNotChangePassword = false;
|
title: 'Operation Failed!',
|
||||||
$scope.dbLoading = true;
|
text: response.data.error_message,
|
||||||
$scope.canNotChangePassword = false;
|
type: 'error'
|
||||||
$scope.errorMessage = response.data.error_message;
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function cantLoadInitialDatas(response) {
|
function cantLoadInitialDatas(response) {
|
||||||
$scope.notificationsBox = false;
|
new PNotify({
|
||||||
$scope.couldNotConnect = false;
|
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;
|
$scope.dbLoading = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,10 +137,33 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
|
|
||||||
<div class="form-group">
|
<form name="containerSettingsForm" action="/"
|
||||||
<label class="col-sm-12 control-label"
|
class="form-horizontal">
|
||||||
style="text-align: center;">{% trans "Contents of .gitignore, use the box below to Add/Edit content of .gitingore file." %}</label>
|
<div ng-hide="installationDetailsForm"
|
||||||
</div>
|
class="form-group">
|
||||||
|
<label class="col-sm-5 control-label">{% trans "Allow Remote Access on following IP" %}</label>
|
||||||
|
<div class="col-sm-6">
|
||||||
|
<input placeholder="IP Address"
|
||||||
|
name="remoteIP" type="text"
|
||||||
|
class="form-control"
|
||||||
|
ng-model="$parent.remoteIP"
|
||||||
|
required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
|
||||||
|
<label class="col-sm-5 control-label"></label>
|
||||||
|
<div class="col-sm-4">
|
||||||
|
<button type="button" ng-click="allowRemoteIP()"
|
||||||
|
class="btn btn-primary btn-lg">{% trans "Save Changes" %}</button>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
@@ -154,7 +177,7 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td>{$ dbUsername $}</td>
|
<td>{$ dbUsername $}</td>
|
||||||
<td></td>
|
<td>{$ dbHost $}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -13,7 +13,9 @@ urlpatterns = [
|
|||||||
|
|
||||||
url(r'^listDBs', views.listDBs, name='listDBs'),
|
url(r'^listDBs', views.listDBs, name='listDBs'),
|
||||||
|
|
||||||
url(r'^changePassword', views.changePassword, name='changePassword'),
|
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'^phpMyAdmin$', views.phpMyAdmin, name='phpMyAdmin'),
|
||||||
url(r'^setupPHPMYAdminSession$', views.setupPHPMYAdminSession, name='setupPHPMYAdminSession'),
|
url(r'^setupPHPMYAdminSession$', views.setupPHPMYAdminSession, name='setupPHPMYAdminSession'),
|
||||||
]
|
]
|
||||||
@@ -131,6 +131,17 @@ def remoteAccess(request):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
return redirect(loadLoginPage)
|
return redirect(loadLoginPage)
|
||||||
|
|
||||||
|
def allowRemoteIP(request):
|
||||||
|
try:
|
||||||
|
userID = request.session['userID']
|
||||||
|
|
||||||
|
dm = DatabaseManager()
|
||||||
|
coreResult = dm.allowRemoteIP(userID, json.loads(request.body))
|
||||||
|
|
||||||
|
return coreResult
|
||||||
|
except KeyError:
|
||||||
|
return redirect(loadLoginPage)
|
||||||
|
|
||||||
def phpMyAdmin(request):
|
def phpMyAdmin(request):
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
userID = request.session['userID']
|
||||||
|
|||||||
@@ -793,6 +793,27 @@ password=%s
|
|||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[mysqlUtilities.changePassword]")
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[mysqlUtilities.changePassword]")
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def allowRemoteAccess(dbName, userName, remoteIP):
|
||||||
|
try:
|
||||||
|
|
||||||
|
connection, cursor = mysqlUtilities.setupConnection()
|
||||||
|
|
||||||
|
if connection == 0:
|
||||||
|
return 0
|
||||||
|
cursor.execute("use mysql")
|
||||||
|
|
||||||
|
cursor.execute("update db set Host='%s' where Db='%s'" % (remoteIP, dbName))
|
||||||
|
cursor.execute("update user set Host='%s' where user='%s'" % (remoteIP, userName))
|
||||||
|
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
return 1
|
||||||
|
|
||||||
|
except BaseException as msg:
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[mysqlUtilities.changePassword]")
|
||||||
|
return 0
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def fetchuser(databaseName):
|
def fetchuser(databaseName):
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -454,6 +454,113 @@ app.controller('listDBs', function ($scope, $http) {
|
|||||||
$scope.generatedPasswordView = true;
|
$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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user