JFolder::create: Could not create directory in all pages - joomla

i installed joomla2.5 and see this error in all administrator pages even login page!
JFolder::create: Could not create directory
i did every solution i found like changing the tmp and logs path to '/logs' or './logs/' but not worked.
folders permission is 755.
any one can help me ?

The 755 permission gives the group/others the read and execute permissions in the directory.
This means, that non-group members cannot create new directories.
Make sure that the owner of the directory is the user that the server is running as.
To figure out which user that is, you can use:
$ echo $(ps axho user,comm|grep -E "httpd|apache"|uniq|grep -v "root"|awk 'END {if ($1) print $1}')
And if does not provide the desired result, simply explore the output of:
$ ps aux | grep -E "httpd|apache" | grep -v -E "root|grep"
You can find which group it belongs to by using:
$ groups [userName]
Next, change the owner of the joomla folder. I am using www-data as an example:
# chown -R www-data:www-data path/to/your/joomla/root/dir
PS,
lines preceded by $ can be executed by a normal user, lines preceded by # require root privilege - you can use sudo or your favorite method.

Change the below variable to in your configuration file(configuration.php) as shown.
public $log_path = '/logs';
public $tmp_path = '/tmp';
Also make sure that these folder has the folder permission 755.
Read more
JFolder::create: Could not create directory - Joomla

Related

Commands without sudo in bash do not work

I am running a bash script and these commands in the script will not work without sudo in front of them. The script.sh is located in a folder such as /jobs/script.sh
Example of commands I am trying to run in the script.sh -
mv /var/app/myapp /var/app/myapp.old
rm file.tar.gz
tar -xzf /home/ubuntu/file.tar.gz -C /var/app/
All the above work if I add sudo in front of them.
I am trying to figure out what permissions are required for them to work without adding sudo in the script.
I have tried giving the script.sh rwx permissions and changing owner to root.
I'm learning permissions in linux, so I'm new to this. Basically what permission should the script.sh have so that I dont have to use sudo in the bash file? Any insight would greatly help.
When you run sudo <some command>, then <some command> is run by the root user (Super user do). The reason you might need to run any command using sudo is because the permissions on the files that command reads/writes/executes are such that only the "Super user" (root) has that permission.
When executing the command mv fileA fileB, the executing user would need:
Write permission to fileB if fileB already existed
Write permission to the directory containing fileB
From what you said it’s most likely you want read and write permissions you can achieve this with chmod
Chmod +[permission] filename
(+ is used to add permission you can also use - instead to remove it)
Where permissions can be:
r —> read
w—> write
x —>excecute
... and more
FOR EXAMPLE: it seems you write permissions for the first file so :
chmod +w /var/app/myapp
Will fix problem

Change permissions for console user (MacOS)

I am trying to write a tiny script to change permissions for a specific folder for the logged in users on macbooks. None of these users have admin rights so I have to do run it remotely as root through our MDM.
I am not sure I am getting the syntax right. Can someone help me with this?
#!/bin/sh
# Get current logged in user
TargetUser=$(echo "show State:/Users/ConsoleUser" | \
scutil | awk '/Name :/ && ! /loginwindow/ { print $3 }')
# Update permissions for target user
chown -R "${TargetUser}" /usr/local/bin
chmod g+w /usr/local/bin

Bash Script Cant Write To Log Files

I've created a simple bash script that grabs some data and then outputs it to a log file. When I run the script without sudo it fails to write to the logs and says they are write-protected. It then ask me if it should unwrite-protect them, but this fails (permission denied).
If I run the script as sudo it appears to work without issue. How can I set these log file to be available to the script?
cd /home/pi/scripts/powermonitor/
python /home/pi/powermonitor/plugpower.py > plug.log
echo -e "$(sed '1d' /home/pi/scripts/powermonitor/plug.log)\n" > plug.log
sed 's/^.\{139\}//' plug.log > plug1.log
rm plug.log
grep -o -E '[0-9]+' plug1.log > plug.log
rm plug1.log
sed -n '1p' plug.log > plug1.log
rm plug.log
perl -pe '
I was being dumb. I just needed to set the write permissions on the log files.
The ability to write a file depends on the file permissions that have been assigned to that file or, if the file does not exist but you want to create a new file, then the permissions on the directory in which you want to write the file. If you use sudo, then you are temporarily becoming the root user, and the root user can read/write/execute any file at all without restriction.
If you run your script first using sudo and the script ends up creating a file, that file is probably going to be owned by the root user and will not be writable by your typical user. If you run your script without using sudo, then it's going to run under the username you used to connect to the machine and that user will need to have permission to write the log files.
You can change the ownership and permissions of directories and files by using the chown, chmod, chgrp commands. If you want to always run your script as sudo, then you don't have much to worry about. If you want to run these commands without sudo, that means you're running them as some other user and you will need to grant write permission to that user, whoever it is, in order to write the files/folders where the log files get written.
For instance, if I wanted to run the script as user sneakyimp and wanted the files written to /home/sneakyimp/logs/ then I'd need to make sure that directory was writable by sneakyimp:
sudo chown -R sneakyimp:sneakyimp /home/sneakyimp/logs
This command changes ownership of that directory and its contents to the user sneakyimp. You might also need to run some chmod commands to make sure they are writable by owner.

