Skip to content

Commit 280655d

Browse files
committed
bug fix: rewrite rules: encoding
1 parent 0047beb commit 280655d

File tree

2 files changed

+46
-37
lines changed

2 files changed

+46
-37
lines changed

filemanager/filemanager.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,8 @@ def writeFileContents(self):
292292
domainName = self.data['domainName']
293293
website = Websites.objects.get(domain=domainName)
294294

295-
writeToFile = open(tempPath, 'w')
296-
writeToFile.write(self.data['fileContent'])
295+
writeToFile = open(tempPath, 'wb')
296+
writeToFile.write(self.data['fileContent'].encode('utf-8'))
297297
writeToFile.close()
298298

299299
if os.path.islink(self.data['fileName']):

websiteFunctions/website.py

+44-35
Original file line numberDiff line numberDiff line change
@@ -1129,11 +1129,15 @@ def getRewriteRules(self, userID=None, data=None):
11291129
try:
11301130
childDom = ChildDomains.objects.get(domain=self.domain)
11311131
filePath = childDom.path + '/.htaccess'
1132+
externalApp = childDom.master.externalApp
11321133
except:
1134+
website = Websites.objects.get(domain=self.domain)
1135+
externalApp = website.externalApp
11331136
filePath = "/home/" + self.domain + "/public_html/.htaccess"
11341137

11351138
try:
1136-
rewriteRules = open(filePath, "r").read()
1139+
command = 'cat %s' % (filePath)
1140+
rewriteRules = ProcessUtilities.outputExecutioner(command, externalApp)
11371141

11381142
if len(rewriteRules) == 0:
11391143
status = {"rewriteStatus": 1, "error_message": "Rules file is currently empty"}
@@ -1145,54 +1149,59 @@ def getRewriteRules(self, userID=None, data=None):
11451149
final_json = json.dumps(status)
11461150
return HttpResponse(final_json)
11471151

1148-
except IOError:
1149-
status = {"rewriteStatus": 1, "error_message": "none", "rewriteRules": ""}
1152+
except BaseException as msg:
1153+
status = {"rewriteStatus": 1, "error_message": str(msg), "rewriteRules": ""}
11501154
final_json = json.dumps(status)
11511155
return HttpResponse(final_json)
11521156

11531157
def saveRewriteRules(self, userID=None, data=None):
1158+
try:
11541159

1155-
currentACL = ACLManager.loadedACL(userID)
1156-
admin = Administrator.objects.get(pk=userID)
1157-
self.domain = data['virtualHost']
1158-
rewriteRules = data['rewriteRules']
1160+
currentACL = ACLManager.loadedACL(userID)
1161+
admin = Administrator.objects.get(pk=userID)
1162+
self.domain = data['virtualHost']
1163+
rewriteRules = data['rewriteRules'].encode('utf-8')
11591164

1160-
if ACLManager.checkOwnership(self.domain, admin, currentACL) == 1:
1161-
pass
1162-
else:
1163-
return ACLManager.loadErrorJson('rewriteStatus', 0)
1165+
if ACLManager.checkOwnership(self.domain, admin, currentACL) == 1:
1166+
pass
1167+
else:
1168+
return ACLManager.loadErrorJson('rewriteStatus', 0)
11641169

1165-
## writing data temporary to file
1170+
## writing data temporary to file
11661171

1167-
mailUtilities.checkHome()
1168-
tempPath = "/tmp/" + str(randint(1000, 9999))
1169-
vhost = open(tempPath, "w")
1170-
vhost.write(rewriteRules)
1171-
vhost.close()
1172+
mailUtilities.checkHome()
1173+
tempPath = "/tmp/" + str(randint(1000, 9999))
1174+
vhost = open(tempPath, "wb")
1175+
vhost.write(rewriteRules)
1176+
vhost.close()
11721177

1173-
## writing data temporary to file
1178+
## writing data temporary to file
11741179

1175-
try:
1176-
childDomain = ChildDomains.objects.get(domain=self.domain)
1177-
filePath = childDomain.path + '/.htaccess'
1178-
externalApp = childDomain.master.externalApp
1179-
except:
1180-
filePath = "/home/" + self.domain + "/public_html/.htaccess"
1181-
website = Websites.objects.get(domain=self.domain)
1182-
externalApp = website.externalApp
1180+
try:
1181+
childDomain = ChildDomains.objects.get(domain=self.domain)
1182+
filePath = childDomain.path + '/.htaccess'
1183+
externalApp = childDomain.master.externalApp
1184+
except:
1185+
filePath = "/home/" + self.domain + "/public_html/.htaccess"
1186+
website = Websites.objects.get(domain=self.domain)
1187+
externalApp = website.externalApp
11831188

1184-
## save configuration data
1189+
## save configuration data
11851190

1186-
command = 'cp %s %s' % (tempPath, filePath)
1187-
ProcessUtilities.executioner(command, externalApp)
1191+
command = 'cp %s %s' % (tempPath, filePath)
1192+
ProcessUtilities.executioner(command, externalApp)
11881193

1189-
command = 'rm -f %s' % (tempPath)
1190-
ProcessUtilities.executioner(command, 'cyberpanel')
1194+
command = 'rm -f %s' % (tempPath)
1195+
ProcessUtilities.executioner(command, 'cyberpanel')
11911196

1192-
installUtilities.reStartLiteSpeedSocket()
1193-
status = {"rewriteStatus": 1, 'error_message': 'None'}
1194-
final_json = json.dumps(status)
1195-
return HttpResponse(final_json)
1197+
installUtilities.reStartLiteSpeedSocket()
1198+
status = {"rewriteStatus": 1, 'error_message': 'None'}
1199+
final_json = json.dumps(status)
1200+
return HttpResponse(final_json)
1201+
except BaseException as msg:
1202+
status = {"rewriteStatus": 0, 'error_message': str(msg)}
1203+
final_json = json.dumps(status)
1204+
return HttpResponse(final_json)
11961205

11971206
def saveSSL(self, userID=None, data=None):
11981207

0 commit comments

Comments
 (0)