3
class trustModeDialog extends plugin
5
public $attributes = array("accessTo","trustModel");
6
public $accessTo = array();
7
public $trustModel = "";
8
public $trustSelect = NULL;
10
private $trustList = NULL;
12
function __construct(&$config, $dn, $parent = NULL)
14
plugin::plugin($config, $dn, $parent);
16
$this->accessTo = array();
17
$this->trustModel= "";
18
$this->is_account = FALSE;
19
if(isset($this->attrs['trustModel'][0])){
20
$this->is_account = TRUE;
21
$this->trustModel= $this->attrs['trustModel'][0];
22
if (isset($this->attrs['accessTo'])){
23
for ($i= 0; $i<$this->attrs['accessTo']['count']; $i++){
24
$tmp= $this->attrs['accessTo'][$i];
25
$this->accessTo[$tmp]= $tmp;
31
$this->initially_was_account = $this->is_account;
34
foreach($this->accessTo as $key => $cn){
35
$lData[$cn] = array('data' => $this->converCnToType($cn));
38
$this->trustList = new sortableListing($this->accessTo, $lData);
39
$this->trustList->setDeleteable(true);
40
$this->trustList->setInstantDelete(true);
41
$this->trustList->setEditable(false);
42
$this->trustList->setWidth("100%");
43
$this->trustList->setHeight("100px");
44
$this->trustList->setColspecs(array('20px','*'));
45
$this->trustList->setHeader(array("~",_("Name"),_("Description")));
46
$this->trustList->setDefaultSortColumn(1);
50
public function PrepareForCopyPaste($source)
52
$this->accessTo = array();
53
$this->trustModel= "";
54
$this->is_account = FALSE;
55
if(isset($source['trustModel'][0])){
56
$this->is_account = TRUE;
57
$this->trustModel= $source['trustModel'][0];
58
if (isset($source['accessTo'])){
59
for ($i= 0; $i<$source['accessTo']['count']; $i++){
60
$tmp= $source['accessTo'][$i];
61
$this->accessTo[$tmp]= $tmp;
67
public function converCnToType($cn)
69
if(isset($this->typeCache[$cn])){
70
return($this->typeCache[$cn]);
73
$ldap = $this->config->get_ldap_link();
74
$ldap->cd($this->config->current['BASE']);
75
$ldap->search("(&(|(objectClass=gotoTerminal)(objectClass=gotoWorkstation)".
76
"(objectClass=goServer))(cn=".$cn."))", array("objectClass", "description"));
77
$this->typeCache[$cn] = array("",$cn,"");
78
if($ldap->count() != 0){
79
$attrs = $ldap->fetch();
81
if(in_array_strict("gotoWorkstation",$attrs['objectClass'])){
82
$img = image('plugins/systems/images/select_workstation.png');
83
}elseif(in_array_strict("gotoTerminal",$attrs['objectClass'])){
84
$img = image('plugins/systems/images/select_terminal.png');
85
}elseif(in_array_strict("goServer",$attrs['objectClass'])){
86
$img = image('plugins/systems/images/select_server.png');
88
if(isset($attrs['description'][0])) {
89
$desc = $attrs['description'][0];
91
$this->typeCache[$cn] = array($img,$cn,$desc);
93
return($this->typeCache[$cn]);
96
public function setAcl($acl)
101
public function execute()
106
$this->trustList->setAcl($this->getacl("accessTo"));
107
$this->trustList->save_object();
109
// Allow to select trusted machines from a list
110
if (isset($_POST["add_ws"])){
111
$this->trustSelect= new trustSelect($this->config,get_userinfo());
115
// Cancel trust and group dialog
116
if (isset($_POST['add_ws_cancel'])){
117
$this->groupSelect= NULL;
118
$this->trustSelect= NULL;
119
$this->dialog= FALSE;
122
// Add selected machines to trusted ones.
123
if (isset($_POST["add_ws_finish"]) && $this->trustSelect){
124
$trusts = $this->trustSelect->detectPostActions();
125
if(isset($trusts['targets'])){
126
$headpage = $this->trustSelect->getHeadpage();
127
foreach($trusts['targets'] as $id){
128
$attrs = $headpage->getEntry($id);
129
$cn = $attrs['cn'][0];
130
$this->accessTo[$cn]=$cn;
131
$this->trustList->addEntry($cn,
132
array('data'=> $this->converCnToType($cn)),
135
$this->is_modified= TRUE;
136
$this->trustList->update();
138
$this->trustSelect= NULL;
139
$this->dialog= FALSE;
142
// Remove machine from trusted ones.
143
$actionL = $this->trustList->getAction();
144
if ($actionL['action'] == "delete"){
145
$this->accessTo = $this->trustList->getMaintainedData();
146
$this->is_modified= TRUE;
150
if ($this->trustSelect){
151
session::set('filterBlacklist', array('cn' => array_values($this->accessTo)));
152
return($this->trustSelect->execute());
155
/* Work on trust modes */
156
$smarty = get_smarty();
157
$smarty->assign("trusthide", " disabled ");
158
$smarty->assign("trustmodeACL", $this->getacl("accessTo"));
159
if ($this->trustModel == "fullaccess"){
161
// pervent double disable tag in html code, this will disturb our clean w3c html
162
$smarty->assign("trustmode", $this->getacl("accessTo"));
164
} elseif ($this->trustModel == "byhost"){
166
$smarty->assign("trusthide", "");
168
// pervent double disable tag in html code, this will disturb our clean w3c html
169
$smarty->assign("trustmode", $this->getacl("accessTo"));
172
$smarty->assign("trustmode", $trustmode);
173
$smarty->assign("trustmodes", array( 0 => _("disabled"), 1 => _("full access"),
174
2 => _("allow access to these hosts")));
177
if((count($this->accessTo))==0)
178
$smarty->assign("emptyArrAccess",true);
180
$smarty->assign("emptyArrAccess",false);
183
$smarty->assign($smarty->assign("use_trustmode",in_array_strict("trustmode", $this->multi_boxes)));
184
$smarty->assign("multiple_support" , $this->multiple_support_active);
185
# $this->trustList->update();
186
$smarty->assign("trustList", $this->trustList->render());
187
return($smarty->fetch(get_template_path("generic.tpl",TRUE, dirname(__FILE__))));
190
public function save_object()
193
/* Trust mode - special handling */
194
if(preg_match("/w/", $this->getacl("accessTo"))){
195
if (isset($_POST['trustmode'])){
196
$saved= $this->trustModel;
197
if ($_POST['trustmode'] == "1"){
198
$this->trustModel= "fullaccess";
199
} elseif ($_POST['trustmode'] == "2"){
200
$this->trustModel= "byhost";
202
$this->trustModel= "";
204
if ($this->trustModel != $saved){
205
$this->is_modified= TRUE;
212
public function save()
217
$objectclasses= array();
218
foreach ($this->attrs['objectClass'] as $key => $class){
219
if (preg_match('/trustAccount/i', $class)){
222
$objectclasses[]= $this->attrs['objectClass'][$key];
224
$this->attrs['objectClass']= $objectclasses;
225
if ($this->trustModel != ""){
226
$this->attrs['objectClass'][]= "trustAccount";
227
$this->attrs['trustModel']= $this->trustModel;
228
$this->attrs['accessTo']= array();
229
if ($this->trustModel == "byhost"){
230
foreach ($this->accessTo as $host){
231
$this->attrs['accessTo'][]= $host;
235
if ($this->initially_was_account){
236
$this->attrs['accessTo']= array();
237
$this->attrs['trustModel']= array();
240
$ldap = $this->config->get_ldap_link();
241
$ldap->cd($this->dn);
243
$ldap->modify($this->attrs);
245
/* Log last action */
246
if($this->initially_was_account){
247
new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
249
new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
252
if (!$ldap->success()){
253
msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(),
254
$this->dn, LDAP_MOD,get_class()));
258
public function get_multi_edit_values()
260
$ret = plugin::get_multi_edit_values();
261
if(in_array_strict("trustmode",$this->multi_boxes)){
262
$ret['trustModel'] = $this->trustModel;
263
$ret['accessTo'] = $this->accessTo;
268
public function multiple_save_object()
270
plugin::multiple_save_object();
271
if(isset($_POST["use_trustmode"])){
272
$this->multi_boxes[] = "trustmode";
275
if(preg_match("/w/", $this->getacl("accessTo"))){
276
if (isset($_POST['trustmode'])){
277
$saved= $this->trustModel;
278
if ($_POST['trustmode'] == "1"){
279
$this->trustModel= "fullaccess";
280
} elseif ($_POST['trustmode'] == "2"){
281
$this->trustModel= "byhost";
283
$this->trustModel= "";
285
if ($this->trustModel != $saved){
286
$this->is_modified= TRUE;
292
public function init_multiple_support($attrs,$all)
294
plugin::init_multiple_support($attrs,$all);
296
if (isset($this->multi_attrs['trustModel'])){
297
$this->trustModel= $this->multi_attrs['trustModel'][0];
298
$this->initially_was_account= TRUE;
299
$this->multi_boxes[] = "trustmode";
301
$this->initially_was_account= FALSE;
302
$this->trustModel= "";
305
$this->accessTo = array();
306
if (isset($this->multi_attrs['accessTo'])){
307
for ($i= 0; $i<$this->multi_attrs['accessTo']['count']; $i++){
308
$tmp= $this->multi_attrs['accessTo'][$i];
309
$this->accessTo[$tmp]= $tmp;
312
$this->trustList->setListData($this->accessTo);
316
public function getacl($attribute,$skip_write= FALSE)
319
$skip_write |= $this->read_only;
320
return $ui->get_permissions($this->acl_base,$this->acl, $attribute,$skip_write);