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:
parent
3bf287e3d6
commit
a6ad7476bc
|
@ -475,9 +475,7 @@ src/mem_add -text
|
||||||
src/mem_del -text
|
src/mem_del -text
|
||||||
src/quota_delete -text
|
src/quota_delete -text
|
||||||
src/quota_edit -text
|
src/quota_edit -text
|
||||||
src/quota_edit.sh -text
|
|
||||||
src/quota_get -text
|
src/quota_get -text
|
||||||
src/quota_get.sh -text
|
|
||||||
src/quota_init -text
|
src/quota_init -text
|
||||||
src/rawstat.daily -text
|
src/rawstat.daily -text
|
||||||
src/sendmail -text
|
src/sendmail -text
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
// DO NOT EDIT THIS FILE, IT WILL BE OVERWRITTEN
|
// DO NOT EDIT THIS FILE, IT WILL BE OVERWRITTEN
|
||||||
// Use the AlternC managment console instead.
|
// Use the AlternC managment console instead.
|
||||||
|
// Do NOT remove any comment of this template
|
||||||
|
|
||||||
acl "allslaves" {
|
acl "allslaves" {
|
||||||
{
|
{
|
||||||
127.0.0.1;
|
127.0.0.1;
|
||||||
|
//AUTO-SLAVES//
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -105,4 +105,5 @@ doone() {
|
||||||
done
|
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
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ print_domain_letter() {
|
||||||
|
|
||||||
print_user_letter() {
|
print_user_letter() {
|
||||||
local user="$1"
|
local user="$1"
|
||||||
echo "$user" | awk '{print substr($1, 1, 1)}'
|
echo ${user:0:1}
|
||||||
}
|
}
|
||||||
|
|
||||||
get_uid_by_name() {
|
get_uid_by_name() {
|
||||||
|
|
|
@ -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) {
|
if [ $# -ne 2 ] || [[ ! "$MID" =~ ^[0-9]+$ ]] || [[ ! "$SIZE" =~ ^[0-9]+$ ]]; then
|
||||||
print "Usage: quota_edit <uid> <size>\n";
|
echo "Usage: quota_edit <uid> <size>"
|
||||||
print " Edit the quota of the AlternC account having uid <uid> the the available space to <size>\n";
|
echo "Edit the quota of the AlternC account having uid <uid> the the available space to <size>"
|
||||||
exit(1);
|
exit 1
|
||||||
}
|
fi
|
||||||
|
|
||||||
$ENV{PATH} = "";
|
DATA_PART=`$DF "${ALTERNC_LOC}/html" 2>/dev/null | $AWK 'NR==2 { print $1 }'`
|
||||||
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
|
/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
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
|
@ -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
|
|
|
@ -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) {
|
if [ "x$MID" == "x" ] ; then
|
||||||
print "Usage: quota_get <uid>\n";
|
echo "Usage: quota_get <uid>"
|
||||||
print " Get the quota of the AlternC account having uid <uid>\n";
|
echo "Get the quota of the AlternC account having uid <uid>"
|
||||||
exit(1);
|
exit 1
|
||||||
}
|
fi
|
||||||
|
|
||||||
$ENV{PATH} = "";
|
# The second line is the one interesting
|
||||||
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
|
# 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]+)$/)) {
|
# quota will give over NFS will print the partition using the full NFS name
|
||||||
die "uid is incorrect.";
|
# (e.g. 10.0.0.1:/var/alternc) so we need to lookup first with mount
|
||||||
}
|
# to convert DATA_PART if needed.
|
||||||
$uid=$1;
|
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;
|
|
||||||
|
|
|
@ -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
|
|
||||||
|
|
|
@ -1,57 +1,30 @@
|
||||||
#!/usr/bin/php -q
|
#!/bin/bash
|
||||||
<?php
|
|
||||||
|
|
||||||
/*
|
# Rebuild the bind configuration's file
|
||||||
$Id: slave_dns,v 1.5 2004/11/25 17:20:55 anonymous Exp $
|
# with the IP of the slave dns
|
||||||
----------------------------------------------------------------------
|
|
||||||
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
|
FLAGFILE="/var/run/alternc/refresh_slave";
|
||||||
modify it under the terms of the GNU General Public License (GPL)
|
TPL="/etc/alternc/templates/bind/slaveip.conf"
|
||||||
as published by the Free Software Foundation; either version 2
|
TARGET="/var/alternc/bind/slaveip.conf"
|
||||||
of the License, or (at your option) any later version.
|
TMP=$(mktemp /tmp/slaveip.conf.XXXX)
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
if [ ! -e "$FLAGFILE" ] ; then
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# Nothing to do
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
exit 0
|
||||||
GNU General Public License for more details.
|
fi
|
||||||
|
|
||||||
To read the license please visit http://www.gnu.org/copyleft/gpl.html
|
# Source some functions
|
||||||
----------------------------------------------------------------------
|
. /usr/lib/alternc/functions.sh
|
||||||
Original Author of file: Benjamin Sonntag
|
|
||||||
Purpose of file: Manage allowed slave dns ip addresses / classes
|
|
||||||
----------------------------------------------------------------------
|
|
||||||
|
|
||||||
*/
|
# 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)) {
|
# Activate the new configuration
|
||||||
unlink($FLAGFILE);
|
mv "$TMP" "$TARGET"
|
||||||
include("/var/alternc/bureau/class/local.php");
|
chown root:bind "$TARGET"
|
||||||
mysql_connect($L_MYSQL_HOST,$L_MYSQL_LOGIN,$L_MYSQL_PWD);
|
chmod 640 "$TARGET"
|
||||||
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
invoke-rc.d bind9 reload
|
||||||
|
|
Loading…
Reference in New Issue