Репозиторий Sisyphus
Последнее обновление: 1 октября 2023 | Пакетов: 18631 | Посещений: 37538229
en ru br
Репозитории ALT

Группа :: Система/Настройка/Прочее
Пакет: alterator-net-routing

 Главная   Изменения   Спек   Патчи   Исходники   Загрузить   Gear   Bugs and FR  Repocop 

alterator-net-routing-0.4.3/000075500000000000000000000000001214543077400157715ustar00rootroot00000000000000alterator-net-routing-0.4.3/Makefile000064400000000000000000000005411214543077400174310ustar00rootroot00000000000000NAME=net-routing
DESCRIPTION="Network Routing"

INSTALL=install

all:
install: install-module install-tools

include /usr/share/alterator/build/module.mak

install-tools:
for i in tools/*; do [ ! -d $$i ] || $(INSTALL) -Dpm 755 $$i/$${i##*/} $(bindir)/$${i##*/};done
for i in tools/*; do [ -d $$i ] || $(INSTALL) -Dpm 755 $$i $(bindir)/$${i##*/};done
alterator-net-routing-0.4.3/applications/000075500000000000000000000000001214543077400204575ustar00rootroot00000000000000alterator-net-routing-0.4.3/applications/net-routing.desktop000064400000000000000000000003411214543077400243230ustar00rootroot00000000000000[Desktop Entry]
Type=Application
Categories=X-Alterator-Network
Icon=net-routing
Terminal=false
X-Alterator-URI=/net-routing
X-Alterator-Weight=30
X-Alterator-Help=net-routing
Name=Routing
Name[ru]=п°п╟я─я┬я─я┐я┌п╦п╥п╟я├п╦я▐
alterator-net-routing-0.4.3/backend3/000075500000000000000000000000001214543077400174435ustar00rootroot00000000000000alterator-net-routing-0.4.3/backend3/net-routing000075500000000000000000000142771214543077400216570ustar00rootroot00000000000000#!/bin/sh


alterator_api_version=1
. alterator-sh-functions
. alterator-net-functions
SCRIPTDIR=/etc/net/scripts
. /etc/net/scripts/functions-ipv4

list_file="$(mktemp /var/cache/alterator/net_routing_XXXXXX)"
exit_handler() {
rm -f -- "$list_file"
}
trap "local rc=$?; trap - EXIT; exit_handler; exit $rc;"\
HUP PIPE INT QUIT TERM EXIT

list_ifaces()
{
local TYPE=
local HOST=
local NM_CONTROLLED=
local ignore=`echo -e "default\nunknown\nlo"`
ls -1 /etc/net/ifaces/*/options 2>/dev/null | \
while read iface_opts; do
TYPE=
HOST=
NM_CONTROLLED=
. $iface_opts
iface_name=${iface_opts%/*}; iface_name=${iface_name##*/};
# ignore bridge hosts
if [ "$TYPE" == "bri" -a -n "$HOST" ]; then
ignore+=`echo -e "\n$HOST"`
fi
# ignore networkmanager interfaces
if [ "$NM_CONTROLLED" == "true" -o "$NM_CONTROLLED" == "yes" -o "$NM_CONTROLLED" == "1" ]; then
ignore+=`echo -e "\n$iface_name"`
fi
if echo "$ignore" | grep -qe "^$iface_name$"; then
continue
fi
echo "$iface_name"
done
}

init_cache()
{
> "$list_file"
list_ifaces | \
while read iface_name; do
route_file="/etc/net/ifaces/$iface_name/ipv4route"
cat "$route_file" | sed "s|\(.*\)|$iface_name \1|" >> "$list_file"
done
}

do_reset(){
init_cache
}

view_system_route(){
ip route show
}

read_iface_route()
{
cat "$list_file"
}

