#!/bin/bash ############################################################################### # # # IPFire.org - A linux based firewall # # Copyright (C) 2010 Michael Tremer & Christian Schmidt # # # # This program is free software: you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # # the Free Software Foundation, either version 3 of the License, or # # (at your option) any later version. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program. If not, see . # # # ############################################################################### . /usr/lib/network/header-config HOOK_SETTINGS=( "DNS_SERVERS" "MTU" "SERVICE_NAME" "SUBNET MAX_SESSIONS" ) DEFAULT_MTU=1492 DEFAULT_MAX_SESSIONS=0 hook_check_config_settings() { assert isset MTU assert isset SUBNET assert isset MAX_SESSIONS local server for server in ${DNS_SERVERS}; do assert ipv4_is_valid "${server}" done } hook_parse_cmdline() { local id="${1}" shift while [ $# -gt 0 ]; do case "${1}" in --dns-server=*) local dns_servers="$(cli_get_val "${1}")" local dns_server for dns_server in ${dns_servers}; do if ! ipv4_is_valid "${dns_server}"; then warning "Invalid IPv4 address: ${dns_server}. Skipped." continue fi list_append DNS_SERVERS "${dns_server}" done ;; --max-sessions=*) MAX_SESSIONS=$(cli_get_val "${1}") if ! isinteger ${MAX_SESSIONS} || ! [ ${MAX_SESSIONS} -ge 0 ]; then error "Invalid value for '--max-session'. This value must be an integer greate or eqal zero." exit ${EXIT_ERROR} fi ;; --mtu=*) MTU=$(cli_get_val "${1}") if ! mtu_is_valid "ipv4" ${MTU}; then error "Invalid value for '--mtu'. Cannot be larger then 9000 or smaller than 576" exit ${EXIT_ERROR} fi ;; --service-name=*) SERVICE_NAME=$(cli_get_val "${1}") ;; --subnet=*) SUBNET=$(cli_get_val "${1}") if ! ipv4_net_is_valid "${SUBNET}"; then error "Invalid IPv4 Subnet ${SUBNET}." exit ${EXIT_ERROR} fi ;; *) warning "Ignoring unknown option '${1}'" ;; esac shift done } hook_up() { local zone=${1} local config=${2} shift 2 # Start the PPPoE server. pppoe_server_start ${zone} exit ${EXIT_OK} } hook_down() { local zone=${1} local config=${2} shift 2 if ! device_exists ${zone}; then error "Zone '${zone}' doesn't exist." exit ${EXIT_ERROR} fi # Stop the PPPoE server. pppoe_server_stop ${zone} exit ${EXIT_OK} } hook_status() { local zone=${1} local config=${2} shift 2 if ! device_exists ${zone}; then error "Zone '${zone}' doesn't exist." exit ${EXIT_ERROR} fi zone_config_settings_read "${zone}" "${config}" local status if pppoe_server_status ${zone}; then status="${MSG_HOOK_UP}" else status="${MSG_HOOK_DOWN}" fi cli_statusline 3 "PPPoE server" "${status}" local gateway=$(ipv4_get_network ${SUBNET}) cli_print_fmt1 3 "Gateway" "${gateway}" local start_address=$(ipv4_encode ${gateway}) start_address=$(( ${start_address} + 1 )) start_address=$(ipv4_decode ${start_address}) local end_address=$(ipv4_get_broadcast ${SUBNET}) cli_print_fmt1 3 "Client range" \ "${start_address}-${end_address}" cli_space local max_sessions=${MAX_SESSIONS} if [ "${max_sessions}" = "0" ]; then max_sessions="unlimited" fi cli_print_fmt1 3 "${max_sessions} session(s) per MAC" cli_space exit ${EXIT_OK} }