-
Notifications
You must be signed in to change notification settings - Fork 1
/
permission_worker.php
222 lines (156 loc) · 6.54 KB
/
permission_worker.php
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<?php
include "layout.class.php";
include "config.php";
include "bartlby-ui.class.php";
$btl=new BartlbyUi($Bartlby_CONF);
$layout= new Layout();
$layout->set_menu("worker");
$layout->setTitle("");
$layout->OUT .= "<script>global_worker_id=" . $_GET[worker_id] . ";</script>";
$defaults=@bartlby_get_worker_by_id($btl->RES, $_GET[worker_id]);
$fm_action="save_permissions";
$btl->hasRight("super_user");
if($defaults == false) {
$btl->redirectError("BARTLBY::OBJECT::MISSING");
exit(1);
}
$worker_rights = $btl->loadForeignRights($defaults[worker_id]);
$optind=0;
$servers_out=array();
$services_x=0;
$btl->service_list_loop(function($svc, $shm) use(&$servers, &$optind, &$btl, &$servers_out, &$services_x, &$worker_rights, &$defaults) {
if($svc[is_gone] != 0) {
return LOOP_CONTINUE;
}
if(($_GET[dropdown_term] && @preg_match("/" . $_GET[dropdown_term] . "/i", $svc[server_name] . "/" . $svc[service_name])) || strstr($defaults[services], "|" . $svc[service_id] . "|") || @in_array( $svc[server_id], $worker_rights[servers]) || @in_array( $svc[service_id], $worker_rights[services])) {
if(!is_array($servers_out[$svc[server_id]])) {
$servers_out[$svc[server_id]]=array();
}
array_push($servers_out[$svc[server_id]], $svc);
$services_x++;
} //if($services_x > 50) return LOOP_BREAK;
});
ksort($servers_out);
$optind=0;
$map = $servers_out;
$optind=0;
while(list($k, $servs) = @each($map)) {
for($x=0; $x<count($servs); $x++) {
//$v1=bartlby_get_service_by_id($btl->RES, $servs[$x][service_id]);
if($x == 0 ) {
//$isup=$btl->isServerUp($v1[server_id]);
//if($isup == 1 ) { $isup="UP"; } else { $isup="DOWN"; }
$servers[$optind][c]="";
$servers[$optind][v]="s" . $servs[$x][server_id];
$servers[$optind][k]="" . $servs[$x][server_name] . "";
$servers[$optind][is_group]=1;
if(@in_array($servs[$x][server_id], $worker_rights[servers])) {
$servers[$optind][s]=1;
}
$optind++;
} else {
}
$state=$btl->getState($servs[$x][current_state]);
$servers[$optind][c]="";
$servers[$optind][v]=$servs[$x][service_id];
$servers[$optind][k]=$servs[$x][server_name] . "/" . $servs[$x][service_name];
if(@in_array($servs[$x][service_id], $worker_rights[services])) {
$servers[$optind][s]=1;
}
$optind++;
}
}
$ov = "<form name='fm1' action='bartlby_action.php' method=POST class='form-horizontal'>";
$ov .= $layout->FormBox(
array(
0=>"Name",
1=>$defaults[name]. $layout->Field("action", "hidden", $fm_action)
)
, true);
$ov .= $layout->FormBox(
array(
0=>"Visible services:",
1=>$layout->DropDown("worker_services[]", $servers, "multiple","",true, "ajax_modify_worker_services_permission")
)
,true);
$ov .= "<table class='border datatable table-border'><thead class='border'><td>Right</td><td>Given</td></thead><tbody class='no-border-y'>";
$all_keys=$btl->loadForeignRights("template");
while(list($k,$v) = each($all_keys)) {
if($k == "servers" || $k == "services" || $k == "selected_servers" || $k == "selected_services") continue;
if($worker_rights[$k][0] && $worker_rights[$k][0] != "false") {
$checked="checked";
} else {
$checked="";
}
$ov .= "<tr><td>" . translatedKey($k) . "</td>";
$ov .= "<td>" . "<input type=checkbox class=icheck name='" . $k . "' $checked>" . "</td>";
}
$ov .= "</tbody></table>";
function translatedKey($k) {
$ar["super_user"]="Super User (has full rights, can also give rights)";
$ar["action.reload"]="allowed to reload data";
$ar["core.edit_cfg"]="can edit config files";
$ar["core.api_access"]="Can Access the REST-API (using priv/pubkey)";
$ar["core.process_info"]="can view statistics";
$ar["core.event_queue"]="view event queue";
$ar["action.disable_notify"]="allowed to disable notifications";
$ar["action.enable_service"]="allowed to enable notifications";
$ar["action.add_comment"]="Add comments (also required for service ack)";
$ar["action.force_check"]="can force checks";
$ar["action.perfhandler_graph"]="perfhandler update";
$ar["action.disable_extension"]="can disable ui-extensions";
$ar["action.enable_extension"]="can enable ui-extensions";
$ar["action.sirene_enable"]="can fire the sirene";
$ar["action.sirene_disable"]="can disarm the sirene";
$ar["modify_all_workers"]="allowed to see all workers";
$ar["main.server_detail"]="server details";
$ar["main.service_detail"]="can view the service list";
$ar["main.overview"]="can view the overview";
$ar["action.stop"]="can shutdown bartlby";
$ar["log.report"]="can do reports?";
$ar["log.logview"]="logfile visible?";
$ar["action.add_server"]="add servers";
$ar["action.delete_server"]=" delete servers";
$ar["action.modify_server"]="modify servers";
$ar["action.copy_server"]="copy servers";
$ar["action.install_package"]="is allowed to install packages";
$ar["action.uninstall_package"]="is allowed to uninstall packages";
$ar["action.delete_package"]="delete packages";
$ar["action.create_package"]="create packages";
$ar["action.add_worker"]="add worker";
$ar["action.delete_worker"]=" delete worker";
$ar["action.modify_worker"]="modify worker";
$ar["action.copy_worker"]="copy worker";
$ar["action.add_service"]="add service";
$ar["action.delete_service"]=" delete service";
$ar["action.modify_service"]="modify service";
$ar["action.copy_service"]="copy service";
$ar["action.add_downtime"]="add downtime";
$ar["action.delete_downtime"]=" delete downtime";
$ar["action.modify_downtime"]="modify downtime";
$ar["main.services"]="can view service list";
$ar["sysmessages"]="system messages visible? in logview.";
$ar["view_service_output"]="service output visible?";
$ar["main.servergroup_detail"]="view servergroup details";
$ar["main.servicegroup_detail"]="view servicegroup details";
$ar["action.add_servicegroup"]="add servicegroup";
$ar["action.add_servergroup"]="add servergroup";
$ar["action.modify_servergroup"]="modify servergroup";
$ar["action.modify_servicegroup"]="modify servicegroup";
$ar["action.delete_servergroup"]="delete servergroup";
$ar["action.delete_servicegroup"]="delete servergroup";
if(!$ar[$k]) {
return "Key ('$k') not translated";
} else {
return $ar[$k];
}
}
$title="UI privileges";
$ov .= $layout->Field("worker_id", "hidden", $_GET[worker_id]) . "<input class='fa fa-save btn btn-primary' type=submit value='Save'>";
$content = "<span class=form-horizontal>" . $ov . "</span>";
$layout->create_box($title, $content);
$r=$btl->getExtensionsReturn("_permissions", $layout);
$layout->FormEnd();
$title="";
//$layout->push_outside($layout->create_box($title, $content));
$layout->display();