Rights of complex command (pipe)

I have a minor complex command using a pipe
python3 wlan.py -p taken | awk '{$10 = sprintf( "%.1f", $10 / 60); print $4 $6 $8 $10 ",min"}' | awk '{gsub(/,/," ");print}' >> /tmp/missed.log
and I get a permission error if this command is executed from a program but not from the command line (sudo). So, obviously there is an issue with the rights of the program. I have set the rights of python and awk to 777 to no avail. But the main question is: What are the rights of the >> command and how can I change them?
the error message is "writing missed.log - permission denied".
File access in a Unix-like environment is tied to who you are, not what programs you run.* When you run sudo python3 ..., you are changing who you are to a more privileged user for the duration of the python3 command. Once Python stops running, you are back to your normal self. Imagine that sudo is Clark Kent taking off his glasses and putting on his cape. Once the badguys have been defeated, Superman goes back to an ordinary Joe.
Your error message indicates your normal user account does not have the necessary permissions to access / and /tmp, and to write /tmp/missed.log. The permissions on wlan.py and /usr/bin/python3 aren't the issue here. I can think of four options (best to worst):
Put the output file somewhere other than in /tmp. You should always be able to write your home directory, so you should be able to run without sudo, with > ~/missed.log instead of > /tmp/missed.log.
When you run your pipeline "from a program," as you said, just include the sudo as if you were running it from the command line. That way you get consistent results.
Add yourself to the group owning /tmp. Do stat -c '%G' /tmp. That will tell you which group owns /tmp. Then, if that group is not root, do usermod -a -G <that group name> <your username>.
Change the permissions on /tmp. This is the bludgeon: possible, but not recommended. sudo rm -f /tmp/missed.log and sudo chmod o+rwx /tmp should make it work, but may open other vulnerabilities you don't want.
* Ignoring setuid, which doesn't seem to be the case here.

Get users home directory when they run a script as root

I have a sh script that needs to be run as root, however it is run by the end user using sudo. How can I get the users home directory when ~/ points to /root when running with sudo?
Try to avoid eval. Especially with root perms.
You can do:
USER_HOME=$(getent passwd $SUDO_USER | cut -d: -f6)
Update:
here is why to avoid eval.
The user's home directory would be ~$SUDO_USER. You can use eval as follows:
USER_HOME=$(eval echo ~${SUDO_USER})
echo ${USER_HOME}
$ sudo env |grep USER
USER=root
USERNAME=root
SUDO_USER=glglgl
So you can access $SUDO_USER and ask the system for his homedir with getent passwd $SUDO_USER | cut -d: -f6.
Try accessing the environment variable $SUDO_USER
Unless I misunderstood the question, when the user runs the script with sudo, the $HOME environment variable does not change. To test out, I created this script:
#!/bin/bash
#sudo_user.sh
env | grep -e USER -e HOME
... and run it:
sudo ./sudo_user.sh
Output:
USER=root
HOME=/home/haiv
USERNAME=root
SUDO_USER=haiv
The output tells me that $HOME is still pointing to the user's home (in this case, /home/haiv).
It comes to a little improvement for the eval solution.
Before sending the username variable to eval, test it with the user existence, so if there's arbitrary code, it won't pass the check.
#? Description:
#? Get the user's home directory by username regardless of whether is running with `sudo`.
#? The username is checked, it must exist, to avoid the arbitrary code execution of `eval`.
#? The returned home directory's existence is not checked.
#?
#? Usage:
#? #home USERNAME
function home () {
if id "$1" >/dev/null 2>&1; then
eval echo "~$1"
else
return 255
fi
}
Run the code on macOS:
$ home root
Output:
/var/root
If you run it with something like:
home 'root ; ls'
It gives nothing and returns an error, the ls won't be executed.
You can use Hai's incomplete answer to very simply construct the user's home directory. He and others correctly state that you can get the original user while in the sudo shell. You can use that to construct the home directory into a new variable called user_home (or whatever you like):
#user_home="/home/${$SUDO_USER}";

Resources