Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- #
- usage()
- {
- cat << EOF
- Usage: $0 [ <ip> ] [ <nextmark> ] [ <switch_addr> ] [ <switch_port> ] [ <id_tariff> ]
- <ip> - 192.168.x.x
- <nextmark> - iptables MARK
- <switch_addr> - switch address
- <switch_port> - switch port
- <tariff_id> - 1-100
- EOF
- }
- function valid_ip()
- {
- local ip=$1
- local stat=1
- if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
- OIFS=$IFS
- IFS='.'
- ip=($ip)
- IFS=$OIFS
- [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
- && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
- stat=$?
- fi
- return $stat
- }
- if [ $# -ne 5 ]; then
- usage
- exit 1
- else
- # Правила для маркировки адреса
- iptables -t mangle -A PREROUTING -s $ip -j MARK --set-mark $nextmark
- iptables -t mangle -A PREROUTING -s $ip -j RETURN
- # В данную переменную мы пишем строку конфига DHCP с учетом адреса юзера ($ip), адреса агента ($switch_addr) и порта агента ($switch_port)
- dhcp='class "'$switch_addr'_'$switch_port'{ match if (binary-to-ascii(10,8,"",suffix(option agent.circuit-id,1)) ="'$switch_port'") and binary-to-ascii(10,8,".",packet(24,4))="'$switch_addr'";} pool { range '$ip'; allow members of"'$switch_addr'_'$switch_port'";}'
- # Пишем конфиг ДХЦП в соответствующий файл
- echo $dhcp >/etc/dhcp/$switch_addr'_'$switch_port'.cfg'
- # Рестартим ДХЦП
- /etc/init.d/isc-dhcp-server restart
- # Включаем интернет пользователю
- iptables -t nat -A POSTROUTING -s $ip -o eth0 -j MASQUERADE
- fi
- exit 1
- fi
- # TODO:
- # Добавление юзера на порт
- # Конфиги свичей не правятся,изменения вносятся по telnet, и сразу конфиг выгружается по tftp
- # Напомню админу, что access_profile profile_id 2 access_id всегда равен номеру порта свича
- # соответственно и profile_id 3 аналогично. НЕ ВНОСИТЬ ИЗМЕНЕНИЙ В profile_id 1 блять!!!
- # Создаем telnet-сессию со свичом
Add Comment
Please, Sign In to add comment