Project

General

Profile

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

    
7
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9
	Copyright (C) 2005 Pascal Suter <d-pfsense-dev@psuter.ch>.
10
	All rights reserved.
11
	(files was created by Pascal based on the source code of services_captiveportal.php from Manuel)
12

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

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

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

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

    
35
##|+PRIV
36
##|*IDENT=page-services-usermanager
37
##|*NAME=Services: User Manager page
38
##|*DESCR=Allow access to the 'Services: User Manager' page.
39
##|*MATCH=services_usermanager.php*
40
##|-PRIV
41

    
42
require("guiconfig.inc");
43
if(isset($_POST['save'])){
44
	$_POST['username']=trim($_POST['username']);
45
	if($_POST['old_username']!="" && $_POST['old_username']!=$_POST['username']){
46
		$config['users'][$_POST['username']]=$config['users'][$_POST['old_username']];
47
		unset($config['users'][$_POST['old_username']]);
48
	}
49
	foreach(Array('fullname','expirationdate') as $field){
50
		$config['users'][$_POST['username']][$field]=trim($_POST[$field]);
51
	}
52
	if(trim($_POST['password1'])!="********" && trim($_POST['password1'])!=""){
53
		if(trim($_POST['password1'])==trim($_POST['password2'])){
54
			$config['users'][$_POST['username']]['password']=md5(trim($_POST['password1']));
55
		} else {
56
			$input_errors[]="passwords did not match --> password was not changed!";
57
		}
58
	}
59
	if($_POST['username']=="" || trim($_POST['password1'])==""){
60
		$input_errors[] = "Username and password must not be empty!";
61
		$_GET['act']="new";
62
	} else {
63
		write_config();
64
		$savemsg=$_POST['username']." successfully saved<br>";
65
	}
66
} else if ($_GET['act']=="delete" && isset($_GET['username'])){
67
	unset($config['users'][$_GET['username']]);
68
	write_config();
69
	$savemsg=$_GET['username']." successfully deleted<br>";
70
}
71
//erase expired accounts
72
$changed=false;
73
if(is_array($config['users'])){
74
	foreach($config['users'] as $username => $user){
75
		if(trim($user['expirationdate'])!="" && strtotime("-1 day")>strtotime($user['expirationdate'])){
76
			unset($config['users'][$username]);
77
			$changed=true;
78
			$savemsg.="$username has expired --> $username was deleted<br>";
79
		}
80
	}
81
	if($changed){
82
		write_config();
83
	}
84
}
85

    
86
$pgtitle = array("Services","User Manager");
87
include("head.inc");
88

    
89
?>
90

    
91
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
92
<?php include("fbegin.inc"); ?>
93
<script language="javascript" type="text/javascript" src="/javascript/datetimepicker.js">
94
//Date Time Picker script- by TengYong Ng of http://www.rainforestnet.com
95
//Script featured on JavaScript Kit (http://www.javascriptkit.com)
96
//For this script, visit http://www.javascriptkit.com
97
</script>
98
<?php if ($input_errors) print_input_errors($input_errors); ?>
99
<?php if ($savemsg) print_info_box($savemsg); ?>
100
<table width="100%" border="0" cellpadding="0" cellspacing="0">
101
  <tr><td class="tabnavtbl">
102
  <ul id="tabnav">
103
	<li class="tabinact1"><a href="services_captiveportal.php">Captive portal</a></li>
104
	<li class="tabinact"><a href="services_captiveportal_mac.php">Pass-through MAC</a></li>
105
	<li class="tabinact"><a href="services_captiveportal_ip.php">Allowed IP addresses</a></li>
106
	<li class="tabact">User Manager</li>
107
  </ul>
108
  </td></tr>
109
  <tr>
110
  <td class="tabcont">
