Svdrp-isdn-from-fli4l
Aus VDR Wiki
(Unterschied zwischen Versionen)
| Zeile 6: | Zeile 6: | ||
nummer=name | nummer=name | ||
</pre> | </pre> | ||
| + | |||
| + | Außerdem wird noch ein kleines C-Programm benötigt, das unter /usr/local/bin/tt erwartet wird (einfach als tt.c speichern und mit gcc -o tt tt.c kompilieren) | ||
| + | |||
| + | <pre> | ||
| + | #include <stdlib.h> | ||
| + | #include <stdio.h> | ||
| + | #include <time.h> | ||
| + | |||
| + | // take seconds from first argument, | ||
| + | // subtract from actual localtime | ||
| + | // and print new time to stdout | ||
| + | int main (int argc, char* argv[]) | ||
| + | { | ||
| + | if (argc < 2) | ||
| + | { | ||
| + | fprintf (stderr, "usage: %s <sec>\n", argv[0]); | ||
| + | exit(-1); | ||
| + | } | ||
| + | time_t now; | ||
| + | time(&now); | ||
| + | now -= atol(argv[1]); | ||
| + | |||
| + | tm *x = localtime(&(now)); | ||
| + | fprintf (stdout, "%s", asctime(x)); | ||
| + | } | ||
| + | </pre> | ||
| + | |||
Hier das Script: | Hier das Script: | ||
Version vom 6. September 2004, 18:19 Uhr
Dieses Script kann über die commands.conf auf dem VDR aufgerufen werden. Es holt vom fli4l-Router Statusinformationen (z.B. uptime, DSL-Status incl. IP-Adresse) sowie die gespeicherten ISDN-Anrufe, ergänzt diese bei Bedarf um die Namen (Zuordnung in Datei /etc/vdr/phone.txt) und zeigt alle Informationen an.
Format der Telefonnummerdatei /etc/vdr/phone.txt:
nummer=name
Außerdem wird noch ein kleines C-Programm benötigt, das unter /usr/local/bin/tt erwartet wird (einfach als tt.c speichern und mit gcc -o tt tt.c kompilieren)
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
// take seconds from first argument,
// subtract from actual localtime
// and print new time to stdout
int main (int argc, char* argv[])
{
if (argc < 2)
{
fprintf (stderr, "usage: %s <sec>\n", argv[0]);
exit(-1);
}
time_t now;
time(&now);
now -= atol(argv[1]);
tm *x = localtime(&(now));
fprintf (stdout, "%s", asctime(x));
}
Hier das Script:
#!/bin/sh
host=fli4lHost
port=5000
cmd="nc -w 2 $host $port"
tmp=/tmp/vdrFli4l
phone=/etc/vdr/phone.txt
export COLUMNS=512
lines=20
rm -f $tmp
##############################################
# get uptime from router
##############################################
seconds=`\
{
echo uptime
echo quit
} | $cmd | awk '{print substr($2,1,length($2)-1);}'`
uptime=`/usr/local/bin/tt $seconds`
##############################################
# get status of pppoe device
##############################################
statusDSL=`\
{
echo status pppoe
echo quit
} | $cmd | awk '{print substr($2,1,length($2)-1);}'`
##############################################
# get ip of pppoe device
##############################################
ipDSL=`\
{
echo ip pppoe
echo quit
} | $cmd | awk '{print substr($2,1,length($2)-1);}'`
##############################################
printf "*************************************
Router
*************************************
Up since $uptime
DSL: ${statusDSL}"
if [ "$statusDSL" = "Online" ]
then
printf " (IP: $ipDSL)"
fi
printf "
*************************************
Calls
*************************************\n"
{
echo telmond-log-file
echo quit
} | $cmd | grep -v OK | sort -r | sed -e 's/ /=/g' > $tmp
awk '
BEGIN { FS="="; }
FILENAME ~ /phone/\
{
phonebook[$1] = $2;
}
FILENAME ~ /tmp/\
{
number=$4;
caller=phonebook[number];
if (caller == "")
caller=number;
printf ("%s %s %s\n", $2, $3, caller);
}
' $phone $tmp
printf "*************************************\n"