Patch/simplifications d'une serie d'alternc tools (quota et permissions)

Reecriture de slave-dns pour qu'il utilise le template (avant il utilisait
le template la premiere fois, et après utilisait un template en dur dans 
son code)
This commit is contained in:
Alan Garcia 2012-02-06 08:28:40 +00:00
parent 3bf287e3d6
commit a6ad7476bc
9 changed files with 78 additions and 155 deletions

2
.gitattributes vendored
View File

@ -475,9 +475,7 @@ src/mem_add -text
src/mem_del -text
src/quota_delete -text
src/quota_edit -text
src/quota_edit.sh -text
src/quota_get -text
src/quota_get.sh -text
src/quota_init -text
src/rawstat.daily -text
src/sendmail -text

View File

@ -1,8 +1,10 @@
// DO NOT EDIT THIS FILE, IT WILL BE OVERWRITTEN
// Use the AlternC managment console instead.
// Do NOT remove any comment of this template
acl "allslaves" {
{
127.0.0.1;
};
{
127.0.0.1;
//AUTO-SLAVES//
};
};

View File

@ -105,4 +105,5 @@ doone() {
done
}
mysql --defaults-file=/etc/alternc/my.cnf -B -e "$query" |grep -v ^uid|doone
mysql --defaults-file=/etc/alternc/my.cnf --skip-column-names -B -e "$query" |doone

View File

