Project

General

Profile

Download (10.2 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	system_usermanager_edit.php
5

    
6
	Copyright (C) 2006 Daniel S. Haischt.
7
	All rights reserved.
8

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

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

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

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

    
31
require("guiconfig.inc");
32

    
33
$pgtitle = "System: User manager: Edit privilege";
34

    
35

    
36
/*
37
  The following code presumes, that the following XML structure exists or
38
  if it does not exist, it will be created.
39

    
40
    <priv>
41
      <id>fooid</id>
42
      <name>foo</name>
43
      <descr>foo desc</descr>
44
    </priv>
45
    <priv>
46
      <id>barid</id>
47
      <name>bar</name>
48
      <descr>bar desc</descr>
49
    </priv>
50
*/
51

    
52
$useract = $_GET['useract'];
53
if (isset($_POST['useract']))
54
	$useract = $_POST['useract'];
55

    
56
/* USERID must be set no matter whether this is a new entry or an existing entry */
57
$userid = $_GET['userid'];
58
if (isset($_POST['userid']))
59
	$userid = $_POST['userid'];
60

    
61
/* ID is only set if the user wants to edit an existing entry */
62
$id = $_GET['id'];
63
if (isset($_POST['id']))
64
	$id = $_POST['id'];
65

    
66
if (empty($config['system']['user'][$userid])) {
67
		pfSenseHeader("system_usermanager.php?id={$userid}&act={$_GET['useract']}");
68
		exit;
69
}
70

    
71
if (!is_array($config['system']['user'][$userid]['priv'])) {
72
  $config['system']['user'][$userid]['priv'] = array();
73
}
74

    
75
$t_privs = &$config['system']['user'][$userid]['priv'];
76

    
77
if (isset($id) && $t_privs[$id]) {
78
        $pconfig['pid'] = $t_privs[$id]['id'];
79
        $pconfig['pname'] = $t_privs[$id]['name'];
80
        $pconfig['descr'] = $t_privs[$id]['descr'];
81
} else {
82
        $pconfig['pid'] = $_GET['pid'];
83
        $pconfig['pname'] = $_GET['pname'];
84
        $pconfig['descr'] = $_GET['descr'];
85
}
86

    
87
if ($_POST) {
88

    
89
	unset($input_errors);
90
	$pconfig = $_POST;
91

    
92
	/* input validation */
93
	$reqdfields = explode(" ", "pid pname");
94
	$reqdfieldsn = explode(",", "ID, Privilege Name");
95

    
96
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
97

    
98
	/* check for overlaps */
99
	foreach ($t_privs as $priv) {
100
		if (isset($id) && ($t_privs[$id]) && ($t_privs[$id] === $priv)) {
101
			continue;
102
		}
103
		if ($priv['id'] == $pconfig['pid']) {
104
			$input_errors[] = gettext("This privilege ID already exists.");
105
			break;
106
		}
107
	}
108

    
109
  if (hasShellAccess($userindex[$userid]['name']) ||
110
      isAllowedToCopyFiles($userindex[$userid]['name'])) {
111
    if (preg_match("/[^a-zA-Z0-9\.\-_]/", $userindex[$userid]['name']))
112
        $input_errors[] = gettext("The username contains invalid characters " .
113
                                  "((this means this user can't be used to create" .
114
                                  " a shell account).");
115
  }
116

    
117
	/* if this is an AJAX caller then handle via JSON */
118
	if(isAjax() && is_array($input_errors)) {
119
		input_errors2Ajax($input_errors);
120
		exit;
121
	}
122

    
123
	if (!$input_errors) {
124
		$priv = array();
125
		$priv['id'] = $pconfig['pid'];
126
		$priv['name'] = $pconfig['pname'];
127
		$priv['descr'] = $pconfig['descr'];
128

    
129
		if (isset($id) && $t_privs[$id])
130
			$t_privs[$id] = $priv;
131
		else
132
			$t_privs[] = $priv;
133

    
134
    if ($priv['id'] == "hasshell") {
135
      assignUID($user['name']);
136
      assignGID($user['groupname']);
137
    }
138

    
139
		write_config();
140

    
141
    $retval = 0;
142
    config_lock();
143
    config_unlock();
144

    
145
    $savemsg = get_std_save_message($retval);
146

    
147
		pfSenseHeader("system_usermanager.php?id={$userid}&act={$useract}");
148
		exit;
149
  }
150
}
151

    
152
/* if ajax is calling, give them an update message */
153
if(isAjax())
154
	print_info_box_np($savemsg);
155

    
156
include("head.inc");
157
/* put your custom HTML head content here        */
158
/* using some of the $pfSenseHead function calls */
159

    
160
$jscriptstr = <<<EOD
161
<script type="text/javascript">
162
<!--
163

    
164
  var privs = new Array();
165

    
166

    
167
EOD;
168

    
169
$privs =& getSystemPrivs();
170

    
171
if (is_array($privs)) {
172
  $id = 0;
173

    
174
  $jscriptstr .= "privs[{$id}] = new Object();\n";
175
  $jscriptstr .= "privs[{$id}]['id'] = 'custom';\n";
176
  $jscriptstr .= "privs[{$id}]['name'] = '*** Custom privilege ***';\n";
177
  $jscriptstr .= "privs[{$id}]['desc'] = 'This is your own, user defined privilege that you may change according to your requirements.';\n";
178
  $id++;
179

    
180
  foreach($privs as $priv){
181
    $jscriptstr .= "privs[{$id}] = new Object();\n";
182
    $jscriptstr .= "privs[{$id}]['id'] = '{$priv['id']}';\n";
183
    $jscriptstr .= "privs[{$id}]['name'] = '{$priv['name']}';\n";
184
    $jscriptstr .= "privs[{$id}]['desc'] = '{$priv['desc']}';\n";
185
    $id++;
186
  }
187
}
188

    
189
$jscriptstr .= <<<EOD
190
  function setTextFields() {
191
    var idx = document.iform.sysprivs.selectedIndex;
192
    var value = document.iform.sysprivs.options[idx].value;
193

    
194
    for (var i = 0; i < privs.length; i++) {
195
      if (privs[i]['id'] == value && privs[i]['id'] != 'custom') {
196
        document.iform.pid.value = privs[i]['id'];
197
        document.iform.pid.readOnly = true;
198
        document.iform.pname.value = privs[i]['name'];
199
        document.iform.pname.readOnly = true;
200
        document.iform.descr.value = privs[i]['desc'];
201
        document.iform.descr.readOnly = true;
202
        break;
203
      } else if (privs[i]['id'] == value) {
204
        document.iform.pid.value = privs[i]['id'];
205
        document.iform.pid.readOnly = false;
206
        document.iform.pname.value = privs[i]['name'];
207
        document.iform.pname.readOnly = false;
208
        document.iform.descr.value = privs[i]['desc'];
209
        document.iform.descr.readOnly = false;
210
        break;
211
      }
212
    }
213
  }
214

    
215
//-->
216
</script>
217

    
218
EOD;
219

    
220
#$pfSenseHead->addScript($jscriptstr);
221
#echo $pfSenseHead->getHTML();
222
include("head.inc");
223

    
224
?>
225

    
226
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
227
<?php include("fbegin.inc"); ?>
228
<p class="pgtitle"><?=$pgtitle;?></p>
229
<?php if ($input_errors) print_input_errors($input_errors); ?>
230
<?php if ($savemsg) print_info_box($savemsg); ?>
231
            <form action="system_usermanager_edit.php" method="post" name="iform" id="iform">
232
            <div id="inputerrors"></div>
233
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
234
                <tr>
235
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("System Privileges");?></td>
236
                  <td width="78%" class="vtable">
237
                    <select name="sysprivs" id="sysprivs" class="formselect" onchange="setTextFields();">
238
                      <option value="custom">*** Custom privilege ***</option>
239
                    <?php
240
                      $privs =& getSystemPrivs();
241

    
242
                      if (is_array($privs)) {
243
                        foreach($privs as $priv){
244
                          if (isset($config['system']['ssh']['sshdkeyonly']) &&  $priv['name'] <> "copyfiles")
245
                              echo "<option value=\"{$priv['id']}\">${priv['name']}</option>";
246
                          else if (empty($config['system']['ssh']['sshdkeyonly']))
247
                              echo "<option value=\"{$priv['id']}\">${priv['name']}</option>";
248
                        }
249
                      }
250
                    ?>
251
                    </select><br />
252
                    (If you do not want to define your own privilege, you may
253
                    select one from this list)
254
                  </td>
255
                </tr>
256
                <tr>
257
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Privilege Identifier");?></td>
258
                  <td width="78%" class="vtable">
259
                    <input name="pid" type="text" class="formfld unknown" id="pid" size="30" value="<?=htmlspecialchars($pconfig['pid']);?>" />
260
                  </td>
261
                </tr>
262
                <tr>
263
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Privilege Name");?></td>
264
                  <td width="78%" class="vtable">
265
                    <input name="pname" type="text" class="formfld unknown" id="pname" size="30" value="<?=htmlspecialchars($pconfig['pname']);?>" />
266
                  </td>
267
                </tr>
268
                <tr>
269
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
270
                  <td width="78%" class="vtable">
271
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="60" value="<?=htmlspecialchars($pconfig['descr']);?>" />
272
                    <br /> <span class="vexpl"><?=gettext("You may enter a description here
273
                    for your reference (not parsed).");?></span></td>
274
                </tr>
275
                <tr>
276
                  <td width="22%" valign="top">&nbsp;</td>
277
                  <td width="78%">
278
                    <input id="submitt"  name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
279
                    <input id="cancelbutton" class="formbtn" type="button" value="<?=gettext("Cancel");?>" onclick="history.back()" />
280
                    <?php if (isset($id) && $t_privs[$id]): ?>
281
                    <input name="id" type="hidden" value="<?=$id;?>" />
282
                    <?php endif; ?>
283
                    <?php if (isset($userid)): ?>
284
                    <input name="userid" type="hidden" value="<?=$userid;?>" />
285
                    <?php endif; ?>
286
                    <?php if (isset($useract)): ?>
287
                    <input name="useract" type="hidden" value="<?=$useract;?>" />
288
                    <?php endif; ?>
289
                  </td>
290
                </tr>
291
              </table>
292
            </form>
293
<?php include("fend.inc"); ?>
294
</body>
295
</html>
(156-156/186)