Skip to content

Commit c5a6f3e

Browse files
committed
PSTN permissions
1 parent 849c40d commit c5a6f3e

16 files changed

+97
-58
lines changed

app/admin/users/edit-result.php

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
"mailNotify"=>$_POST['mailNotify'],
102102
"mailChangelog"=>$_POST['mailChangelog'],
103103
"editVlan"=>$_POST['editVlan'],
104+
"pstn"=>$_POST['pstn'],
104105
"pdns"=>$_POST['pdns']
105106
);
106107
# update pass ?

app/admin/users/edit.php

+21-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
$Database = new Database_PDO;
1212
$User = new User ($Database);
1313
$Admin = new Admin ($Database);
14+
$Subnets = new Subnets ($Database);
1415
$Tools = new Tools ($Database);
1516
$Result = new Result ();
1617

@@ -274,7 +275,7 @@
274275
<tr>
275276
<td><?php print _("VLANs"); ?></td>
276277
<td>
277-
<input type="checkbox" class="input-switch" value="Yes" name="editVlan" <?php if(@$user->editVlan == "Yes") print 'checked'; ?>>
278+
<input type="checkbox" class="input-switch" value="Yes" name="editVlan" <?php if($user['editVlan'] == "Yes") print 'checked'; ?>>
278279
</td>
279280
<td class="info2"><?php print _('Select to allow user to manage VLANs'); ?></td>
280281
</tr>
@@ -284,12 +285,30 @@
284285
<tr>
285286
<td><?php print _("PowerDNS"); ?></td>
286287
<td>
287-
<input type="checkbox" class="input-switch" value="Yes" name="pdns" <?php if(@$user->pdns == "Yes") print 'checked'; ?>>
288+
<input type="checkbox" class="input-switch" value="Yes" name="pdns" <?php if($user['pdns'] == "Yes") print 'checked'; ?>>
288289
</td>
289290
<td class="info2"><?php print _('Select to allow user to create DNS records'); ?></td>
290291
</tr>
291292
<?php } ?>
292293

294+
<!-- pstn -->
295+
<?php if ($User->settings->enablePSTN==1) { ?>
296+
<tr>
297+
<td><?php print _("PSTN");?></td>
298+
<td>
299+
<select class="form-control input-sm input-w-auto" name="pstn">
300+
<?php
301+
foreach (array(0,1,2,3) as $p) {
302+
$selected = $p==$user['pstn'] ? "selected" : "";
303+
print "<option value='$p' $selected>".$Subnets->parse_permissions ($p)."</option>";
304+
}
305+
?>
306+
</select>
307+
</td>
308+
<td class="info2"><?php print _('Select to allow user to manage PSTN numbers'); ?></td>
309+
</tr>
310+
<?php } ?>
311+
293312
<!-- Custom -->
294313
<?php
295314
if(sizeof($custom) > 0) {

app/admin/users/print-all.php

+16
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
<th><?php print _('PowerDNS'); ?></th>
4242
<?php } ?>
4343
<th><?php print _('Manage VLANs'); ?></th>
44+
<?php if ($User->settings->enablePSTN==1) { ?>
45+
<th><?php print _('PSTN'); ?></th>
46+
<?php } ?>
4447
<th><?php print _('Groups'); ?></th>
4548
<th><?php print _('Last login'); ?></th>
4649
<?php
@@ -97,6 +100,9 @@
97100
print "<td><span class='badge badge1 badge5 alert-success'>"._("Yes")."</span></td>";
98101
}
99102
print "<td><span class='badge badge1 badge5 alert-success'>"._("Yes")."</span></td>";
103+
if ($User->settings->enablePSTN==1) {
104+
print "<td><span class='badge badge1 badge5 alert-success'>"._($Subnets->parse_permissions (3))."</span></td>";
105+
}
100106
}
101107
else {
102108
if ($User->settings->enablePowerDNS==1) {
@@ -118,6 +124,16 @@
118124
print "<td>";
119125
print $user['editVlan'];
120126
print "</td>";
127+
128+
// pstn
129+
if ($User->settings->enablePSTN==1) {
130+
// append badge
131+
$user['pstn'] = $user['pstn']=="No" ? "<span class='badge badge1 badge5 alert-danger'>"._($user['pstn'])."</span>" : "<span class='badge badge1 badge5 alert-success'>"._($Subnets->parse_permissions ($user['pstn']))."</span>";
132+
133+
print "<td>";
134+
print $user['pstn'];
135+
print "</td>";
136+
}
121137
}
122138

123139
# groups

app/admin/users/print-user.php

+22
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,28 @@
4747
<td><?php print _('Language'); ?></td>
4848
<td><?php print $language->l_name; ?></td>
4949
</tr>
50+
<?php if ($User->settings->enablePowerDNS==1) { ?>
51+
<tr>
52+
<?php
53+
$user->pdns = $user->pdns=="Yes"||$user->role=="Administrator" ? "Yes" : "No";
54+
?>
55+
<td><?php print _('PowerDNS'); ?></td>
56+
<td><?php print $user->pdns; ?></td>
57+
</tr>
58+
<?php } ?>
59+
<tr>
60+
<?php
61+
$user->editVlan = $user->editVlan=="Yes"||$user->role=="Administrator" ? "Yes" : "No";
62+
?>
63+
<td><?php print _('Manage VLANs'); ?></td>
64+
<td><?php print $user->editVlan; ?></td>
65+
</tr>
66+
<?php if ($User->settings->enablePSTN==1) { ?>
67+
<tr>
68+
<td><?php print _('PSTN'); ?></td>
69+
<td><?php print $Subnets->parse_permissions ($user->pstn); ?></td>
70+
</tr>
71+
<?php } ?>
5072
<tr>
5173
<td></td>
5274
<td>

app/tools/devices/device-details/device-pstn.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
}
115115

