Project

General

Profile

Download (11.4 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	interfaces_ppp_edit.php
4
	part of pfSense(http://pfsense.org)
5

    
6
	Originally written by Adam Lebsack <adam at holonyx dot com>
7
	Changes by Chris Buechler <cmb at pfsense dot org> 
8
	Additions by Scott Ullrich <sullrich@pfsense.org>
9
	
10
	Copyright (C) 2004-2009 BSD Perimeter LLC.
11
	Copyright (C) 2009 Scott Ullrich
12
	All rights reserved.
13

    
14
	Redistribution and use in source and binary forms, with or without
15
	modification, are permitted provided that the following conditions are met:
16

    
17
	1. Redistributions of source code must retain the above copyright notice,
18
	   this list of conditions and the following disclaimer.
19

    
20
	2. Redistributions in binary form must reproduce the above copyright
21
	   notice, this list of conditions and the following disclaimer in the
22
	   documentation and/or other materials provided with the distribution.
23

    
24
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
25
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
26
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
28
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33
	POSSIBILITY OF SUCH DAMAGE.
34
*/
35
/*
36
	pfSense_MODULE:	interfaces
37
*/
38

    
39
##|+PRIV
40
##|*IDENT=page-interfaces-ppp-edit
41
##|*NAME=Interfaces: PPP: Edit page
42
##|*DESCR=Allow access to the 'Interfaces: PPP: Edit' page.
43
##|*MATCH=interfaces_ppp_edit.php*
44
##|-PRIV
45

    
46
require("guiconfig.inc");
47

    
48
if (!is_array($config['ppps']['ppp']))
49
	$config['ppps']['ppp'] = array();
50

    
51
$a_ppps = &$config['ppps']['ppp'];
52

    
53
$id = $_GET['id'];
54
if (isset($_POST['id']))
55
	$id = $_POST['id'];
56

    
57
if (isset($id) && $a_ppps[$id]) {
58
	$pconfig['port'] = $a_ppps[$id]['port'];
59
	$pconfig['initstr'] = base64_decode($a_ppps[$id]['initstr']);
60
	$pconfig['simpin'] = $a_ppps[$id]['simpin'];
61
	$pconfig['pin-wait'] = $a_ppps[$id]['pin-wait'];
62
	$pconfig['apn'] = $a_ppps[$id]['apn'];
63
	$pconfig['apnum'] = $a_ppps[$id]['apnum'];
64
	$pconfig['phone'] = $a_ppps[$id]['phone'];
65
	$pconfig['username'] = $a_ppps[$id]['username'];
66
	$pconfig['password'] = $a_ppps[$id]['password'];
67
	$pconfig['localip'] = $a_ppps[$id]['localip'];
68
	$pconfig['gateway'] = $a_ppps[$id]['gateway'];
69
	if (isset($a_ppps[$id]['defaultgw']))
70
		$pconfig['defaultgw'] = true;
71
	$pconfig['connect-timeout'] = $a_ppps[$id]['connect-timeout'];
72
	$pconfig['descr'] = $a_ppps[$id]['descr'];
73
}
74

    
75
if ($_POST) {
76

    
77
	unset($input_errors);
78
	$pconfig = $_POST;
79

    
80
	/* input validation */
81
	$reqdfields = explode(" ", "port");
82
	$reqdfieldsn = explode(",", "Serial Port");
83

    
84
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
85

    
86
	foreach ($a_ppps as $ppp) {
87
		if (isset($id) && ($a_ppps[$id]) && ($a_ppps[$id] === $ppp))
88
			continue;
89

    
90
		if ($ppp['port'] == $_POST['port']) {
91
			$input_errors[] = "Port is in use";
92
			break;
93
		}
94
	}
95

    
96
	if (!$input_errors) {
97
		$ppp = array();
98

    
99
		$ppp['port'] = $_POST['port'];
100
		if ($_POST['initstr'] <> "")
101
			$ppp['initstr'] = base64_encode($_POST['initstr']);
102
		else
103
			unset($ppp['initstr']);
104
			
105
		if ($_POST['simpin'] <> "") {
106
			$ppp['simpin'] = $_POST['simpin'];
107
			$ppp['pin-wait'] = $_POST['pin-wait'];
108
		} else {
109
			unset($ppp['simpin']);
110
			unset($ppp['pin-wait']);
111
		}
112
		
113
		$ppp['apn'] = $_POST['apn'];
114
		if ($ppp['apn'] <> ""){
115
			if ($_POST['apnum'] <> "")
116
				$ppp['apnum'] = $_POST['apnum'];
117
			else
118
				$ppp['apnum'] = "1";
119
		} else {
120
			unset($ppp['apn']);
121
			unset($ppp['apnum']);
122
		}
123
		
124
		$ppp['phone'] = $_POST['phone'];
125
		$ppp['username'] = $_POST['username'];
126
		$ppp['password'] = $_POST['password'];
127
		$ppp['localip'] = $_POST['localip'];
128
		$ppp['gateway'] = $_POST['gateway'];
129
		if ($_POST['defaultgw'] == "on")
130
			$ppp['defaultgw'] = true;
131
		else
132
			unset($ppp['defaultgw']);
133
		if ($_POST['connect-timeout'] <> "")
134
			$ppp['connect-timeout'] = $_POST['connect-timeout'];
135
		else
136
			unset($ppp['connect-timeout']);
137
		$ppp['descr'] = $_POST['descr'];
138

    
139
        $iflist = get_configured_interface_list();
140
        foreach ($iflist as $if) {
141
        	if ($config['interfaces'][$if]['if'] == basename($a_ppps[$id]['port'])) {
142
				$config['interfaces'][$if]['if'] = basename($ppp['port']);
143
				$thisif = $if;
144
			}
145
		}
146
		if (isset($id) && $a_ppps[$id])
147
			$a_ppps[$id] = $ppp;
148
		else
149
			$a_ppps[] = $ppp;
150
			
151
		write_config();
152
		if (!empty($thisif))
153
			interface_ppp_configure($thisif);
154

    
155
		header("Location: interfaces_ppp.php");
156
		exit;
157
	}
158
}
159

    
160
$pgtitle = "Interfaces: PPP: Edit";
161
include("head.inc");
162

    
163
?>
164

    
165
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
166
<?php include("fbegin.inc"); ?>
167
<?php if ($input_errors) print_input_errors($input_errors); ?>
168
<form action="interfaces_ppp_edit.php" method="post" name="iform" id="iform">
169
	<script src="/javascript/scriptaculous/prototype.js" type="text/javascript">
170
	</script>
171
	<script type="text/javascript">
172
	function prefill_att() {
173
		$('initstr').value = "Q0V1E1S0=0&C1&D2+FCLASS=0";
174
		$('apn').value = "ISP.CINGULAR";
175
		$('apnum').value = "1";
176
		$('phone').value = "*99#";
177
		$('username').value = "att";
178
		$('password').value = "att";
179
	}
180
	function prefill_sprint() {
181
		$('initstr').value = "E1Q0";
182
		$('apn').value = "";
183
		$('apnum').value = "";
184
		$('phone').value = "#777";
185
		$('username').value = "sprint";
186
		$('password').value = "sprint";
187
	}
188
	function prefill_vzw() {
189
		$('initstr').value = "E1Q0s7=60";
190
		$('apn').value = "";
191
		$('apnum').value = "";
192
		$('phone').value = "#777";
193
		$('username').value = "123@vzw3g.com";
194
		$('password').value = "vzw";
195
	}
196
	</script>
197
	<table width="100%" border="0" cellpadding="6" cellspacing="0">
198
		<tr>
199
			<td colspan="2" valign="top" class="listtopic">PPP configuration</td>
200
		</tr>
201
		<tr>
202
			<td width="22%" valign="top" class="vncellreq">Parent interface</td>
203
			<td width="78%" class="vtable">
204
				<select name="port" id="port" class="formselect">
205
				<?php
206
					$portlist = glob("/dev/cua*");
207
					$modems = glob("/dev/modem*");
208
					$portlist = array_merge($portlist, $modems);
209
					foreach ($portlist as $port) {
210
						if(preg_match("/\.(lock|init)$/", $port))
211
							continue;
212
						echo "<option value=\"".trim($port)."\"";
213
						if ($pconfig['port'] == $port)
214
							echo "selected";
215
						echo ">{$port}</option>";
216
					}
217
				?>
218
				</select>
219
				<p/>
220
				Pre-fill connection information: 
221
				<a href='#' onClick='javascript:prefill_att();'>ATT</A>
222
				<a href='#' onClick='javascript:prefill_sprint();'>Sprint</A>
223
				<a href='#' onClick='javascript:prefill_vzw();'>Verizon</A>
224
			</td>
225
		</tr>
226
		<tr>
227
			<td width="22%" valign="top" class="vncell">Link Type</td>
228
			<td width="78%" class="vtable">
229
				<input type="checkbox" value="on" id="defaultgw" name="defaultgw" <?php if (isset($pconfig['defaultgw'])) echo "checked"; ?>>This link will be used as the default gateway.
230
			</td>
231
		</tr>
232
		<tr>
233
			<td width="22%" valign="top" class="vncell">Init String</td>
234
			<td width="78%" class="vtable">
235
				<input type="text" size="40" class="formfld unknown" id="initstr" name="initstr" value="<?=htmlspecialchars($pconfig['initstr']);?>">
236
				<br><span class="vexpl">Note: Enter the modem initialization string here. Do NOT include the "AT" string at the beginning of the command.</span>
237
			</td>
238
		</tr>
239
 		<tr>
240
 		  <td width="22%" valign="top" class="vncell">Sim PIN</td>
241
 		  <td width="78%" class="vtable">
242
 		    <input name="simpin" type="text" class="formfld unknown" id="simpin" size="12" value="<?=htmlspecialchars($pconfig['simpin']);?>">
243
 		</td>
244
 		</tr>
245
  		<tr>
246
 		  <td width="22%" valign="top" class="vncell">Sim PIN wait</td>
247
 		  <td width="78%" class="vtable">
248
 		    <input name="pin-wait" type="text" class="formfld unknown" id="pin-wait" size="2" value="<?=htmlspecialchars($pconfig['pin-wait']);?>">
249
 		    <br><span class="vexpl">Note: Time to wait for SIM to discover network after PIN is sent to SIM (seconds).</span>
250
 		</td>
251
 		</tr>
252
 		<tr>
253
 		  <td width="22%" valign="top" class="vncell">Access Point Name (APN)</td>
254
 		  <td width="78%" class="vtable">
255
 		    <input name="apn" type="text" class="formfld unknown" id="apn" size="40" value="<?=htmlspecialchars($pconfig['apn']);?>">
256
 		</td>
257
 		</tr>
258
 		<tr>
259
 		  <td width="22%" valign="top" class="vncell">APN number (optional)</td>
260
 		  <td width="78%" class="vtable">
261
 		    <input name="apnum" type="text" class="formfld unknown" id="apnum" size="2" value="<?=htmlspecialchars($pconfig['apnum']);?>">
262
 		    <br><span class="vexpl">Note: Defaults to 1 if you set APN above. Ignored if you set no APN above.</span>
263
 		</td>
264
 		</tr>
265
 		<tr>
266
 		  <td width="22%" valign="top" class="vncell">Phone Number</td>
267
 		  <td width="78%" class="vtable">
268
 		    <input name="phone" type="text" class="formfld unknown" id="phone" size="40" value="<?=htmlspecialchars($pconfig['phone']);?>">
269
 		    <br><span class="vexpl">Note: Typically (*99# or *99***# or *99***1#) for GSM networks and *777 for CDMA networks</span>
270
 		  </td>
271
 		</tr>
272
		<tr>
273
			<td width="22%" valign="top" class="vncell">Username</td>
274
			<td width="78%" class="vtable">
275
				<input name="username" type="text" class="formfld user" id="username" size="20" value="<?=htmlspecialchars($pconfig['username']);?>">
276
			</td>
277
		</tr>
278
		<tr>
279
			<td width="22%" valign="top" class="vncell">Password</td>
280
			<td width="78%" class="vtable">
281
				<input name="password" type="password" class="formfld pwd" id="password" value="<?=htmlspecialchars($pconfig['password']);?>">
282
			</td>
283
		</tr>
284
 		<tr>
285
 		  <td width="22%" valign="top" class="vncell">Local IP</td>
286
 		  <td width="78%" class="vtable">
287
			<input name="localip" type="text" class="formfld unknown" id="localip" size="40" value="<?=htmlspecialchars($pconfig['localip']);?>">
288
			<br><span class="vexpl">Note: Enter your IP address here if it is not automatically assigned.</span>
289
 		  </td>
290
		</tr>
291
		<tr>
292
			<td width="22%" valign="top" class="vncell">Remote IP (Gateway)</td>
293
			<td width="78%" class="vtable">
294
				<input name="gateway" type="text" class="formfld unknown" id="gateway" size="40" value="<?=htmlspecialchars($pconfig['gateway']);?>">
295
				<br><span class="vexpl">Note: Enter the remote IP here if not automatically assigned. This is where the packets will be routed.</span>
296
			</td>
297
		</tr>
298
		<tr>
299
		<tr>
300
			<td width="22%" valign="top" class="vncell">Connection Timeout</td>
301
			<td width="78%" class="vtable">
302
				<input name="connect-timeout" type="text" class="formfld unknown" id="connect-timeout" size="2" value="<?=htmlspecialchars($pconfig['connect-timeout']);?>">
303
				<br><span class="vexpl">Note: Enter timeout in seconds for connection to be established (sec.) Default is 45 sec.</span>
304
			</td>
305
		</tr>
306
		<tr>
307
			<td width="22%" valign="top" class="vncell">Description</td>
308
			<td width="78%" class="vtable">
309
				<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
310
				<br><span class="vexpl">You may enter a description here for your reference (not parsed).</span>
311
			</td>
312
		</tr>
313
		<tr>
314
			<td width="22%" valign="top">&nbsp;</td>
315
			<td width="78%">
316
				<input name="Submit" type="submit" class="formbtn" value="Save"> 
317
				<input type="button" value="Cancel" onclick="history.back()">
318
				<?php if (isset($id) && $a_ppps[$id]): ?>
319
					<input name="id" type="hidden" value="<?=$id;?>">
320
				<?php endif; ?>
321
			</td>
322
		</tr>
323
	</table>
324
</form>
325
<?php include("fend.inc"); ?>
326
</body>
327
</html>
(91-91/216)