111
<?php
112
if($_GET['act']=="new" || $_GET['act']=="edit"){
113
	if($_GET['act']=="edit" && isset($_GET['username'])){
114
		$user=$config['users'][$_GET['username']];
115
	}
116
?>
117
	<form action="services_usermanager.php" method="post" name="iform" id="iform">
118
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
119
                <tr>
120
                  <td width="22%" valign="top" class="vncellreq">Username</td>
121
                  <td width="78%" class="vtable">
122
                    <input name="username" type="text" class="formfld user" id="username" size="20" value="<? echo $_GET['username']; ?>">
123
                    <br>
124
                    <span class="vexpl">Enter the desired username.</span></td>
125
                </tr>
126
                <tr>
127
                  <td width="22%" valign="top" class="vncellreq">Password</td>
128
                  <td width="78%" class="vtable">
129
                    <input name="password1" type="password" class="formfld pwd" id="password1" size="20" value="<?php echo ($_GET['act']=='edit' ? "********" : "" ); ?>">
130
                    <br>
131
                    <span class="vexpl">Enter the desired password.</span></td>
132
                </tr>
133
                <tr>
134
                  <td width="22%" valign="top" class="vncellreq">Password confirmation</td>
135
                  <td width="78%" class="vtable">
136
                    <input name="password2" type="password" class="formfld pwd" id="password2" size="20" value="<?php echo ($_GET['act']=='edit' ? "********" : "" ); ?>">
137
                    <br>
138
                    <span class="vexpl">Confirm the above password.</span></td>
139
                </tr>
140
                <tr>
141
                  <td width="22%" valign="top" class="vncell">Full name</td>
142
                  <td width="78%" class="vtable">
143
                    <input name="fullname" type="text" class="formfld unknown" id="fullname" size="20" value="<? echo $user['fullname']; ?>">
144
                    <br>
145
                    Enter the user's full name.</td>
146
                </tr>
147
                <tr>
148
                  <td width="22%" valign="top" class="vncell">Expiration Date</td>
149
                  <td width="78%" class="vtable">
150
                    <input name="expirationdate" type="text" class="formfld unknown" id="expirationdate" size="10" value="<? echo $user['expirationdate']; ?>">
151
                    <a href="javascript:NewCal('expirationdate','mmddyyyy')"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_cal.gif" width="16" height="16" border="0" alt="Pick a date"></a>
152
                    <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>
153
                </tr>
154
                <tr>
155
                  <td width="22%" valign="top">&nbsp;</td>
156
                  <td width="78%">
157
                    <input name="save" type="submit" class="formbtn" value="Save">
158
                    <input name="old_username" type="hidden" value="<? echo $_GET['username'];?>">
159
                  </td>
160
                </tr>
161
              </table>
162
     </form>
163
<?php
164
} else {
165
	echo <<<END
166
     <table width="100%" border="0" cellpadding="0" cellspacing="0">
167
                <tr>
168
                  <td width="35%" class="listhdrr">Username</td>
169
                  <td width="20%" class="listhdrr">Full Name</td>
170
                  <td width="35%" class="listhdr">Expires</td>
171
                  <td width="10%" class="list"></td>
172
		</tr>
173
END;
174
	if(is_array($config['users'])){
175
		foreach($config['users'] as $username => $user){
176
?>
177
		<tr>
178
                  <td class="listlr">
179
                    <?php echo $username; ?>&nbsp;
180
                  </td>
181
                  <td class="listr">
182
                    <?php echo $user['fullname']; ?>&nbsp;
183
                  </td>
184
                  <td class="listbg">
185
                    <?php echo $user['expirationdate']; ?>&nbsp;
186
                  </td>
187
                  <td valign="middle" nowrap class="list"> <a href="services_usermanager.php?act=edit&username=<?php echo $username; ?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0"></a>
188
                     &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="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0"></a></td>
189
		</tr>
190
<?php
191
		}
192
	}
193
	echo <<<END
194
		<tr>
195
                  <td class="list" colspan="3"></td>
196
                  <td class="list"> <a href="services_usermanager.php?act=new"><img src="./themes/".$g['theme']."/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
197
	        </tr>
198
     </table>
199
END;
200
}
201
?>
202

    
203
  </td>
204
  </tr>
205
  </table>
206
<?php include("fend.inc"); ?>
(133-133/203)