116116
# set permission
117-
$permission = $Tools->check_prefix_permission ($User->user, $sp->id);
117+
$permission = $Tools->check_prefix_permission ($User->user);
118118

119119
print " <td class='actions' style='padding:0px;'>";
120120
print " <div class='btn-group'>";

app/tools/pstn-prefixes/all-prefixes.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# fetch all locations
2626
$all_prefixes = $Tools->fetch_all_prefixes();
2727

28-
$colspan = $admin ? 8 : 7;
28+
$colspan = $admin||$User->user->pstn==3 ? 9 : 8;
2929

3030
// table
3131
print "<table id='manageSubnets' class='table sorted table-striped table-top table-td-top'>";
@@ -47,7 +47,6 @@
4747
}
4848
}
4949
}
50-
if($admin)
5150
print " <th style='width:80px'></th>";
5251
print "</tr>";
5352
print "</thead>";
@@ -63,7 +62,14 @@
6362
else {
6463

6564
$html = $Tools->print_menu_prefixes ( $User->user, $all_prefixes, $custom );
65+
if($html!==false)
6666
print implode("\n", $html);
67+
68+
else {
69+
print "<tr>";
70+
print " <td colspan='$colspan'>".$Result->show("info","No PSTN prefixes available", false, false, true)."</td>";
71+
print "</tr>";
72+
}
6773
}
6874
print "</tbody>";
6975
print "</table>";

app/tools/pstn-prefixes/edit-number-result.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# initialize user object
77
$Database = new Database_PDO;
88
$User = new User ($Database);
9-
$Admin = new Admin ($Database);
9+
$Admin = new Admin ($Database, false);
1010
$Tools = new Tools ($Database);
1111
$Result = new Result ();
1212

@@ -16,6 +16,9 @@
1616
# strip input tags
1717
$_POST = $Admin->strip_input_tags($_POST);
1818

19+
# check permissions
20+
if($Tools->check_prefix_permission ($User->user) <2) { $Result->show("danger", _('You do not have permission to manage PSTN numbers'), true, true); }
21+
1922
# validate csrf cookie
2023
$User->csrf_cookie ("validate", "pstn_number", $_POST['csrf_cookie']) === false ? $Result->show("danger", _("Invalid CSRF cookie"), true) : "";
2124

@@ -37,6 +40,7 @@
3740
if($prefix===false) { $Result->show("danger", _("Invalid prefix"), true); }
3841

