usmannasir 2025-07-04 14:28:31 +05:00
parent 2e0d70cada
commit 8374d431e8
2 changed files with 16 additions and 6 deletions

View File

@ -716,7 +716,9 @@ class FileManager:
if self.data['fileName'].find(pathCheck) == -1 or self.data['fileName'].find('..') > -1:
return self.ajaxPre(0, 'Not allowed.')
command = 'cat ' + self.returnPathEnclosed(self.data['fileName'])
# Ensure proper UTF-8 handling for file reading
# Use explicit UTF-8 locale for the cat command
command = 'LANG=C.UTF-8 LC_ALL=C.UTF-8 cat ' + self.returnPathEnclosed(self.data['fileName'])
finalData['fileContents'] = ProcessUtilities.outputExecutioner(command, website.externalApp)
except:
pathCheck = '/'
@ -724,12 +726,15 @@ class FileManager:
if self.data['fileName'].find(pathCheck) == -1 or self.data['fileName'].find('..') > -1:
return self.ajaxPre(0, 'Not allowed.')
command = 'cat ' + self.returnPathEnclosed(self.data['fileName'])
# Ensure proper UTF-8 handling for file reading
# Use explicit UTF-8 locale for the cat command
command = 'LANG=C.UTF-8 LC_ALL=C.UTF-8 cat ' + self.returnPathEnclosed(self.data['fileName'])
finalData['fileContents'] = ProcessUtilities.outputExecutioner(command)
json_data = json.dumps(finalData)
return HttpResponse(json_data)
# Ensure proper UTF-8 encoding in JSON response
json_data = json.dumps(finalData, ensure_ascii=False)
return HttpResponse(json_data, content_type='application/json; charset=utf-8')
except BaseException as msg:
return self.ajaxPre(0, str(msg))

View File

@ -324,10 +324,15 @@ class ProcessUtilities(multi.Thread):
if user!=None:
if not command.startswith('sudo'):
command = f'sudo -u {user} {command}'
# Ensure UTF-8 environment for proper character handling
env = os.environ.copy()
env['LC_ALL'] = 'en_US.UTF-8'
env['LANG'] = 'en_US.UTF-8'
if shell == None or shell == True:
p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env)
else:
p = subprocess.Popen(shlex.split(command), stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
p = subprocess.Popen(shlex.split(command), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env)
if retRequired:
return 1, p.communicate()[0].decode("utf-8")