@ -23,7 +23,7 @@ print_domain_letter() {
print_user_letter() {
local user="$1"
echo "$user" | awk '{print substr($1, 1, 1)}'
echo ${user:0:1}
}
get_uid_by_name() {

View File

@ -1,33 +1,17 @@
#!/usr/bin/perl
#!/bin/bash
. /etc/alternc/local.sh
use strict;
# Set disk quota to an user
# Won't work over NFS
my ($uid,$size) = @ARGV;
MID=$1
SIZE=$2
if (!$size || !$uid) {
print "Usage: quota_edit <uid> <size>\n";
print " Edit the quota of the AlternC account having uid <uid> the the available space to <size>\n";
exit(1);
}
if [ $# -ne 2 ] || [[ ! "$MID" =~ ^[0-9]+$ ]] || [[ ! "$SIZE" =~ ^[0-9]+$ ]]; then
echo "Usage: quota_edit <uid> <size>"
echo "Edit the quota of the AlternC account having uid <uid> the the available space to <size>"
exit 1
fi
$ENV{PATH} = "";
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
if (!($uid =~ /^([0-9]+)$/)) {
die "uid is incorrect.";
}
$uid=$1;
if (!($size =~ /^([0-9]+)$/)) {
die "size is incorrect.";
}
$size=$1;
$< = $>;
$( = $);
my $PTH="/usr/lib/alternc/quota_edit.sh '$uid' '$size'";
system($PTH);
0;
DATA_PART=`$DF "${ALTERNC_LOC}/html" 2>/dev/null | $AWK 'NR==2 { print $1 }'`
/usr/sbin/setquota -r -g $MID $SIZE $SIZE 0 0 $DATA_PART 2>/dev/null || echo "Group quota are not enabled on /var/alternc." >&2

View File

@ -1,4 +0,0 @@
#!/bin/bash
. /etc/alternc/local.sh
DATA_PART=`/bin/df ${ALTERNC_LOC} 2>/dev/null | /usr/bin/awk '/^\// { print $1 }'`
/usr/sbin/setquota -r -g $1 $2 $2 0 0 $DATA_PART 2>/dev/null || echo "Group quota are not enabled on /var/alternc." >&2

View File

@ -1,28 +1,43 @@
#!/usr/bin/perl
#!/bin/bash
. /etc/alternc/local.sh
use strict;
AWK=/usr/bin/awk
DF=/bin/df
SED=/bin/sed
MOUNT=/bin/mount
QUOTA=/usr/bin/quota
GREP=/bin/grep
WC=/usr/bin/wc
my ($uid) = @ARGV;
MID=$1
if (!$uid) {
print "Usage: quota_get <uid>\n";
print " Get the quota of the AlternC account having uid <uid>\n";
exit(1);
}
if [ "x$MID" == "x" ] ; then
echo "Usage: quota_get <uid>"
echo "Get the quota of the AlternC account having uid <uid>"
exit 1
fi
$ENV{PATH} = "";
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
# The second line is the one interesting
# We look precisely on the HTML directory. Why ? because it's surely
# the bigger one, and if someone separate it we need to look this one
# particulary. It should be interesting to cumulate quota of all mounted directory.
DATA_PART=`$DF "${ALTERNC_LOC}/html" 2>/dev/null | $AWK 'NR==2 { print $1 }'`
if (!($uid =~ /^([0-9]+)$/)) {
die "uid is incorrect.";
}
$uid=$1;
# quota will give over NFS will print the partition using the full NFS name
# (e.g. 10.0.0.1:/var/alternc) so we need to lookup first with mount
# to convert DATA_PART if needed.
QUOTA_PART=`$MOUNT | $SED -n -e "s,\([^ ]*\) on ${DATA_PART} type nfs.*,\1,p"`
if [ -z "$QUOTA_PART" ]; then
QUOTA_PART="$DATA_PART"
fi
$< = $>;
$( = $);
# Now we get the quota
val=$(quota -A -wg "$MID" |grep "$QUOTA_PART" | awk '{ print $2 "\n" $3; }')
my $PTH="/usr/lib/alternc/quota_get.sh '$uid'";
# If the quota aren't activated, I return something anyway
if [ -z "$val" ] ; then
echo -e "0\n0"
else
echo -e "$val"
fi
system($PTH);
0;

View File

@ -1,46 +0,0 @@
#!/bin/bash
. /etc/alternc/local.sh
AWK=/usr/bin/awk
DF=/bin/df
SED=/bin/sed
MOUNT=/bin/mount
QUOTA=/usr/bin/quota
GREP=/bin/grep
WC=/usr/bin/wc
DATA_PART=`$DF ${ALTERNC_LOC} 2>/dev/null | $AWK '/^\// { print $1 }'`
# quota will give over NFS will print the partition using the full NFS name
# (e.g. 10.0.0.1:/var/alternc) so we need to lookup first with mount
# to convert DATA_PART if needed.
QUOTA_PART=`$MOUNT | $SED -n -e "s,\([^ ]*\) on ${DATA_PART} type nfs.*,\1,p"`
if [ -z "$QUOTA_PART" ]; then
QUOTA_PART="$DATA_PART"
fi
# quota will split its display on two lines if QUOTA_PART is bigger than 15
# characters. *sigh*
PART_LEN=`echo -n "$QUOTA_PART" | $WC -c`
val=$(
if [ "$PART_LEN" -gt 15 ]; then
$QUOTA -g "$1" |
$SED -n -e "\\;${QUOTA_PART};,+1s/ *\([0-9]*\) .*/\1/p" |
$GREP -v '^$'
$QUOTA -g "$1" |
$SED -n -e "\\;${QUOTA_PART};,+1s/ *[0-9]* *\([0-9]*\) .*/\1/p" |
$GREP -v '^$'
else
$QUOTA -g "$1" | $AWK /${QUOTA_PART//\//\\\/}/\ {print\ '$2'}
$QUOTA -g "$1" | $AWK /${QUOTA_PART//\//\\\/}/\ {print\ '$3'}
fi
)
# If the quota aren't activated, I return something anyway
if [ -z "$val" ] ; then
echo 0
echo 0
else
echo -e "$val"
fi

View File

@ -1,57 +1,30 @@
#!/usr/bin/php -q
<?php
#!/bin/bash
/*
$Id: slave_dns,v 1.5 2004/11/25 17:20:55 anonymous Exp $
----------------------------------------------------------------------
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
# Rebuild the bind configuration's file
# with the IP of the slave dns
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.
FLAGFILE="/var/run/alternc/refresh_slave";
TPL="/etc/alternc/templates/bind/slaveip.conf"
TARGET="/var/alternc/bind/slaveip.conf"
TMP=$(mktemp /tmp/slaveip.conf.XXXX)
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.
if [ ! -e "$FLAGFILE" ] ; then
# Nothing to do
exit 0
fi
To read the license please visit http://www.gnu.org/copyleft/gpl.html
----------------------------------------------------------------------
Original Author of file: Benjamin Sonntag
Purpose of file: Manage allowed slave dns ip addresses / classes
----------------------------------------------------------------------
# Source some functions
. /usr/lib/alternc/functions.sh
*/
# Get the slave IP. Remove the "newline" caracters
val=$(mysql_query "SELECT concat(ip,'::',class,'; ') FROM slaveip;"|tr '\n' ' ')
$FLAGFILE="/var/run/alternc/refresh_slave";
# Add the slaves to the templates, re-add the missing "/" separator of subnet
cat "$TPL" | sed -e "s/\/\/AUTO-SLAVES\/\//$val/g" -e "s/::/\//g" > "$TMP"
if (file_exists($FLAGFILE)) {
unlink($FLAGFILE);
include("/var/alternc/bureau/class/local.php");
mysql_connect($L_MYSQL_HOST,$L_MYSQL_LOGIN,$L_MYSQL_PWD);
mysql_select_db($L_MYSQL_DATABASE);
$r=mysql_query("SELECT * FROM slaveip");
$f=fopen("/var/alternc/bind/slaveip.conf","wb");
fputs($f,"
// DO NOT EDIT THIS FILE, IT WILL BE OVERWRITTEN
// Use the AlternC managment console instead.
acl \"allslaves\" {
{
127.0.0.1; // myself, just to be sure
");
while ($c=mysql_fetch_array($r)) {
fputs($f,$c['ip']."/".$c['class'].";\n");
}
fputs($f,"};\n};\n");
fclose($f);
exec("invoke-rc.d bind9 reload");
}
# Activate the new configuration
mv "$TMP" "$TARGET"
chown root:bind "$TARGET"
chmod 640 "$TARGET"
invoke-rc.d bind9 reload