3942
// duplicate check
43+
if($_POST['action']=="add")
4044
if ($Tools->check_number_duplicates ($prefix->id, $_POST['number'])){ $Result->show("danger", _("Duplicate number"), true); }
4145

4246
// ranges

app/tools/pstn-prefixes/edit-number.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# initialize user object
1111
$Database = new Database_PDO;
1212
$User = new User ($Database);
13-
$Admin = new Admin ($Database);
13+
$Admin = new Admin ($Database, false);
1414
$Tools = new Tools ($Database);
1515
$Addresses = new Addresses ($Database);
1616
$Result = new Result ();
@@ -21,6 +21,9 @@
2121
# create csrf token
2222
$csrf = $User->csrf_cookie ("create", "pstn_number");
2323

24+
# check permissions
25+
if($Tools->check_prefix_permission ($User->user) < 2) { $Result->show("danger", _('You do not have permission to manage PSTN numbers'), true, true); }
26+
2427
# get Location object
2528
if($_POST['action']!="add") {
2629
$number = $Admin->fetch_object ("pstnNumbers", "id", $_POST['id']);

app/tools/pstn-prefixes/edit-result.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# initialize user object
77
$Database = new Database_PDO;
88
$User = new User ($Database);
9-
$Admin = new Admin ($Database);
9+
$Admin = new Admin ($Database, false);
1010
$Tools = new Tools ($Database);
1111
$Result = new Result ();
1212

@@ -16,6 +16,9 @@
1616
# strip input tags
1717
$_POST = $Admin->strip_input_tags($_POST);
1818

19+
# check permissions
20+
if($Tools->check_prefix_permission ($User->user) <3) { $Result->show("danger", _('You do not have permission to manage PSTN prefixes'), true); }
21+
1922
# validate csrf cookie
2023
$User->csrf_cookie ("validate", "pstn", $_POST['csrf_cookie']) === false ? $Result->show("danger", _("Invalid CSRF cookie"), true) : "";
2124

app/tools/pstn-prefixes/edit.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# initialize user object
1111
$Database = new Database_PDO;
1212
$User = new User ($Database);
13-
$Admin = new Admin ($Database);
13+
$Admin = new Admin ($Database, false);
1414
$Tools = new Tools ($Database);
1515
$Result = new Result ();
1616

@@ -20,6 +20,9 @@
2020
# create csrf token
2121
$csrf = $User->csrf_cookie ("create", "pstn");
2222

23+
# check permissions
24+
if($Tools->check_prefix_permission ($User->user) < 3) { $Result->show("danger", _('You do not have permission to manage PSTN prefixes'), true, true); }
25+
2326
# get Location object
2427
if($_POST['action']!="add") {
2528
$prefix = $Admin->fetch_object ("pstnPrefixes", "id", $_POST['id']);

app/tools/pstn-prefixes/single-prefix-slaves-list.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
}
126126

127127
# set permission
128-
$permission = $Tools->check_prefix_permission ($User->user, $sp->id);
128+
$permission = $Tools->check_prefix_permission ($User->user);
129129

130130
print " <td class='actions' style='padding:0px;'>";
131131
print " <div class='btn-group'>";

app/tools/pstn-prefixes/single-prefix-slaves.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
}
3636
else {
3737
# set permission
38-
$permission = $Tools->check_prefix_permission ($User->user, $prefix->id);
38+
$permission = $Tools->check_prefix_permission ($User->user);
3939

4040
# raw prefix number
4141
$prefix->prefix_raw = $Tools->prefix_normalize ($prefix->prefix);

app/tools/pstn-prefixes/single-prefix.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
else {
3232

3333
# set permission
34-
$permission = $Tools->check_prefix_permission ($User->user, $prefix->id);
34+
$permission = $Tools->check_prefix_permission ($User->user);
3535

3636
# raw prefix number
3737
$prefix->prefix_raw = $Tools->prefix_normalize ($prefix->prefix);

functions/classes/class.Tools.php

+5-44
Original file line numberDiff line numberDiff line change
@@ -2089,47 +2089,8 @@ public function check_number_duplicates ($prefix = false, $number = false) {
20892089
* @param int $subnetId
20902090
* @return void
20912091
*/
2092-
public function check_prefix_permission ($user, $prefix_id) {
2093-
2094-
# get all user groups
2095-
$groups = json_decode($user->groups, true);
2096-
2097-
# if user is admin then return 3, otherwise check
2098-
if($user->role == "Administrator") { return 3; }
2099-
2100-
# set subnet permissions
2101-
$prefix = $this->fetch_object ("pstnPrefixes", "id", $prefix_id);
2102-
if($prefix===false) return 0;
2103-
//null?
2104-
if(is_null($prefix->permissions) || $prefix->permissions=="null") return 0;
2105-
$subnetP = json_decode(@$prefix->permissions);
2106-
2107-
# set section permissions
2108-
$Section = new Sections ($this->Database);
2109-
$section = $Section->fetch_section ("id", $subnet->sectionId);
2110-
$sectionP = json_decode($section->permissions);
2111-
2112-
# if section permission == 0 then return 0
2113-
if($out == 0) {
2114-
return 0;
2115-
}
2116-
else {
2117-
$out = 0;
2118-
# ok, user has section access, check also for any higher access from subnet
2119-
if(sizeof($subnetP) > 0) {
2120-
foreach($subnetP as $sk=>$sp) {
2121-
# check each group if user is in it and if so check for permissions for that group
2122-
foreach($groups as $uk=>$up) {
2123-
if($uk == $sk) {
2124-
if($sp > $out) { $out = $sp; }
2125-
}
2126-
}
2127-
}
2128-
}
2129-
}
2130-
2131-
# return result
2132-
return $out;
2092+
public function check_prefix_permission ($user) {
2093+
return $user->role=="Administrator" ? 3 : $user->pstn;
21332094
}
21342095

21352096
/**
@@ -2156,7 +2117,7 @@ public function print_menu_prefixes ( $user, $prefixes, $custom_fields ) {
21562117
# remove all not permitted!
21572118
if(sizeof($prefixes)>0) {
21582119
foreach($prefixes as $k=>$s) {
2159-
$permission = $this->check_prefix_permission ($user, $s->id);
2120+
$permission = $this->check_prefix_permission ($user);
21602121
if($permission == 0) { unset($prefixes[$k]); }
21612122
}
21622123
}
@@ -2296,12 +2257,12 @@ public function print_menu_prefixes ( $user, $prefixes, $custom_fields ) {
22962257
}
22972258

22982259
# set permission
2299-
$permission = $this->check_prefix_permission ($user, $option['value']['id']);
2260+
$permission = $this->check_prefix_permission ($user);
23002261

23012262
$html[] = " <td class='actions' style='padding:0px;'>";
23022263
$html[] = " <div class='btn-group'>";
23032264

2304-
if($permission>1) {
2265+
if($permission>2) {
23052266
$html[] = " <button class='btn btn-xs btn-default editPSTN' data-action='edit' data-id='".$option['value']['id']."'><i class='fa fa-pencil'></i></button>";
23062267
$html[] = " <button class='btn btn-xs btn-default editPSTN' data-action='delete' data-id='".$option['value']['id']."'><i class='fa fa-times'></i></button>";
23072268
}

functions/version.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/* set latest version */
33
define("VERSION", "1.24"); //version changes if database structure changes
44
/* set latest revision */
5-
define("REVISION", "10"); //revision always changes, verision only if database structure changes
5+
define("REVISION", "11"); //revision always changes, verision only if database structure changes
66
/* set last possible upgrade */
77
define("LAST_POSSIBLE", "1.1"); //minimum required version to be able to upgrade
88
?>

misc/CHANGELOG

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
== 1.24.00
1+
== 1.24.11
22

33
New features:
44
------------
@@ -68,6 +68,7 @@
6868
----------------------------
6969
+ PowerDNS regenerate PTR records now only updates current subnet (before whole zone);
7070
+ Fixed visual bug on 32-bit systems;
71+
+ Normal users with RWA permissions can scan subnets;
7172
+ Changed default timestamp from 0000-00-00 00:00:00 to 1970-01-01 00:00:01 to avoid SQL install errors if strict mode;
7273

7374
== 1.20.1

0 commit comments

Comments
 (0)