2011-03-06 20:43:51 +00:00
|
|
|
#!/bin/bash -e
|
2006-05-16 18:20:14 +00:00
|
|
|
#
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
# AlternC - Web Hosting System
|
2012-08-24 08:51:00 +00:00
|
|
|
# Copyright (C) 2000-2012 by the AlternC Development Team.
|
|
|
|
# https://alternc.org/
|
2006-05-16 18:20:14 +00:00
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
# LICENSE
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License (GPL)
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# To read the license please visit http://www.gnu.org/copyleft/gpl.html
|
|
|
|
# ----------------------------------------------------------------------
|
2012-08-24 08:51:00 +00:00
|
|
|
# Purpose of file: Fix permission, ACL and ownership of AlternC's files
|
2006-05-16 18:20:14 +00:00
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
|
2012-08-24 08:51:00 +00:00
|
|
|
# Default Query : fixperms for all account
|
2011-12-31 15:46:11 +00:00
|
|
|
query="SELECT uid,login FROM membres"
|
2011-12-31 16:00:30 +00:00
|
|
|
sub_dir=""
|
2012-06-12 17:11:46 +00:00
|
|
|
file=""
|
2012-08-24 08:51:00 +00:00
|
|
|
# Two optionals argument
|
2011-12-31 15:46:11 +00:00
|
|
|
# -l string : a specific login to fix
|
2012-08-24 08:51:00 +00:00
|
|
|
# -u integer : a specific uid to fix
|
|
|
|
# -f integer : a specific file to fix according to a given uid
|
2012-06-12 17:11:46 +00:00
|
|
|
|
|
|
|
while getopts "l:u:f:d:" optname
|
2011-12-31 15:46:11 +00:00
|
|
|
do
|
|
|
|
case "$optname" in
|
|
|
|
"l")
|
2012-06-12 17:11:46 +00:00
|
|
|
if [[ "$OPTARG" =~ ^[a-zA-Z0-9_]+$ ]] ; then
|
|
|
|
query="SELECT uid,login FROM membres WHERE login LIKE '$OPTARG'"
|
|
|
|
else
|
|
|
|
echo "Bad login provided"
|
|
|
|
exit
|
|
|
|
fi
|
2011-12-31 15:46:11 +00:00
|
|
|
;;
|
|
|
|
"u")
|
2012-06-12 17:11:46 +00:00
|
|
|
if [[ "$OPTARG" =~ ^[0-9]+$ ]] ; then
|
|
|
|
query="SELECT uid,login FROM membres WHERE uid LIKE '$OPTARG'"
|
|
|
|
else
|
|
|
|
echo "Bad uid provided"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
"f")
|
|
|
|
file="$OPTARG"
|
2011-12-31 15:46:11 +00:00
|
|
|
;;
|
2011-12-31 16:00:30 +00:00
|
|
|
"d")
|
|
|
|
sub_dir="$OPTARG"
|
|
|
|
;;
|
2011-12-31 15:46:11 +00:00
|
|
|
"?")
|
|
|
|
echo "Unknown option $OPTARG - stop processing"
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
":")
|
|
|
|
echo "No argument value for option $OPTARG - stop processing"
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
# Should not occur
|
|
|
|
echo "Unknown error while processing options"
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2006-05-16 18:20:14 +00:00
|
|
|
|
|
|
|
PATH=/sbin:/bin:/usr/sbin:/usr/bin
|
|
|
|
umask 022
|
|
|
|
|
2013-02-18 13:11:25 +00:00
|
|
|
CONFIG_FILE="/usr/lib/alternc/functions.sh"
|
2006-05-16 18:20:14 +00:00
|
|
|
if [ ! -r "$CONFIG_FILE" ]; then
|
|
|
|
echo "Can't access $CONFIG_FILE."
|
|
|
|
exit 1
|
|
|
|
fi
|
2013-02-18 13:11:25 +00:00
|
|
|
source "$CONFIG_FILE"
|
2006-05-16 18:20:14 +00:00
|
|
|
|
|
|
|
if [ `id -u` -ne 0 ]; then
|
2013-02-18 13:11:25 +00:00
|
|
|
echo "$0 must be launched as root"
|
2006-05-16 18:20:14 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2008-04-24 16:10:27 +00:00
|
|
|
doone() {
|
2012-08-24 09:06:19 +00:00
|
|
|
read GID LOGIN || true
|
2011-05-22 09:22:45 +00:00
|
|
|
while [ "$LOGIN" ] ; do
|
2006-05-16 18:20:14 +00:00
|
|
|
if [ "$DEBUG" ]; then
|
2011-05-22 19:18:43 +00:00
|
|
|
echo "Setting rights and ownership for user $LOGIN having gid $GID"
|
2006-05-16 18:20:14 +00:00
|
|
|
fi
|
2013-02-18 15:28:17 +00:00
|
|
|
REP="$(get_html_path_by_name "$LOGIN")"
|
2011-12-31 15:46:11 +00:00
|
|
|
|
2012-08-24 08:51:00 +00:00
|
|
|
# Set the file readable only for the AlternC User
|
2012-08-25 09:52:03 +00:00
|
|
|
mkdir -p "$REP"
|
2012-06-19 15:29:15 +00:00
|
|
|
chown -R alterncpanel:$GID "$REP"
|
2011-05-22 09:22:45 +00:00
|
|
|
chmod 2770 -R "$REP"
|
|
|
|
|
|
|
|
# Delete existings ACL
|
2011-05-22 17:23:59 +00:00
|
|
|
# Set the defaults acl on all the files
|
2012-06-19 15:29:15 +00:00
|
|
|
setfacl -b -k -n -R -m d:g:alterncpanel:rwx -m d:u::rwx -m d:g::rwx -m d:u:$GID:rwx -m d:g:$GID:rwx -m d:o::--- -m d:mask:rwx\
|
|
|
|
-Rm g:alterncpanel:rwx -m u:$GID:rwx -m g:$GID:rwx -m mask:rwx\
|
2012-06-12 17:11:46 +00:00
|
|
|
"$REP"
|
2011-05-22 09:22:45 +00:00
|
|
|
|
2012-08-24 08:51:00 +00:00
|
|
|
read GID LOGIN || true
|
2006-05-16 18:20:14 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2012-08-24 08:51:00 +00:00
|
|
|
fixfile() {
|
2012-06-12 17:11:46 +00:00
|
|
|
read GID LOGIN
|
2012-09-27 10:05:25 +00:00
|
|
|
/usr/bin/setfacl -bk "$file"
|
2012-06-12 17:11:46 +00:00
|
|
|
echo "gid: $GID"
|
|
|
|
echo "file: $file"
|
2012-09-27 10:05:25 +00:00
|
|
|
chown alterncpanel:$GID "$file"
|
|
|
|
chmod 0770 "$file"
|
|
|
|
/usr/bin/setfacl -m u:$GID:rw- -m g:$GID:rw- -m g:alterncpanel:rw- -m u:$GID:rw- -m g:$GID:rw- "$file"
|
2012-06-12 17:11:46 +00:00
|
|
|
echo file ownership and ACLs changed
|
|
|
|
}
|
|
|
|
|
2012-08-24 08:51:00 +00:00
|
|
|
if [[ "$file" != "" ]]; then
|
|
|
|
if [ -e "$file" ]; then
|
|
|
|
mysql --defaults-file=/etc/alternc/my.cnf --skip-column-names -B -e "$query" |fixfile
|
2012-06-12 17:11:46 +00:00
|
|
|
else
|
|
|
|
echo "file not found"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
mysql --defaults-file=/etc/alternc/my.cnf --skip-column-names -B -e "$query" |doone
|
|
|
|
fi
|