2011-01-28 15:55:26 +00:00
|
|
|
#!/bin/bash
|
2007-09-09 18:18:19 +00:00
|
|
|
|
2012-08-26 17:20:10 +00:00
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
# AlternC - Web Hosting System
|
|
|
|
# Copyright (C) 2000-2012 by the AlternC Development Team.
|
|
|
|
# https://alternc.org/
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
# 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
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
# Purpose of file: Main functions used for any bash script for AlternC.
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
# Init some vars
|
2011-01-28 15:55:26 +00:00
|
|
|
. /etc/alternc/local.sh
|
|
|
|
|
2012-08-26 17:20:10 +00:00
|
|
|
|
2011-01-28 15:55:26 +00:00
|
|
|
# Init some other vars
|
2011-01-29 15:12:26 +00:00
|
|
|
MYSQL_DO="/usr/bin/mysql --defaults-file=/etc/alternc/my.cnf -Bs -e "
|
2011-02-01 22:44:18 +00:00
|
|
|
mysql_query() { /usr/bin/mysql --defaults-file=/etc/alternc/my.cnf -Bs -e "$@" ; }
|
2011-01-28 15:55:26 +00:00
|
|
|
DOMAIN_LOG_FILE="/var/log/alternc/update_domains.log"
|
2011-01-29 15:46:33 +00:00
|
|
|
VHOST_FILE="$VHOST_DIR/vhosts_all.conf"
|
2012-10-15 14:20:38 +00:00
|
|
|
VHOST_MANUALCONF="$VHOST_DIR/manual/"
|
2011-01-28 15:55:26 +00:00
|
|
|
|
2012-08-26 17:20:10 +00:00
|
|
|
|
|
|
|
# Some useful miscellaneous shell functions
|
2007-09-09 18:21:57 +00:00
|
|
|
print_domain_letter() {
|
2012-04-20 16:52:16 +00:00
|
|
|
local domain=$1
|
|
|
|
domain=${domain/.${domain/*./}/}
|
|
|
|
domain=${domain/*./}
|
|
|
|
domain=${domain:0:1}
|
2012-08-26 17:20:10 +00:00
|
|
|
# Bash match a 'é' when we give him [a-z]. Strange
|
2012-04-20 16:52:16 +00:00
|
|
|
if [[ "$domain" =~ [ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0-9]{1} ]]; then
|
|
|
|
echo $domain
|
|
|
|
else
|
|
|
|
echo '_'
|
|
|
|
fi
|
2007-09-09 18:21:57 +00:00
|
|
|
}
|
|
|
|
|
2012-08-26 17:20:10 +00:00
|
|
|
|
|
|
|
# echoes the first letter of an alternc account name.
|
2007-09-09 18:21:57 +00:00
|
|
|
print_user_letter() {
|
|
|
|
local user="$1"
|
2012-02-06 08:28:40 +00:00
|
|
|
echo ${user:0:1}
|
2007-09-09 18:21:57 +00:00
|
|
|
}
|
|
|
|
|
2012-08-26 17:20:10 +00:00
|
|
|
|
|
|
|
# return the uid of an alternc account
|
2011-05-17 16:36:01 +00:00
|
|
|
get_uid_by_name() {
|
|
|
|
mysql_query 'SELECT uid FROM membres WHERE login="'"$1"'" LIMIT 1;'
|
|
|
|
}
|
|
|
|
|
2012-08-26 17:20:10 +00:00
|
|
|
|
2007-09-09 18:18:19 +00:00
|
|
|
# imprime le nom d'usager associé au domaine
|
|
|
|
get_account_by_domain() {
|
2011-02-01 22:44:18 +00:00
|
|
|
mysql_query 'SELECT a.login FROM membres a, sub_domaines b WHERE a.uid = b.compte AND \
|
2011-01-28 15:55:26 +00:00
|
|
|
CONCAT(IF(sub="", "", CONCAT(sub, ".")), domaine) = "'"$1"'" LIMIT 1;'
|
2007-09-09 18:18:19 +00:00
|
|
|
}
|
|
|
|
|
2012-10-15 14:20:38 +00:00
|
|
|
get_uid_by_domain() {
|
|
|
|
mysql_query 'SELECT b.compte as uid FROM sub_domaines b WHERE \
|
|
|
|
CONCAT(IF(sub="", "", CONCAT(sub, ".")), domaine) = "'"$1"'" LIMIT 1;'
|
|
|
|
}
|
2012-08-26 17:20:10 +00:00
|
|
|
|
|
|
|
# Log (echoes+log) an error and exit the current script with an error.
|
2011-01-28 15:55:26 +00:00
|
|
|
log_error() {
|
|
|
|
local error=$1
|
|
|
|
echo "`date` $0 : $1" | tee -a "$DOMAIN_LOG_FILE" >&2
|
|
|
|
exit 1
|
2007-09-09 18:18:19 +00:00
|
|
|
}
|
|
|
|
|