summaryrefslogtreecommitdiffstats
path: root/usr/local/www/services_usermanager.php
blob: 755627ae4b6542b742bc8a09f715134aaf7af154 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<?php
/* $Id$ */
/*
	services_usermanager.php
	part of m0n0wall (http://m0n0.ch/wall)

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

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

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

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

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

##|+PRIV
##|*IDENT=page-services-usermanager
##|*NAME=Services: User Manager page
##|*DESCR=Allow access to the 'Services: User Manager' page.
##|*MATCH=services_usermanager.php*
##|-PRIV

require("guiconfig.inc");
if(isset($_POST['save'])){
	$_POST['username']=trim($_POST['username']);
	if($_POST['old_username']!="" && $_POST['old_username']!=$_POST['username']){
		$config['users'][$_POST['username']]=$config['users'][$_POST['old_username']];
		unset($config['users'][$_POST['old_username']]);
	}
	foreach(Array('fullname','expirationdate') as $field){
		$config['users'][$_POST['username']][$field]=trim($_POST[$field]);
	}
	if(trim($_POST['password1'])!="********" && trim($_POST['password1'])!=""){
		if(trim($_POST['password1'])==trim($_POST['password2'])){
			$config['users'][$_POST['username']]['password']=md5(trim($_POST['password1']));
		} else {
			$input_errors[]="passwords did not match --> password was not changed!";
		}
	}
	if($_POST['username']=="" || trim($_POST['password1'])==""){
		$input_errors[] = "Username and password must not be empty!";
		$_GET['act']="new";
	} else {
		write_config();
		$savemsg=$_POST['username']." successfully saved<br>";
	}
} else if ($_GET['act']=="delete" && isset($_GET['username'])){
	unset($config['users'][$_GET['username']]);
	write_config();
	$savemsg=$_GET['username']." successfully deleted<br>";
}
//erase expired accounts
$changed=false;
if(is_array($config['users'])){
	foreach($config['users'] as $username => $user){
		if(trim($user['expirationdate'])!="" && strtotime("-1 day")>strtotime($user['expirationdate'])){
			unset($config['users'][$username]);
			$changed=true;
			$savemsg.="$username has expired --> $username was deleted<br>";
		}
	}
	if($changed){
		write_config();
	}
}

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

?>

<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
<?php include("fbegin.inc"); ?>
<script language="javascript" type="text/javascript" src="/javascript/datetimepicker.js">
//Date Time Picker script- by TengYong Ng of http://www.rainforestnet.com
//Script featured on JavaScript Kit (http://www.javascriptkit.com)
//For this script, visit http://www.javascriptkit.com
</script>
<?php if ($input_errors) print_input_errors($input_errors); ?>
<?php if ($savemsg) print_info_box($savemsg); ?>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr><td class="tabnavtbl">
  <ul id="tabnav">
	<li class="tabinact1"><a href="services_captiveportal.php">Captive portal</a></li>
	<li class="tabinact"><a href="services_captiveportal_mac.php">Pass-through MAC</a></li>
	<li class="tabinact"><a href="services_captiveportal_ip.php">Allowed IP addresses</a></li>
	<li class="tabact">User Manager</li>
  </ul>
  </td></tr>
  <tr>
  <td class="tabcont">
<?php
if($_GET['act']=="new" || $_GET['act']=="edit"){
	if($_GET['act']=="edit" && isset($_GET['username'])){
		$user=$config['users'][$_GET['username']];
	}
?>
	<form action="services_usermanager.php" method="post" name="iform" id="iform">
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
                <tr>
                  <td width="22%" valign="top" class="vncellreq">Username</td>
                  <td width="78%" class="vtable">
                    <input name="username" type="text" class="formfld user" id="username" size="20" value="<? echo $_GET['username']; ?>">
                    <br>
                    <span class="vexpl">Enter the desired username.</span></td>
                </tr>
                <tr>
                  <td width="22%" valign="top" class="vncellreq">Password</td>
                  <td width="78%" class="vtable">
                    <input name="password1" type="password" class="formfld pwd" id="password1" size="20" value="<?php echo ($_GET['act']=='edit' ? "********" : "" ); ?>">
                    <br>
                    <span class="vexpl">Enter the desired password.</span></td>
                </tr>
                <tr>
                  <td width="22%" valign="top" class="vncellreq">Password confirmation</td>
                  <td width="78%" class="vtable">
                    <input name="password2" type="password" class="formfld pwd" id="password2" size="20" value="<?php echo ($_GET['act']=='edit' ? "********" : "" ); ?>">
                    <br>
                    <span class="vexpl">Confirm the above password.</span></td>
                </tr>
                <tr>
                  <td width="22%" valign="top" class="vncell">Full name</td>
                  <td width="78%" class="vtable">
                    <input name="fullname" type="text" class="formfld unknown" id="fullname" size="20" value="<? echo $user['fullname']; ?>">
                    <br>
                    Enter the user's full name.</td>
                </tr>
                <tr>
                  <td width="22%" valign="top" class="vncell">Expiration Date</td>
                  <td width="78%" class="vtable">
                    <input name="expirationdate" type="text" class="formfld unknown" id="expirationdate" size="10" value="<? echo $user['expirationdate']; ?>">
                    <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>
                    <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>
                </tr>
                <tr>
                  <td width="22%" valign="top">&nbsp;</td>
                  <td width="78%">
                    <input name="save" type="submit" class="formbtn" value="Save">
                    <input name="old_username" type="hidden" value="<? echo $_GET['username'];?>">
                  </td>
                </tr>
              </table>
     </form>
<?php
} else {
	echo <<<END
     <table width="100%" border="0" cellpadding="0" cellspacing="0">
                <tr>
                  <td width="35%" class="listhdrr">Username</td>
                  <td width="20%" class="listhdrr">Full Name</td>
                  <td width="35%" class="listhdr">Expires</td>
                  <td width="10%" class="list"></td>
		</tr>
END;
	if(is_array($config['users'])){
		foreach($config['users'] as $username => $user){
?>
		<tr>
                  <td class="listlr">
                    <?php echo $username; ?>&nbsp;
                  </td>
                  <td class="listr">
                    <?php echo $user['fullname']; ?>&nbsp;
                  </td>
                  <td class="listbg">
                    <?php echo $user['expirationdate']; ?>&nbsp;
                  </td>
                  <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>
                     &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>
		</tr>
<?php
		}
	}
	echo <<<END
		<tr>
                  <td class="list" colspan="3"></td>
                  <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>
	        </tr>
     </table>
END;
}
?>

  </td>
  </tr>
  </table>
<?php include("fend.inc"); ?>
OpenPOWER on IntegriCloud