Skip to content

Commit 5c5e263

Browse files
committed
Added SFTP port configuration to wordpress backup manager. Fix for strip_trailing_zero
1 parent de7dbb3 commit 5c5e263

File tree

9 files changed

+115
-15
lines changed

9 files changed

+115
-15
lines changed

CyberCP/settings.py

+3
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@
2828
ALLOWED_HOSTS = ['*']
2929

3030
# Application definition
31+
STATICFILES_STORAGE = "django.core.files.storage.FileSystemStorage"
32+
COLLECTFAST_STRATEGY = "collectfast.strategies.filesystem.FileSystemStrategy"
3133

3234
INSTALLED_APPS = [
35+
'collectfast',
3336
'django.contrib.admin',
3437
'django.contrib.auth',
3538
'django.contrib.contenttypes',

cyberpanel.sh

+7
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,13 @@ export LC_CTYPE=en_US.UTF-8
11201120
export LC_ALL=en_US.UTF-8
11211121
#need to set lang to address some pip module installation issue.
11221122

1123+
### @micfogas - code added to force updating of python3 package 'packaging' to version 22 or higher to avoid fatal error
1124+
###
1125+
Debug_Log2 "Force updating pip package 'packaging' to \>\=22...,40"
1126+
pip install packaging>=22 --root-user-action=ignore --break-system-packages -U --force-reinstall -I
1127+
###
1128+
### @micfogas end code addition
1129+
11231130
Retry_Command "pip install --default-timeout=3600 virtualenv"
11241131

11251132
Download_Requirement

cyberpanel_upgrade.sh

+1
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,7 @@ elif [[ "$Server_OS" = "Ubuntu" ]] ; then
715715
# shellcheck disable=SC1091
716716
. /usr/local/CyberPanelTemp/bin/activate
717717
Check_Return
718+
pip3 install packaging>=22 --root-user-action=ignore --break-system-packages -U --force-reinstall -I
718719
pip3 install --default-timeout=3600 --ignore-installed -r /usr/local/requirments-old.txt
719720
Check_Return
720721
elif [[ "$Server_OS" = "openEuler" ]] ; then

plogical/IncScheduler.py

+25-7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import socket
2828
from websiteFunctions.models import NormalBackupJobs, NormalBackupJobLogs
2929
from boto3.s3.transfer import TransferConfig
30+
import traceback
3031

3132
try:
3233
from s3Backups.models import BackupPlan, BackupLogs
@@ -1396,6 +1397,7 @@ def SendTORemote(FileName, RemoteBackupID):
13961397
RemoteBackupOBJ = RemoteBackupConfig.objects.get(pk=RemoteBackupID)
13971398
config = json.loads(RemoteBackupOBJ.config)
13981399
HostName = config['Hostname']
1400+
Port = config.get('Port', 22)
13991401
Username = config['Username']
14001402
Password = config['Password']
14011403
Path = config['Path']
@@ -1405,14 +1407,28 @@ def SendTORemote(FileName, RemoteBackupID):
14051407
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
14061408

14071409
# Connect to the server using the private key
1408-
ssh.connect(HostName, username=Username, password=Password)
1410+
ssh.connect(HostName, port=Port, username=Username, password=Password)
1411+
1412+
# Create directory and wait for the command to complete
1413+
stdin, stdout, stderr = ssh.exec_command(f'mkdir -p {Path}')
1414+
stdout.read() # Wait for command completion
1415+
14091416
sftp = ssh.open_sftp()
1410-
ssh.exec_command(f'mkdir -p {Path}')
14111417

14121418
if os.path.exists(ProcessUtilities.debugPath):
1413-
logging.writeToFile(f"Filename: {FileName}, Path {Path}/{FileName.split('/')[-1]}. [SendTORemote]")
1419+
logging.writeToFile(f"Filename: {FileName}, Path {Path}/{FileName.split('/')[-1]} [SendTORemote]")
14141420

1415-
sftp.put(FileName, f"{Path}/{FileName.split('/')[-1]}")
1421+
try:
1422+
sftp.put(FileName, f"{Path}/{FileName.split('/')[-1]}")
1423+
except FileNotFoundError:
1424+
# Double check if directory exists by explicitly creating it via SFTP
1425+
try:
1426+
sftp.mkdir(Path)
1427+
except IOError:
1428+
# Directory may already exist, which would cause an error
1429+
pass
1430+
# Try the transfer again
1431+
sftp.put(FileName, f"{Path}/{FileName.split('/')[-1]}")
14161432

14171433
# sftp.get(str(remotepath), str(loaclpath),
14181434
# callback=self.UpdateDownloadStatus)
@@ -1432,11 +1448,13 @@ def SendTORemote(FileName, RemoteBackupID):
14321448
# with sftp.cd(Path):
14331449
# sftp.put(FileName)
14341450

1435-
1451+
# Close connections
1452+
sftp.close()
1453+
ssh.close()
14361454

14371455
except BaseException as msg:
1438-
print('%s. [SendTORemote]' % (str(msg)))
1439-
logging.writeToFile('%s. [SendTORemote]' % (str(msg)))
1456+
print('%s. [SendTORemote]' % (traceback.format_exc()))
1457+
logging.writeToFile('%s. [SendTORemote]' % (traceback.format_exc()))
14401458

14411459
@staticmethod
14421460
def SendToS3Cloud(FileName, RemoteBackupCofigID, backupID, scheduleID):

plogical/applicationInstaller.py

+18-7
Original file line numberDiff line numberDiff line change
@@ -2520,17 +2520,27 @@ def WPCreateBackup(self):
25202520
Adminobj = Administrator.objects.get(pk=self.extraArgs['adminID'])
25212521
Backuptype = self.extraArgs['Backuptype']
25222522
try:
2523-
BackupDestination = self.extraArgs['BackupDestination']
2524-
SFTP_ID = self.extraArgs['SFTPID']
2523+
config = self.extraArgs['remoteBackupConfig']
2524+
if config == "-1":
2525+
BackupDestination = 'Local'
2526+
SFTP_ID = None
2527+
else:
2528+
BackupDestination = config.split(":")[1]
2529+
SFTP_ID = int(config.split(":")[0])
25252530
except:
2526-
BackupDestination = 'Local'
2527-
SFTP_ID = None
2531+
try:
2532+
BackupDestination = self.extraArgs['BackupDestination']
2533+
SFTP_ID = self.extraArgs['SFTPID']
2534+
if os.path.exists(ProcessUtilities.debugPath):
2535+
logging.writeToFile(f'BackupDestination: {BackupDestination}, SFTP_ID: {SFTP_ID}')
2536+
except:
2537+
BackupDestination = 'Local'
2538+
SFTP_ID = None
2539+
25282540

25292541
from plogical.phpUtilities import phpUtilities
25302542
vhFile = f'/usr/local/lsws/conf/vhosts/{wpsite.owner.domain}/vhost.conf'
25312543

2532-
2533-
25342544
website = wpsite.owner
25352545
PhpVersion = phpUtilities.WrapGetPHPVersionFromFileToGetVersionWithPHP(vhFile)
25362546
VHuser = website.externalApp
@@ -3066,6 +3076,7 @@ def RestoreWPbackupNow(self):
30663076
RemoteBackupOBJ = RemoteBackupConfig.objects.get(pk=RemoteBackupID)
30673077
RemoteBackupconf = json.loads(RemoteBackupOBJ.config)
30683078
HostName = RemoteBackupconf['Hostname']
3079+
Port = RemoteBackupconf['Port']
30693080
Username = RemoteBackupconf['Username']
30703081
Password = RemoteBackupconf['Password']
30713082
Path = RemoteBackupconf['Path']
@@ -3080,7 +3091,7 @@ def RestoreWPbackupNow(self):
30803091
# SSH connection to the remote server
30813092
ssh = paramiko.SSHClient()
30823093
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
3083-
ssh.connect(HostName, username=Username, password=Password)
3094+
ssh.connect(HostName, port=Port, username=Username, password=Password)
30843095

30853096
if os.path.exists(ProcessUtilities.debugPath):
30863097
logging.writeToFile(f"SFTP Connected successfully..")

websiteFunctions/static/websiteFunctions/websiteFunctions.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1620,7 +1620,8 @@ app.controller('WPsiteHome', function ($scope, $http, $timeout, $compile, $windo
16201620
$scope.currentStatus = "Starting creation Backups..";
16211621
var data = {
16221622
WPid: $('#WPid').html(),
1623-
Backuptype: $('#backuptype').val()
1623+
Backuptype: $('#backuptype').val(),
1624+
remoteBackupConfig: $('#remoteBackupConfig').val()
16241625
}
16251626
var url = "/websites/WPCreateBackup";
16261627

@@ -2118,6 +2119,7 @@ app.controller('RemoteBackupConfig', function ($scope, $http, $timeout, $window)
21182119
$scope.SaveBackupConfig = function () {
21192120
$scope.RemoteBackupLoading = false;
21202121
var Hname = $scope.Hostname;
2122+
var Port = $scope.Port;
21212123
var Uname = $scope.Username;
21222124
var Passwd = $scope.Password;
21232125
var path = $scope.path;
@@ -2128,6 +2130,7 @@ app.controller('RemoteBackupConfig', function ($scope, $http, $timeout, $window)
21282130

21292131
data = {
21302132
Hname: Hname,
2133+
Port: Port,
21312134
Uname: Uname,
21322135
Passwd: Passwd,
21332136
path: path,

websiteFunctions/templates/websiteFunctions/RemoteBackupConfig.html

+10
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ <h3 class="content-box-header">
4343
required>
4444
</div>
4545

46+
</div>
47+
<div ng-hide="SFTPBackUpdiv" class="form-group">
48+
<label class="col-sm-3 control-label">{% trans "Port" %}</label>
49+
<div class="col-sm-6">
50+
<input name="Port" type="text" class="form-control" ng-model="Port"
51+
required>
52+
</div>
53+
4654
</div>
4755
<div ng-hide="SFTPBackUpdiv" class="form-group">
4856
<label class="col-sm-3 control-label">{% trans "Username" %}</label>
@@ -131,6 +139,7 @@ <h3 class="content-box-header">
131139
<tr>
132140
<th style="padding: 18px; color: white; width: 161px; font-size: 12px;">Backup Type</th>
133141
<th style="padding: 18px; color: white; width: 161px; font-size: 12px;">HostName</th>
142+
<th style="padding: 18px; color: white; width: 161px; font-size: 12px;">Port</th>
134143
<th style="padding: 18px; color: white; width: 161px; font-size: 12px;">Path / Key Name</th>
135144
<th style="padding: 18px; color: white; width: 161px; font-size: 12px;">Action</th>
136145
</tr>
@@ -141,6 +150,7 @@ <h3 class="content-box-header">
141150
<tr>
142151
<td style="padding: 13px;">{{ sub.Type }}</td>
143152
<td style="padding: 13px;">{{ sub.HostName }}</td>
153+
<td style="padding: 13px;">{{ sub.Port }}</td>
144154
<td style="padding: 13px;">{{ sub.Path }}</td>
145155
<td style="padding: 13px;">
146156
<button

websiteFunctions/templates/websiteFunctions/WPsiteHome.html

+11
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,17 @@ <h3 class="content-box-header">
583583
</select>
584584
</div>
585585
</div>
586+
<div ng-hide="installationDetailsForm" class="form-group">
587+
<label class="col-sm-3 control-label">{% trans "Remote Backup Destination" %}</label>
588+
<div class="col-sm-6">
589+
<select id="remoteBackupConfig" class="form-control">
590+
<option value="-1" selected>None (Local Backup Only)</option>
591+
{% for config in backupconfigs %}
592+
<option value="{{ config.id }}:{{ config.Type }}">{{ config.Type }} - {{ config.HostName }}:{{ config.Port }} / {{ config.Path }}</option>
593+
{% endfor %}
594+
</select>
595+
</div>
596+
</div>
586597
<div ng-hide="installationDetailsForm" class="form-group">
587598
<label class="col-sm-3 control-label"></label>
588599
<div class="col-sm-4">

websiteFunctions/website.py

+36
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,37 @@ def WPHome(self, request=None, userID=None, WPid=None, DeleteID=None):
196196
Data['wpsite'] = WPobj
197197
Data['test_domain_data'] = 1
198198

199+
allcon = RemoteBackupConfig.objects.all()
200+
Data['backupconfigs'] = []
201+
for i in allcon:
202+
configr = json.loads(i.config)
203+
if i.configtype == "SFTP":
204+
Data['backupconfigs'].append({
205+
'id': i.pk,
206+
'Type': i.configtype,
207+
'HostName': configr['Hostname'],
208+
'Port': configr['Port'],
209+
'Path': configr['Path']
210+
})
211+
elif i.configtype == "S3":
212+
Provider = configr['Provider']
213+
if Provider == "Backblaze":
214+
Data['backupconfigs'].append({
215+
'id': i.pk,
216+
'Type': i.configtype,
217+
'HostName': Provider,
218+
'Port': "",
219+
'Path': configr['S3keyname']
220+
})
221+
else:
222+
Data['backupconfigs'].append({
223+
'id': i.pk,
224+
'Type': i.configtype,
225+
'HostName': Provider,
226+
'Port': "",
227+
'Path': configr['S3keyname']
228+
})
229+
199230
try:
200231
DeleteID = request.GET.get('DeleteID', None)
201232

@@ -275,6 +306,7 @@ def RemoteBackupConfig(self, request=None, userID=None, DeleteID=None):
275306
'id': i.pk,
276307
'Type': i.configtype,
277308
'HostName': configr['Hostname'],
309+
'Port': configr['Port'],
278310
'Path': configr['Path']
279311
})
280312
elif i.configtype == "S3":
@@ -284,13 +316,15 @@ def RemoteBackupConfig(self, request=None, userID=None, DeleteID=None):
284316
'id': i.pk,
285317
'Type': i.configtype,
286318
'HostName': Provider,
319+
'Port': "",
287320
'Path': configr['S3keyname']
288321
})
289322
else:
290323
Data['backupconfigs'].append({
291324
'id': i.pk,
292325
'Type': i.configtype,
293326
'HostName': Provider,
327+
'Port': "",
294328
'Path': configr['S3keyname']
295329
})
296330

@@ -1276,11 +1310,13 @@ def SaveBackupConfig(self, userID=None, data=None):
12761310
ConfigType = data['type']
12771311
if ConfigType == 'SFTP':
12781312
Hname = data['Hname']
1313+
Port = data['Port']
12791314
Uname = data['Uname']
12801315
Passwd = data['Passwd']
12811316
path = data['path']
12821317
config = {
12831318
"Hostname": Hname,
1319+
"Port": Port,
12841320
"Username": Uname,
12851321
"Password": Passwd,
12861322
"Path": path

0 commit comments

Comments
 (0)