Moin
Mit...
Code:
internet_forwardrules =
"tcp 0.0.0.0:231 0.0.0.0:23 0 # Telnet-Server",
"tcp 0.0.0.0:82 0.0.0.0:4200 0 # HTTP-Server",
"tcp 0.0.0.0:81 0.0.0.0:81 0 # HTTP-Server",
"tcp 0.0.0.0:2222 0.0.0.0:22 0 # SSH-Server",
"tcp 0.0.0.0:84 0.0.0.0:8088 0 # HTTP-Server";
...gibst du Dienste (Server) frei, die auf der Box selber laufen.
Freigaben (Portforwarding) für einzelne Geräte findest du...
Code:
landevices {
landevices_version = 2;
landevices {
ip = 10.10.10.40;
name = "\336\255\276\257\336\255\276\257\336\255\276\257\336\255\276\257ZZZZZ
mac = 00:00:00:00:00:00;
medium = medium_unknown;
auto_etherwake = no;
ifaceid = ::;
type = neightype_unknown;
staticlease = no;
ipv4forwardrules =
"tcp 0.0.0.0:80 10.10.10.40:80 0 # busybox";
}
...
}
...unter den landevices.
Von Aussen könnten die Regeln angezeigt/angelegt/de/aktiviert/gelöscht werden,
wenn auf der Fritz!Box ein Webserver laufen würde mit z.B. Shellskript CGI.
Das Programm am End heisst ctlmgr_ctl und macht dass, was auch das Webinterface macht.
Ich bastel/lerne da grad was in der Richtung...
fb_fw.sh
Code:
#!/bin/sh
local FW_IP=${1}
local FW_PORT=${2}
local FW_PORT_ST=${3}
local FW_PORT_EN=${4}
local FW_PRT=${5}
local FW_DESCR=${6}
local FW_ACT=${7}
local NEWRULE=$(ctlmgr_ctl r forwardrules settings/rule/count)
fw_activate () {
if [ $# -eq 2 ] ; then
ctlmgr_ctl w forwardrules settings/rule${1}/activated ${2}
fi
}
fw_delete () {
if [ $# -eq 1 ] ; then
ctlmgr_ctl w forwardrules settings/rule${1}/fwip 0
fi
}
fw_status () {
local maxcount=$(ctlmgr_ctl r forwardrules settings/rule/count)
if [ ${maxcount} -gt 0 ] ; then
local count=0
while [ ${count} -lt ${maxcount} ] ; do
local FW_IP=$(ctlmgr_ctl r forwardrules settings/rule${count}/fwip)
local FW_PORT=$(ctlmgr_ctl r forwardrules settings/rule${count}/port)
local FW_PORT_ST=$(ctlmgr_ctl r forwardrules settings/rule${count}/fwport)
local FW_PORT_EN=$(ctlmgr_ctl r forwardrules settings/rule${count}/endport)
local FW_PRT=$(ctlmgr_ctl r forwardrules settings/rule${count}/protocol)
local FW_DESCR=$(ctlmgr_ctl r forwardrules settings/rule${count}/description)
local FW_ACT=$(ctlmgr_ctl r forwardrules settings/rule${count}/activated)
echo -ne ${FW_IP}\
', '\
${FW_PORT}\
' an '\
${FW_PORT_ST}\
' - '\
${FW_PORT_EN}\
', '\
${FW_PRT}\
', '\
${FW_DESCR}\
', '\
${FW_ACT}'\n'
: $((count++))
done
else
echo -ne 'No rules present!\n'
fi
}
if [ $# -eq 7 ] ; then
ctlmgr_ctl w forwardrules settings/rule${NEWRULE}/fwip ${FW_IP}
ctlmgr_ctl w forwardrules settings/rule${NEWRULE}/port ${FW_PORT}
ctlmgr_ctl w forwardrules settings/rule${NEWRULE}/fwport ${FW_PORT_ST}
ctlmgr_ctl w forwardrules settings/rule${NEWRULE}/endport ${FW_PORT_EN}
ctlmgr_ctl w forwardrules settings/rule${NEWRULE}/protocol ${FW_PRT}
ctlmgr_ctl w forwardrules settings/rule${NEWRULE}/description ${FW_DESCR}
fw_activate ${NEWRULE} ${FW_ACT}
else
case ${1} in
disable) fw_activate ${2} 0;;
enable) fw_activate ${2} 1;;
delete) fw_delete ${2};;
help) echo -ne $(basename ${0})\
': Need 7 arguments!\n'\
'[fwip] [port] [fwport] [endport] [protocol] [description] [activated]\n'\
'status for entries\n'\
'disable number or enable number enables or disable entry nummber\n'\
'(first entry is 0)\n'\
'and delete number is deleting entry number\n';;
status) echo -ne 'Rules:\n'
fw_status ;;
*) echo -ne $(basename ${0})': try help\n';;
esac
fi
#EOF
Aufruf:
Ohne Parameter:
help
Code:
fb_fw.sh help
fb_fw.sh: Need 7 arguments!
[fwip] [port] [fwport] [endport] [protocol] [description] [activated]
status for entries
disable number or enable number enables or disable entry nummber
(first entry is 0)
and delete number is deleting entry number
status (Beispielausgabe)
Code:
Rules:
10.10.10.40, 80 an 80 - 80, TCP, busybox, 1
...wurde angelegt mit: fb_fw.sh 10.10.10.40 80 80 80 TCP busybox 1
Ein CGI, dass dieses Skript aufruft, müsste die Parameter richtig parsen (QUERY_STRING) und richtig an dieses Skript übergeben.
Ganz grob, aber prinzipiell möglich...
/cgi-bin/index.cgi
Code:
#!/bin/sh
echo 'Content-Type: text/html; charset="utf-8"
'
echo '<!DOCTYPE html>
<html>
<head><title>Startseite: index.cgi</title></head>
<body><h1>Fritz!Box Portfreigaben</h1><p>
'$(./fb_fw.cgi ${QUERY_STRING})'
</p>
</body>
</html>
'
#EOF
(fb_fw.sh einfach umbenannt und ab ins /cgi-bin/ kopiert, also da wo die index.cgi liegt)
Die URL wird aufgerufen wie das Skript...
/cgi-bin/index.cgi?status
/cgi-bin/index.cgi?disable 0
/cgi-bin/index.cgi?enable 0
/cgi-bin/index.cgi?delete 0