| 1 | #!/bin/bash |
|---|
| 2 | # |
|---|
| 3 | # $Id: get_account_by_domain 22 2005-04-11 17:21:15Z jerome $ |
|---|
| 4 | # ---------------------------------------------------------------------- |
|---|
| 5 | # AlternC - Web Hosting System |
|---|
| 6 | # Copyright (C) 2002 by the AlternC Development Team. |
|---|
| 7 | # http://alternc.org |
|---|
| 8 | # ---------------------------------------------------------------------- |
|---|
| 9 | # Based on: |
|---|
| 10 | # Valentin Lacambre's web hosting softwares: http://altern.org/ |
|---|
| 11 | # ---------------------------------------------------------------------- |
|---|
| 12 | # LICENSE |
|---|
| 13 | # |
|---|
| 14 | # This program is free software; you can redistribute it and/or |
|---|
| 15 | # modify it under the terms of the GNU General Public License (GPL) |
|---|
| 16 | # as published by the Free Software Foundation; either version 2 |
|---|
| 17 | # of the License, or (at your option) any later version. |
|---|
| 18 | # |
|---|
| 19 | # This program is distributed in the hope that it will be useful, |
|---|
| 20 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 21 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 22 | # GNU General Public License for more details. |
|---|
| 23 | # |
|---|
| 24 | # To read the license please visit http://www.gnu.org/copyleft/gpl.html |
|---|
| 25 | # ---------------------------------------------------------------------- |
|---|
| 26 | # Original Author of file: Jerome Moinet |
|---|
| 27 | # Purpose of file: gives account by domains or sub-domains |
|---|
| 28 | # ---------------------------------------------------------------------- |
|---|
| 29 | # |
|---|
| 30 | PATH="" |
|---|
| 31 | PROG_NAME=get_account_by_domain |
|---|
| 32 | PROG_VERSION=0.1.0 |
|---|
| 33 | ALTERNC_ETC=/etc/alternc |
|---|
| 34 | ALTERNC_CONF_FILE=$ALTERNC_ETC/local.sh |
|---|
| 35 | export TEXTDOMAIN=alternc-admintools |
|---|
| 36 | |
|---|
| 37 | # Be sure to use the right programs on Debian |
|---|
| 38 | # and be sure they are there |
|---|
| 39 | id=/usr/bin/id |
|---|
| 40 | mysql=/usr/bin/mysql |
|---|
| 41 | sed=/bin/sed |
|---|
| 42 | gettext=/usr/bin/gettext |
|---|
| 43 | printf=/usr/bin/printf |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | # Must have gettext first to display error messages |
|---|
| 47 | [ -x "$gettext" ] || { echo "Cannot execute $gettext"; exit 1 ; } |
|---|
| 48 | |
|---|
| 49 | for i in $id $mysql $sed $printf |
|---|
| 50 | do |
|---|
| 51 | ! [ -x "$i" ] && { echo "$($gettext "Unable to execute") ${i}."; exit 1 ; } |
|---|
| 52 | done |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | # Language-dependent messages |
|---|
| 56 | # Uses gettext and mo files. |
|---|
| 57 | # Don't change these messages, change the .po file instead. |
|---|
| 58 | HELP=$($gettext "Gives account hosting domain or sub-domain.") |
|---|
| 59 | USAGE=`$printf "$($gettext "Usage: %s [domain|sub-domain].")" $PROG_NAME` |
|---|
| 60 | NOT_FOUND_MSG=$($gettext "does not exist.") |
|---|
| 61 | NON_ROOT_MSG=$($gettext "You have to be root (uid 0) to execute this program.") |
|---|
| 62 | MISSING_PROG=$($gettext "Unable to execute") |
|---|
| 63 | MISSING_CONF_FILE=`$printf "$($gettext "Can't find %s. Are you sure AlterncC is properly installed?")" $ALTERNC_CONF_FILE` |
|---|
| 64 | MYSQL_UNREACHABLE_DATABASE=`$printf "$($gettext "Cannot access accounts database. Please check either %s or Mysql state.")" $ALTERNC_CONF_FILE` |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | #------------------------- |
|---|
| 68 | # Main |
|---|
| 69 | #------------------------- |
|---|
| 70 | # Must be root |
|---|
| 71 | [ "`$id -u`" != "0" ] && { echo $NON_ROOT_MSG ; exit 1 ; } |
|---|
| 72 | # Must have minimum 1 parameter |
|---|
| 73 | [ -z "$1" ] && { echo $USAGE ; exit 1 ; } |
|---|
| 74 | # Handle -h and --help flags |
|---|
| 75 | [ "$1" = "-h" ] || [ "$1" = "--help" ] && { echo $HELP ; echo $USAGE ; exit 0 ; } |
|---|
| 76 | # Have to get AlternC conf file : |
|---|
| 77 | ! [ -f "$ALTERNC_CONF_FILE" ] && { echo $MISSING_CONF_FILE ; exit 1 ; } || . $ALTERNC_CONF_FILE |
|---|
| 78 | mysql="$mysql --defaults-file=/etc/alternc/my.cnf" |
|---|
| 79 | $mysql -e "select count(*) from domaines_standby;" > /dev/null 2>&1 |
|---|
| 80 | [ "$?" != 0 ] && { echo "$MYSQL_UNREACHABLE_DATABASE" ; exit 1 ; } |
|---|
| 81 | |
|---|
| 82 | # Does the stuff |
|---|
| 83 | $mysql -B -N -e "select concat(a.login, \" (\", a.mail, \")\") from membres a, sub_domaines b where a.uid = b.compte and concat(if(sub=\"\", \"\", concat(sub, \".\")), domaine) = \"${1}\";" |
|---|
| 84 | |
|---|
| 85 | |
|---|