]>
Commit | Line | Data |
---|---|---|
e9ea243e MT |
1 | #!/bin/bash |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2010 Michael Tremer & Christian Schmidt # | |
6 | # # | |
7 | # This program is free software: you can redistribute it and/or modify # | |
8 | # it under the terms of the GNU General Public License as published by # | |
9 | # the Free Software Foundation, either version 3 of the License, or # | |
10 | # (at your option) any later version. # | |
11 | # # | |
12 | # This program is distributed in the hope that it will be useful, # | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
15 | # GNU General Public License for more details. # | |
16 | # # | |
17 | # You should have received a copy of the GNU General Public License # | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
19 | # # | |
20 | ############################################################################### | |
21 | ||
f41fa3d7 | 22 | . /usr/lib/network/header-config |
e9ea243e | 23 | |
b6d9bf2b | 24 | HOOK_CONFIG_SETTINGS="HOOK DELAY" |
e9ea243e MT |
25 | |
26 | # Default settings. | |
27 | DELAY=0 | |
28 | ||
b6d9bf2b | 29 | hook_check_config_settings() { |
e9ea243e MT |
30 | assert isset DELAY |
31 | assert isinteger DELAY | |
32 | } | |
33 | ||
b6d9bf2b MT |
34 | hook_new() { |
35 | local zone="${1}" | |
e9ea243e MT |
36 | shift |
37 | ||
38 | while [ $# -gt 0 ]; do | |
39 | case "${1}" in | |
40 | --delay=*) | |
b6d9bf2b | 41 | DELAY="$(cli_get_val "${1}")" |
e9ea243e MT |
42 | ;; |
43 | esac | |
44 | shift | |
45 | done | |
46 | ||
b6d9bf2b | 47 | zone_config_settings_write "${zone}" "${HOOK}" |
e9ea243e MT |
48 | |
49 | exit ${EXIT_OK} | |
50 | } | |
51 | ||
1c6a4e30 | 52 | hook_up() { |
e9ea243e MT |
53 | local zone=${1} |
54 | local config=${2} | |
55 | shift 2 | |
56 | ||
57 | if ! device_exists ${zone}; then | |
58 | error "Zone '${zone}' doesn't exist." | |
59 | exit ${EXIT_ERROR} | |
60 | fi | |
61 | ||
62 | # Start dhclient for IPv4 on this zone. | |
63 | dhclient_start ${zone} ipv4 | |
64 | ||
65 | exit ${EXIT_OK} | |
66 | } | |
67 | ||
1c6a4e30 | 68 | hook_down() { |
e9ea243e MT |
69 | local zone=${1} |
70 | local config=${2} | |
71 | shift 2 | |
72 | ||
73 | if ! device_exists ${zone}; then | |
74 | error "Zone '${zone}' doesn't exist." | |
75 | exit ${EXIT_ERROR} | |
76 | fi | |
77 | ||
78 | # Stop dhclient for IPv4 on this zone. | |
79 | dhclient_stop ${zone} ipv4 | |
80 | ||
81 | exit ${EXIT_OK} | |
82 | } | |
83 | ||
1c6a4e30 | 84 | hook_status() { |
e9ea243e MT |
85 | local zone=${1} |
86 | local config=${2} | |
87 | shift 2 | |
88 | ||
89 | if ! device_exists ${zone}; then | |
90 | error "Zone '${zone}' doesn't exist." | |
91 | exit ${EXIT_ERROR} | |
92 | fi | |
e9df08ad | 93 | |
b6d9bf2b | 94 | zone_config_settings_read "${zone}" "${config}" |
e9ea243e | 95 | |
8e3508ac MT |
96 | local status |
97 | if dhclient_status ${zone} ipv4; then | |
98 | status="${MSG_HOOK_UP}" | |
e9ea243e | 99 | else |
8e3508ac | 100 | status="${MSG_HOOK_DOWN}" |
e9ea243e | 101 | fi |
8e3508ac | 102 | cli_statusline 3 "${HOOK}" "${status}" |
e9ea243e | 103 | |
c041b631 MT |
104 | cli_print_fmt1 3 "IPv4 address" "$(db_get "${zone}/ipv4/local-ip-address")" |
105 | local gateway="$(db_get "${zone}/ipv4/remote-ip-address")" | |
8e3508ac MT |
106 | if isset gateway; then |
107 | cli_print_fmt1 3 "Gateway" "${gateway}" | |
ffea9f57 SS |
108 | cli_space |
109 | fi | |
110 | local dns_servers="$(db_get "${zone}/ipv4/domain-name-servers")" | |
111 | if isset dns_servers; then | |
112 | cli_print_fmt1 3 "DNS-Servers" "${dns_servers}" | |
113 | cli_space | |
e9ea243e MT |
114 | fi |
115 | ||
116 | exit ${EXIT_OK} | |
117 | } |