2012-04-12 14:06:47 +00:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
# FIXME relecture + commentaires
|
|
|
|
|
|
|
|
|
|
id=$1
|
|
|
|
|
url=$2
|
|
|
|
|
email=$3
|
|
|
|
|
schedule=$4
|
|
|
|
|
now=$5
|
|
|
|
|
user=$6
|
|
|
|
|
password=$7
|
|
|
|
|
|
|
|
|
|
timeout=5
|
|
|
|
|
|
|
|
|
|
for CONFIG_FILE in \
|
|
|
|
|
/etc/alternc/local.sh \
|
|
|
|
|
/usr/lib/alternc/functions.sh
|
|
|
|
|
do
|
|
|
|
|
if [ ! -r "$CONFIG_FILE" ]; then
|
|
|
|
|
echo "Can't access $CONFIG_FILE."
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
. "$CONFIG_FILE"
|
|
|
|
|
done
|
|
|
|
|
|
2012-08-22 07:42:17 +00:00
|
|
|
|
from="noreply@$FQDN"
|
|
|
|
|
|
2012-04-12 14:06:47 +00:00
|
|
|
|
if [ "x$url" == "x" ] ; then
|
|
|
|
|
echo Missing arguments
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
urldecode() {
|
|
|
|
|
arg="$1"
|
|
|
|
|
i="0"
|
|
|
|
|
(
|
|
|
|
|
while [ "$i" -lt ${#arg} ]; do
|
|
|
|
|
c0=${arg:$i:1}
|
|
|
|
|
if [ "x$c0" = "x%" ]; then
|
|
|
|
|
c1=${arg:$((i+1)):1}
|
|
|
|
|
c2=${arg:$((i+2)):1}
|
|
|
|
|
printf "\x$c1$c2"
|
|
|
|
|
i=$((i+3))
|
|
|
|
|
else
|
|
|
|
|
echo -n "$c0"
|
|
|
|
|
i=$((i+1))
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
) | sed -e 's/"/\\"/g' -e 's/\!/\\\!/g'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
params=""
|
|
|
|
|
if [ ! "x$user" == "x" -a ! "x$password" == "x" ]; then
|
|
|
|
|
params="--http-user=\"$(urldecode $user)\" --http-password=\"$(urldecode $password)\""
|
|
|
|
|
fi
|
|
|
|
|
|
2012-08-22 07:42:17 +00:00
|
|
|
|
wget -O - $params "$(urldecode $url)" --timeout=$timeout | mailx -s "AlternC Cron $id - Report $date" -r "$from" "$email"
|
2012-04-12 14:06:47 +00:00
|
|
|
|
|
|
|
|
|
# On calcule l'heure de la prochaine execution idéale
|
|
|
|
|
((interval=$schedule * 60))
|
|
|
|
|
((next=$(( $(( $now / $interval)) + 1 )) * $interval ))
|
|
|
|
|
|
|
|
|
|
# On check pour pas avoir d'injection SQL
|
|
|
|
|
if [[ ! "$id" =~ ^[0-9]+$ || ! "$next" =~ ^[0-9]+$ ]] ; then
|
|
|
|
|
echo "Id +$id+ or time +$next+ is incorrect."
|
|
|
|
|
return 2
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
$MYSQL_DO "update cron set next_execution = FROM_UNIXTIME($next) where id = $id;"
|
|
|
|
|
|