make_route_line() {
local iface="$1"
local src_net="$2"
local src_mask="$3"
local dst_iface="$4"
local dst_ip="$5"
local metric="$6"

local str_src=
if [ -z "$src_net" ]; then
write_error "`_ "Invalid source network address:"`"
return
elif [ "$src_net" == "default" ]; then
str_src="default"
src_mask=
else
if ! echo "$src_net" | grep -q -E '^[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}$'; then
write_error "`_ "Invalid source network address:"` $src_net"
return
fi
fi

if [ "$src_net" != "default" ]; then
[ -n "$src_mask" ] \
|| src_mask=24
if ((src_mask<0 || src_mask>32)); then
write_error "`_ "Invalid source network mask:"` $src_mask"
return
fi
fi

[ -z "$src_net" -o -z "$src_mask" ] || str_src="${src_net}/${src_mask}"

local str_via_host="$dst_ip"
if [ -n "$dst_ip" ]; then
if ! echo "$dst_ip" | grep -q -E '^[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}$'; then
write_error "`_ "Invalid destination address:"` $dst_ip"
return
fi
fi
[ -z "$str_via_host" ] || str_via_host="via $str_via_host"

local str_dev_iface="$dst_iface"
[ -z "$str_dev_iface" ] || str_dev_iface="dev $dst_iface"
[ "$dst_iface" == "$iface" -a -n "$str_via_host" ] && str_dev_iface="" ||:

[ -n "$metric" ] || metric=0
if ! ((metric>=0 && metric<=255)) || ! echo "$metric"| grep -qe '^[[:digit:]][[:digit:]]*$'; then
write_error "`_ "Invalid metric:"` $metric"
return
fi
[ "$metric" != "0" ] || metric=
[ -z "$metric" ] || metric="metric $metric"

if [ -n "$iface" -a -n "$str_src" -a -n "$str_dev_iface$str_via_host" ]; then
echo "$iface $str_src $str_via_host $str_dev_iface $metric"
fi
}

add_route()
{
local routeline=$(make_route_line "$1" "$2" "$3" "$4" "$5" "$6")
[ -z "$routeline" ] \
|| echo "$routeline" >> "$list_file"
}

do_apply(){
local iface=
local routestr=
# clear routes
list_ifaces | \
while read iface
do
if [ -d "/etc/net/ifaces/$iface" ]; then
alterator-net-routing $iface del
> "/etc/net/ifaces/$iface/ipv4route"
fi
done
# write config
while read routeline
do
iface=`echo "$routeline" | sed 's|[[:space:]].*||'`
routestr=`echo "$routeline" | sed 's|^[[:alnum:]]*[[:space:]]*||'`
if [ -f "/etc/net/ifaces/$iface/ipv4route" ]; then
echo "$routestr" >> "/etc/net/ifaces/$iface/ipv4route"
fi
done < "$list_file"
# up routes
list_ifaces | \
while read routeline
do
iface=`echo "$routeline" | sed 's|[[:space:]].*||'`
alterator-net-routing $iface add
done
}

select_route() {
num="$1"
[ -n "$num" ] || num=1

strline=`head -n $num "$list_file" | tail -n 1`

str="$(echo "$strline"| sed 's|[[:space:]].*||')"
[ "$str" != "$strline" ] || str=
write_string_param "interface" "$str"

str="$(echo "$strline"| sed 's|.*[[:space:]]\([[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*\)/[[:digit:]]*[[:space:]].*|\1|')"
[ "$str" != "$strline" ] || str="default"
write_string_param "src_net" "$str"

str="$(echo "$strline"| sed 's|.*[[:space:]][[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*/\([[:digit:]]*\)[[:space:]].*|\1|')"
[ "$str" != "$strline" ] || str=
write_string_param "src_mask" "$str"

str="$(echo "$strline"| sed 's|.*[[:space:]]dev[[:space:]][[:space:]]*\([[:alnum:]][[:alnum:]]*\)[[:space:]]*.*|\1|')"
[ "$str" != "$strline" ] || str=
write_string_param "dst_interface" "$str"

str="$(echo "$strline"| sed 's|.*[[:space:]]via[[:space:]][[:space:]]*\([[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*\)[[:space:]]*.*|\1|')"
[ "$str" != "$strline" ] || str=
write_string_param "dst_ip" "$str"

str="$(echo "$strline"| sed 's|.*[[:space:]]metric[[:space:]][[:space:]]*\([[:digit:]][[:digit:]]*\)[[:space:]]*.*|\1|')"
[ "$str" != "$strline" ] || str="0"
write_string_param "metric" "$str"
}

