usmannasir / cyberpanel

Cyber Panel - The hosting control panel for OpenLiteSpeed
GNU General Public License v3.0
1.57k stars 606 forks source link

change permissions on dot files not working #468

Open lorvent opened 4 years ago

lorvent commented 4 years ago

Prologue: I have been using cyberpanel for more than a year but since i see that it is adding many under-the-hood features, i decided to use it more extensively than DA. and one feature which i really liked is "manage git" which also can pull changes with webhook....that simply means, i can discard one more service which does that for me (honestly it is not at the point of discarding another service at the moment)

actual problem:

i tried modifying permissions of .env file using file manager but looks like it is not performing that.

side note:

i also had another problem, trying to copy .env.example. as .env also does nothing, tried 3 times, equal to cp .env.example .env

so finally i had to do it from terminal.

meramsey commented 3 years ago

Looks like there could be some issues with filenames with special characters but not seeing anything super obvious to indicate this in. File that would be handling this though is below for when me or someone else has time to reproduce and investigate this further.

https://github.com/usmannasir/cyberpanel/blob/stable/filemanager/filemanager.py

ru-dmitry commented 3 years ago

To the best of my memory, by default find shell command does not include hidden files (hidden means started with a dot).

meramsey commented 3 years ago

Looks like copy should work without issues based on latest code. https://github.com/usmannasir/cyberpanel/blob/d42d01b0f5abf2a075c9a367a125787ef36b3699/filemanager/filemanager.py#L404

In regards to the permissions. it is possible this is not working due to chmod not liking hidden files.

Can you advise what exact permissions the .env file had before and what permissions you tried to set? I would like to test this out on my end.

Also from looking at the code we really should be probably using a python native library like the os module to do this stuff vs shell commands as they would handle stuff way cleaner and faster. I'll look into seeing about how hard it would be to refactor the current filemanager commands to use python native stuff here which should better handle the weird filename errors and edge cases ive seen with it.

https://docs.python.org/3/library/shutil.html#shutil.chown https://www.geeksforgeeks.org/os-module-python-examples/ https://www.geeksforgeeks.org/how-to-get-the-permission-mask-of-a-file-in-python/ https://stackoverflow.com/questions/15607903/python-module-os-chmodfile-664-does-not-change-the-permission-to-rw-rw-r-bu https://www.tutorialspoint.com/How-to-change-the-permission-of-a-directory-using-Python

@usmannasir @aonsyed is there any reason you guys can think of to not use python native os module to chown/chmod and cp/mv files. Not sure if that had been tried before and there was some blockage or not. Figured I'd ask before i take a stab at it.

lorvent commented 3 years ago

default permissions of .env or .env.example are 644.

meramsey commented 3 years ago

Thanks for the update.

I think its possible that your current Cyberpanel installation may not be the latest version 2.0.3 or the files applicable not fully updated. As i was not able to reproduce those specific issues with latest version in Ubuntu 20. I haven't tested in Centos 7 yet but I don't see any reason why that would make a difference in this case.

I was able to copy ".env.example" to ".env" rename and also set permissions without issue.

With that being said though. I did however notice some other odd issues with the filemanager where it caches the last set permissions till hard refreshed and this could be causing things to not look like they worked. Opened new bug about that https://github.com/usmannasir/cyberpanel/issues/506

I recommend if you haven't done so to update to the latest version and see if that helps.

lorvent commented 3 years ago

I am already on 2.0.3

i will wait for 2.0.4 and i will try to reproduce the bug.