Project

General

Profile

Download (8.81 KB) Statistics
| Branch: | Tag: | Revision:
1 9699028a Scott Ullrich
#!/usr/local/bin/php
2 3d8deb41 Scott Ullrich
<?php
3 b46bfcf5 Bill Marquette
/* $Id$ */
4 9699028a Scott Ullrich
/*
5
	services_usermanager.php
6
	part of m0n0wall (http://m0n0.ch/wall)
7 3d8deb41 Scott Ullrich
8 9699028a Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
9
	All rights reserved.
10 3f345054 Scott Ullrich
	Copyright (C) 2005 Pascal Suter <d-pfsense-dev@psuter.ch>.
11 3d8deb41 Scott Ullrich
	All rights reserved.
12 9699028a Scott Ullrich
	(files was created by Pascal based on the source code of services_captiveportal.php from Manuel)
13 3d8deb41 Scott Ullrich
14 9699028a Scott Ullrich
	Redistribution and use in source and binary forms, with or without
15
	modification, are permitted provided that the following conditions are met:
16 3d8deb41 Scott Ullrich
17 9699028a Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
18
	   this list of conditions and the following disclaimer.
19 3d8deb41 Scott Ullrich
20 9699028a Scott Ullrich
	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 3d8deb41 Scott Ullrich
24 9699028a Scott Ullrich
	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
$pgtitle = array("Services", "Usermanager");
36
require("guiconfig.inc");
37
if(isset($_POST['save'])){
38
	$_POST['username']=trim($_POST['username']);
39
	if($_POST['old_username']!="" && $_POST['old_username']!=$_POST['username']){
40
		$config['users'][$_POST['username']]=$config['users'][$_POST['old_username']];
41
		unset($config['users'][$_POST['old_username']]);
42
	}
43
	foreach(Array('fullname','expirationdate') as $field){
44
		$config['users'][$_POST['username']][$field]=trim($_POST[$field]);
45
	}
46
	if(trim($_POST['password1'])!="********" && trim($_POST['password1'])!=""){
47
		if(trim($_POST['password1'])==trim($_POST['password2'])){
48
			$config['users'][$_POST['username']]['password']=md5(trim($_POST['password1']));
49
		} else {
50
			$input_errors[]="passwords did not match --> password was not changed!";
51
		}
52
	}
53
	if($_POST['username']=="" || trim($_POST['password1'])==""){
54 5bc18ff3 Colin Smith
		$input_errors[] = "Username and password must not be empty!";
55 9699028a Scott Ullrich
		$_GET['act']="new";
56
	} else {
57
		write_config();
58
		$savemsg=$_POST['username']." successfully saved<br>";
59
	}
60
} else if ($_GET['act']=="delete" && isset($_GET['username'])){
61
	unset($config['users'][$_GET['username']]);
62
	write_config();
63
	$savemsg=$_GET['username']." successfully deleted<br>";
64
}
65
//erase expired accounts
66
$changed=false;
67
if(is_array($config['users'])){
68
	foreach($config['users'] as $username => $user){
69
		if(trim($user['expirationdate'])!="" && strtotime("-1 day")>strtotime($user['expirationdate'])){
70
			unset($config['users'][$username]);
71
			$changed=true;
72
			$savemsg.="$username has expired --> $username was deleted<br>";
73
		}
74
	}
75
	if($changed){
76
		write_config();
77
	}
78
}
79
80
?>
81 3d8deb41 Scott Ullrich
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
82
<html>
83
<head>
84
<title><?=gentitle("pfSense webGUI");?></title>
85
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
86
<link href="gui.css" rel="stylesheet" type="text/css">
87
</head>
88
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
89 9699028a Scott Ullrich
<?php include("fbegin.inc"); ?>
90
<script language="javascript" type="text/javascript" src="datetimepicker.js">
91
//Date Time Picker script- by TengYong Ng of http://www.rainforestnet.com
92
//Script featured on JavaScript Kit (http://www.javascriptkit.com)
93
//For this script, visit http://www.javascriptkit.com
94
</script>
95
<?php if ($input_errors) print_input_errors($input_errors); ?>
96
<?php if ($savemsg) print_info_box($savemsg); ?>
97
<table width="100%" border="0" cellpadding="0" cellspacing="0">
98 2d6c7764 Scott Ullrich
  <tr><td class="tabnavtbl">
99 9699028a Scott Ullrich
  <ul id="tabnav">
100 2d6c7764 Scott Ullrich
	<li class="tabinact1"><a href="services_captiveportal.php">Captive portal</a></li>
101
	<li class="tabinact"><a href="services_captiveportal_mac.php">Pass-through MAC</a></li>
102
	<li class="tabinact"><a href="services_captiveportal_ip.php">Allowed IP addresses</a></li>
103 12bd7e25 Scott Ullrich
	<li class="tabact">User Manager</li>
104 9699028a Scott Ullrich
  </ul>
105
  </td></tr>
106
  <tr>
107
  <td class="tabcont">
108
<?php
109
if($_GET['act']=="new" || $_GET['act']=="edit"){
110
	if($_GET['act']=="edit" && isset($_GET['username'])){
111
		$user=$config['users'][$_GET['username']];
112
	}
113
?>
114
	<form action="services_usermanager.php" method="post" name="iform" id="iform">
115
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
116 3d8deb41 Scott Ullrich
                <tr>
117 9699028a Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">Username</td>
118 3d8deb41 Scott Ullrich
                  <td width="78%" class="vtable">
119
                    <input name="username" type="text" class="formfld" id="username" size="20" value="<? echo $_GET['username']; ?>">
120 9699028a Scott Ullrich
                    <br>
121 5bc18ff3 Colin Smith
                    <span class="vexpl">Enter the desired username.</span></td>
122 9699028a Scott Ullrich
                </tr>
123 3d8deb41 Scott Ullrich
                <tr>
124 9699028a Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">Password</td>
125 3d8deb41 Scott Ullrich
                  <td width="78%" class="vtable">
126
                    <input name="password1" type="password" class="formfld" id="password1" size="20" value="<?php echo ($_GET['act']=='edit' ? "********" : "" ); ?>">
127 9699028a Scott Ullrich
                    <br>
128 5bc18ff3 Colin Smith
                    <span class="vexpl">Enter the desired password.</span></td>
129 9699028a Scott Ullrich
                </tr>
130 3d8deb41 Scott Ullrich
                <tr>
131 5bc18ff3 Colin Smith
                  <td width="22%" valign="top" class="vncellreq">Password confirmation</td>
132 3d8deb41 Scott Ullrich
                  <td width="78%" class="vtable">
133
                    <input name="password2" type="password" class="formfld" id="password2" size="20" value="<?php echo ($_GET['act']=='edit' ? "********" : "" ); ?>">
134 9699028a Scott Ullrich
                    <br>
135 5bc18ff3 Colin Smith
                    <span class="vexpl">Confirm the above password.</span></td>
136 9699028a Scott Ullrich
                </tr>
137 3d8deb41 Scott Ullrich
                <tr>
138 5bc18ff3 Colin Smith
                  <td width="22%" valign="top" class="vncell">Full name</td>
139 3d8deb41 Scott Ullrich
                  <td width="78%" class="vtable">
140 9699028a Scott Ullrich
                    <input name="fullname" type="text" class="formfld" id="fullname" size="20" value="<? echo $user['fullname']; ?>">
141
                    <br>
142 5bc18ff3 Colin Smith
                    Enter the user's full name.</td>
143 9699028a Scott Ullrich
                </tr>
144 3d8deb41 Scott Ullrich
                <tr>
145 9699028a Scott Ullrich
                  <td width="22%" valign="top" class="vncell">Expiration Date</td>
146 3d8deb41 Scott Ullrich
                  <td width="78%" class="vtable">
147 9699028a Scott Ullrich
                    <input name="expirationdate" type="text" class="formfld" id="expirationdate" size="10" value="<? echo $user['expirationdate']; ?>">
148 3d8deb41 Scott Ullrich
                    <a href="javascript:NewCal('expirationdate','mmddyyyy')"><img src="cal.gif" width="16" height="16" border="0" alt="Pick a date"></a>
149 5bc18ff3 Colin Smith
                    <br> <span class="vexpl">Enter this acocunt's expiration date in us-format (mm/dd/yyyy) or leave this field empty for no expiration.</span></td>
150 9699028a Scott Ullrich
                </tr>
151 3d8deb41 Scott Ullrich
                <tr>
152 9699028a Scott Ullrich
                  <td width="22%" valign="top">&nbsp;</td>
153 3d8deb41 Scott Ullrich
                  <td width="78%">
154
                    <input name="save" type="submit" class="formbtn" value="Save">
155 9699028a Scott Ullrich
                    <input name="old_username" type="hidden" value="<? echo $_GET['username'];?>">
156
                  </td>
157
                </tr>
158
              </table>
159
     </form>
160
<?php
161
} else {
162
	echo <<<END
163
     <table width="100%" border="0" cellpadding="0" cellspacing="0">
164
                <tr>
165
                  <td width="35%" class="listhdrr">Username</td>
166
                  <td width="20%" class="listhdrr">Full Name</td>
167
                  <td width="35%" class="listhdr">Expires</td>
168
                  <td width="10%" class="list"></td>
169
		</tr>
170
END;
171
	if(is_array($config['users'])){
172
		foreach($config['users'] as $username => $user){
173
?>
174
		<tr>
175
                  <td class="listlr">
176
                    <?php echo $username; ?>&nbsp;
177
                  </td>
178
                  <td class="listr">
179
                    <?php echo $user['fullname']; ?>&nbsp;
180
                  </td>
181
                  <td class="listbg">
182
                    <?php echo $user['expirationdate']; ?>&nbsp;
183
                  </td>
184
                  <td valign="middle" nowrap class="list"> <a href="services_usermanager.php?act=edit&username=<?php echo $username; ?>"><img src="e.gif" width="17" height="17" border="0"></a>
185 5bc18ff3 Colin Smith
                     &nbsp;<a href="services_usermanager.php?act=delete&username=<?php echo $username; ?>" onclick="return confirm('Do you really want to delete this user?')"><img src="x.gif" width="17" height="17" border="0"></a></td>
186 9699028a Scott Ullrich
		</tr>
187
<?php
188
		}
189
	}
190
	echo <<<END
191 3d8deb41 Scott Ullrich
		<tr>
192 9699028a Scott Ullrich
                  <td class="list" colspan="3"></td>
193
                  <td class="list"> <a href="services_usermanager.php?act=new"><img src="plus.gif" width="17" height="17" border="0"></a></td>
194
	        </tr>
195
     </table>
196
END;
197
}
198
?>
199 3d8deb41 Scott Ullrich
200 9699028a Scott Ullrich
  </td>
201
  </tr>
202
  </table>
203
<?php include("fend.inc"); ?>