get_domains_by_account 3.34 KB
Newer Older
1
#!/bin/bash
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
#
# $Id: get_domains_by_account 22 2005-04-11 17:21:15Z jerome $
# ----------------------------------------------------------------------
# AlternC - Web Hosting System
# Copyright (C) 2002 by the AlternC Development Team.
# http://alternc.org
# ----------------------------------------------------------------------
# Based on:
# Valentin Lacambre's web hosting softwares: http://altern.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
# ----------------------------------------------------------------------
# Original Author of file: Jerome Moinet
# Purpose of file: gives domains and sub-domains attached to an account
# ----------------------------------------------------------------------
#
PATH=""
PROG_NAME=get_domains_by_account
PROG_VERSION=0.1.0
ALTERNC_ETC=/etc/alternc
ALTERNC_CONF_FILE=$ALTERNC_ETC/local.sh
export TEXTDOMAIN=alternc-admintools


# Be sure to use the right programs on Debian
# and be sure they are there
id=/usr/bin/id
mysql=/usr/bin/mysql
gettext=/usr/bin/gettext
printf=/usr/bin/printf

# Must have gettext first to display error messages
[ -x "$gettext" ] || { echo "Cannot execute $gettext"; exit 1 ; }

for i in $id $mysql $printf
do
  ! [ -x "$i" ] && { echo "$($gettext "Unable to execute") ${i}."; exit 1 ; }
done

# Language-dependent messages
# Uses gettext and mo files.
# Don't change these messages, change the .po file instead.
HELP=$($gettext "Gives domains and sub-domains attached to an account.")
USAGE=`$printf "$($gettext "Usage: %s account.")" $PROG_NAME`
NOT_FOUND_MSG=$($gettext "does not exist.")
NON_ROOT_MSG=$($gettext "You have to be root (uid 0) to execute this program.")
MISSING_PROG=$($gettext "Unable to execute")
MISSING_CONF_FILE=`$printf "$($gettext "Can't find %s. Are you sure AlterncC is properly installed?")" $ALTERNC_CONF_FILE`
MYSQL_UNREACHABLE_DATABASE=`$printf "$($gettext "Cannot access accounts database. Please check either %s or Mysql state.")" $ALTERNC_CONF_FILE`


#-------------------------
# Main
#-------------------------
# Must be root
[ "`$id -u`" != "0" ] && { echo $NON_ROOT_MSG ; exit 1 ; }
# Must have minimum 1 parameter
[ -z "$1" ] && { echo $USAGE ; exit 1 ; }
# Handle -h and --help flags
[ "$1" = "-h" ] || [ "$1" = "--help" ] && { echo $HELP ; echo $USAGE ; exit 0 ; }
# Have to get AlternC conf file :
! [ -f "$ALTERNC_CONF_FILE" ] && { echo $MISSING_CONF_FILE ; exit 1 ; } || . $ALTERNC_CONF_FILE
# Must have access to mysql to retreive accounts owning domains :
77
mysql="$mysql --defaults-file=/etc/alternc/my.cnf -B -N -e"
Alan Garcia's avatar
Alan Garcia committed
78
$mysql "desc domaines;" > /dev/null 2>&1
79
[ "$?" != 0 ] && { echo "$MYSQL_UNREACHABLE_DATABASE" ; exit 1 ; }
80 81 82 83 84

# Does the stuff
$mysql "select concat(a.sub, if(a.sub=\"\",\"\", \".\"), a.domaine) from sub_domaines a, membres b where a.compte = b.uid and b.login = \"${1}\";"