change_route() {
local routeline=$(make_route_line "$1" "$2" "$3" "$4" "$5" "$6")
local setlist="$7"
[ -n "$setlist" ] || setlist=1

if [ -n "$routeline" ]; then
sed -i "${setlist} i\\${routeline}" "$list_file"
((setlist++))
sed -i "${setlist}d" "$list_file"
fi
}

# initialize
do_reset

on_message(){
case "$in_action" in
delete)
sed -i "${in_setlist}d" "$list_file" ;;
add)
add_route "$in_interface" "$in_src_net" "$in_src_mask" "$in_dst_interface" "$in_dst_ip" "$in_metric" ;;
select)
select_route "${in_setlist}" ;;
change)
change_route "$in_interface" "$in_src_net" "$in_src_mask" "$in_dst_interface" "$in_dst_ip" "$in_metric" "$in_setlist";;
apply)
do_apply ;;
reset)
do_reset ;;
routes)
read_iface_route | nl | write_enum ;;
list)
case "${in__objects##*/}" in
*) list_ifaces | write_enum ;;
esac
;;
read)
write_string_param view "$(view_system_route)" ;;
esac
}

message_loop
alterator-net-routing-0.4.3/tools/000075500000000000000000000000001214543077400171315ustar00rootroot00000000000000alterator-net-routing-0.4.3/tools/alterator-net-routing000075500000000000000000000010141214543077400233210ustar00rootroot00000000000000#!/bin/sh

usage()
{
echo 'alterator-net routing handler'
echo "Usage: $0 <interface> <add|del>" >&2
exit 1
}

[ $# -ge 2 ] || usage
NAME=$1

export NAME MYIFACEDIR=/etc/net/ifaces/$NAME SCRIPTDIR=/etc/net/scripts

. /etc/net/scripts/functions
pickup_defaults
pickup_options

ACTION=$2
case $ACTION in
add)
. $SCRIPTDIR/functions-ipv4
try_static && config_ipv4_routes_rules add
;;
del)
. $SCRIPTDIR/functions-ipv4
config_ipv4_routes_rules del
;;
*)
print_error "Illegal argument to $0: '$ACTION'"
;;
esac
alterator-net-routing-0.4.3/ui/000075500000000000000000000000001214543077400164065ustar00rootroot00000000000000alterator-net-routing-0.4.3/ui/net-routing/000075500000000000000000000000001214543077400206615ustar00rootroot00000000000000alterator-net-routing-0.4.3/ui/net-routing/ajax.scm000064400000000000000000000043011214543077400223060ustar00rootroot00000000000000(define-module (ui net-routing ajax)
:use-module (alterator str)
:use-module (alterator ajax)
:use-module (alterator woo)
:export (init))

