Project

General

Profile

Download (8.81 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/* $Id$ */
4
/*
5
	services_usermanager.php
6
	part of m0n0wall (http://m0n0.ch/wall)
7

    
8
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
9
	All rights reserved.
10
	Copyright (C) 2005 Pascal Suter <d-pfsense-dev@psuter.ch>.
11
	All rights reserved.
12
	(files was created by Pascal based on the source code of services_captiveportal.php from Manuel)
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
$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
		$input_errors[] = "Username and password must not be empty!";
55
		$_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
<!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
<?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
  <tr><td class="tabnavtbl">
99
  <ul id="tabnav">
100
	<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
	<li class="tabact">User Manager</li>
104
  </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
                <tr>
117
                  <td width="22%" valign="top" class="vncellreq">Username</td>
118
                  <td width="78%" class="vtable">
119
                    <input name="username" type="text" class="formfld" id="username" size="20" value="<? echo $_GET['username']; ?>">
120
                    <br>
121
                    <span class="vexpl">Enter the desired username.</span></td>
122
                </tr>
123
                <tr>
124
                  <td width="22%" valign="top" class="vncellreq">Password</td>
125
                  <td width="78%" class="vtable">
126
                    <input name="password1" type="password" class="formfld" id="password1" size="20" value="<?php echo ($_GET['act']=='edit' ? "********" : "" ); ?>">
127
                    <br>
128
                    <span class="vexpl">Enter the desired password.</span></td>
129
                </tr>
130
                <tr>
131
                  <td width="22%" valign="top" class="vncellreq">Password confirmation</td>
132
                  <td width="78%" class="vtable">
133
                    <input name="password2" type="password" class="formfld" id="password2" size="20" value="<?php echo ($_GET['act']=='edit' ? "********" : "" ); ?>">
134
                    <br>
135
                    <span class="vexpl">Confirm the above password.</span></td>
136
                </tr>
137
                <tr>
138
                  <td width="22%" valign="top" class="vncell">Full name</td>
139
                  <td width="78%" class="vtable">
140
                    <input name="fullname" type="text" class="formfld" id="fullname" size="20" value="<? echo $user['fullname']; ?>">
141
                    <br>
142
                    Enter the user's full name.</td>
143
                </tr>
144
                <tr>
145
                  <td width="22%" valign="top" class="vncell">Expiration Date</td>
146
                  <td width="78%" class="vtable">
147
                    <input name="expirationdate" type="text" class="formfld" id="expirationdate" size="10" value="<? echo $user['expirationdate']; ?>">
148
                    <a href="javascript:NewCal('expirationdate','mmddyyyy')"><img src="cal.gif" width="16" height="16" border="0" alt="Pick a date"></a>
149
                    <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
                </tr>
151
                <tr>
152
                  <td width="22%" valign="top">&nbsp;</td>
153
                  <td width="78%">
154
                    <input name="save" type="submit" class="formbtn" value="Save">
155
                    <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
                     &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
		</tr>
187
<?php
188
		}
189
	}
190
	echo <<<END
191
		<tr>
192
                  <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

    
200
  </td>
201
  </tr>
202
  </table>
203
<?php include("fend.inc"); ?>
(81-81/109)