(define (update-view)
(catch/message (lambda()
(form-update-value "view" (woo-get-option (woo-read-first "/net-routing") 'view)))))

(define (update-list)
(catch/message (lambda()
(form-update-enum "setlist"
(apply woo "routes" "/net-routing"
(form-value-list '("language")) )))))

(define (do_delete)
(catch/message (lambda()
(apply woo "delete" "/net-routing"
(form-value-list '("language" "setlist")) )))
(update-list))

(define (do_add)
(catch/message (lambda()
(apply woo "add" "/net-routing"
(form-value-list '("language" "interface" "src_net" "src_mask" "dst_interface" "dst_ip" "metric")) )))
(update-list))

(define (do_change)
(catch/message (lambda()
(apply woo "change" "/net-routing"
(form-value-list '("language" "interface" "src_net" "src_mask" "dst_interface" "dst_ip" "metric" "setlist")) )))
(update-list))

(define (do_apply)
(catch/message (lambda()
(apply woo "apply" "/net-routing"
(form-value-list '("language")) )))
(update-list)
(update-view)
)

(define (do_reset)
(catch/message (lambda()
(apply woo "reset" "/net-routing"
(form-value-list '("language")) )))
(update-list))

(define (on_select_route)
(catch/message (lambda()
(form-update-value-list '("interface" "src_net" "src_mask" "dst_interface" "dst_ip" "metric")
(apply woo "select" "/net-routing"
(form-value-list '("language" "setlist")) ))))
)

(define (init)
(do_reset)

(form-update-enum "interface" (woo-list "/net-routing/ifaces"))
(form-update-enum "src_mask" (woo-list "/net-eth/avail_masks"))
(form-update-value "src_mask" "24")
(form-update-enum "dst_interface" (woo-list "/net-routing/ifaces"))
;(form-update-value "metric" "0")

(form-bind "setlist" "click" on_select_route)

(form-bind "btn_view_update" "click" update-view)
(form-bind "btn_change" "click" do_change)

(form-bind "btn_delete" "click" do_delete)
(form-bind "btn_add" "click" do_add)
(form-bind "btn_apply" "click" do_apply)
(form-bind "btn_reset" "click" do_reset)
)

alterator-net-routing-0.4.3/ui/net-routing/index.html000064400000000000000000000042131214543077400226560ustar00rootroot00000000000000<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<!-- tcp connections module -->
<html wf="none">
<body>
<form method="POST">
<table>
<tr>
<th colspan="2"><span translate="_">View</span></th>
</tr>
<tr>
<td>
<textarea rows="10" readonly="yes" name="view" style="width:590px"/>
</td>
<td>
<input type="button" name="btn_view_update" value="Update" class="btn"/>
</td>
</tr>
<tr>
<th colspan="2"><span translate="_">Setup</span></th>
</tr>
<tr>
<td>
<select name="setlist" size="10" style="width:600px"/>
</td>
<td>
<input type="button" name="btn_delete" value="Delete" class="btn"/>
</td>
</tr>
<tr>
<th colspan="2"><span translate="_">Edit route</span></th>
</tr>
<tr>
<td colspan="2">
<table>
<tr>
<td><span translate="_">Interface:</span></td>
<td><select name="interface"/></td>
<td>&nbsp;</td>
<td><input type="button" name="btn_add" value="Add" class="btn"/></td>
</tr>
<tr>
<td><span translate="_">Source:</span></td>
<td><input type="text" class="text" name="src_net"/></td>
<td><select name="src_mask"/></td>
<td><input type="button" name="btn_change" value="Change" class="btn"/></td>
</tr>
<tr>
<td><span translate="_">Destination:</span></td>
<td><input type="text" class="text" name="dst_ip"/></td>
<td><select name="dst_interface"/></td>
<td>&nbsp;</td>
</tr>
<tr>
<td><span translate="_">Metric:</span></td>
<td><input type="text" maxlength="3" class="text" name="metric"/></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
</td>
</tr>
<tr>
<th colspan="2"><span translate="_">Conclusion</span></th>
</tr>
<tr>
<td colspan="2">
<input type="button" name="btn_apply" value="Apply" class="btn"/>
&nbsp;
<input type="button" name="btn_reset" value="Reset" class="btn"/>
</td>
</tr>
</table>
</form>
</body>
</html>
alterator-net-routing-0.4.3/ui/net-routing/index.scm000064400000000000000000000071461214543077400225040ustar00rootroot00000000000000(document:surround "/std/frame")

(gridbox margin 10
(gridbox columns "100;0;100" (separator)(label (_ "View"))(separator))

(gridbox columns "100;0"
(textbox name "view" rowspan 4 alterability #f)
(button text (_ "Update") name "btn_view_update")
)

(gridbox columns "100;0;100" (separator)(label (_ "Setup"))(separator))

(gridbox
(gridbox columns "100;0"
(listbox name "setlist" rowspan 4)
(button text (_ "Delete") name "btn_delete")
)
)

(gridbox columns "100;0;100" (separator)(label (_ "Edit route"))(separator))

(gridbox columns "25;50;25"
(label (_ "Interface:") align "right")
(gridbox columns "50;50"
(combobox name "interface")
(spacer)
)
(button text (_ "Add") name "btn_add" align "left")

(label (_ "Source:") align "right")
(gridbox columns "50;50"
(edit name "src_net")
(combobox name "src_mask")
)
(button text (_ "Change") name "btn_change" align "left")

(label (_ "Destination:") align "right")
(gridbox columns "50;50"
(edit name "dst_ip")
(combobox name "dst_interface")
)
(spacer)

(label (_ "Metric:") align "right")
(gridbox columns "50;50"
(spinbox name "metric" step 1 minimum 0 maximum 255)
)
(spacer)
)

(gridbox columns "100;0;100" (separator)(label (_ "Conclusion"))(separator))

(gridbox columns "100;0;0;100" margin 15 colspan 3
(spacer)
(button text (_ "Apply") name "btn_apply")
(button text (_ "Reset") name "btn_reset")
(spacer)
)
)

;;;;;;;;;;;;;;;; copy of ajax.scm

(define (update-view)
(catch/message (lambda()
(form-update-value "view" (woo-get-option (woo-read-first "/net-routing") 'view)))))

(define (update-list)
(catch/message (lambda()
(form-update-enum "setlist"
(apply woo "routes" "/net-routing"
(form-value-list '("language")) )))))

(define (do_delete)
(catch/message (lambda()
(apply woo "delete" "/net-routing"
(form-value-list '("language" "setlist")) )))
(update-list))

(define (do_add)
(catch/message (lambda()
(apply woo "add" "/net-routing"
(form-value-list '("language" "interface" "src_net" "src_mask" "dst_interface" "dst_ip" "metric")) )))
(update-list))

(define (do_change)
(catch/message (lambda()
(apply woo "change" "/net-routing"
(form-value-list '("language" "interface" "src_net" "src_mask" "dst_interface" "dst_ip" "metric" "setlist")) )))
(update-list))

(define (do_apply)
(catch/message (lambda()
(apply woo "apply" "/net-routing"
(form-value-list '("language")) )))
(update-list)
(update-view)
)

(define (do_reset)
(catch/message (lambda()
(apply woo "reset" "/net-routing"
(form-value-list '("language")) )))
(update-list))

(define (on_select_route)
(catch/message (lambda()
(form-update-value-list '("interface" "src_net" "src_mask" "dst_interface" "dst_ip" "metric")
(apply woo "select" "/net-routing"
(form-value-list '("language" "setlist")) ))))
)

(define (init)
(do_reset)

(form-update-enum "interface" (woo-list "/net-routing/ifaces"))
(form-update-enum "src_mask" (woo-list "/net-eth/avail_masks"))
(form-update-value "src_mask" "24")
(form-update-enum "dst_interface" (woo-list "/net-routing/ifaces"))
;(form-update-value "metric" "0")

(form-bind "setlist" "click" on_select_route)

(form-bind "btn_view_update" "click" update-view)
(form-bind "btn_change" "click" do_change)

(form-bind "btn_delete" "click" do_delete)
(form-bind "btn_add" "click" do_add)
(form-bind "btn_apply" "click" do_apply)
(form-bind "btn_reset" "click" do_reset)
)


(document:root (when loaded (init)))
 
дизайн и разработка: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
текущий майнтейнер: Michael Shigorin