~ubuntu-branches/ubuntu/quantal/gosa/quantal

« back to all changes in this revision

Viewing changes to .pc/smarty3.patch/gosa-core/plugins/personal/posix/trustModeDialog/class_trustModeDialog.inc

  • Committer: Package Import Robot
  • Author(s): Cajus Pollmeier
  • Date: 2012-06-19 09:36:39 UTC
  • mfrom: (7.2.16 sid)
  • Revision ID: package-import@ubuntu.com-20120619093639-uxhp7dk39opb2ygk
Tags: 2.7.4-4
New smarty3 package fixes problems with template loading. This
release removes the workarounds for that issue.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
class trustModeDialog extends plugin 
 
4
{
 
5
    public $attributes  = array("accessTo","trustModel");
 
6
    public $accessTo    = array();
 
7
    public $trustModel  = "";
 
8
    public $trustSelect = NULL;
 
9
 
 
10
    private $trustList = NULL;
 
11
 
 
12
    function __construct(&$config, $dn, $parent = NULL)
 
13
    {
 
14
        plugin::plugin($config, $dn, $parent);
 
15
 
 
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;
 
26
                }
 
27
            }
 
28
 
 
29
        }
 
30
 
 
31
        $this->initially_was_account = $this->is_account;
 
32
 
 
33
        $lData = array();
 
34
        foreach($this->accessTo as $key => $cn){
 
35
            $lData[$cn] = array('data' => $this->converCnToType($cn));
 
36
        }
 
37
 
 
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);
 
47
 
 
48
    }
 
49
 
 
50
    public function PrepareForCopyPaste($source)
 
51
    {
 
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;
 
62
                }
 
63
            }
 
64
        }
 
65
    }
 
66
 
 
67
    public function converCnToType($cn)
 
68
    {
 
69
        if(isset($this->typeCache[$cn])){
 
70
            return($this->typeCache[$cn]);
 
71
        }
 
72
 
 
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();
 
80
            $img = $desc = "";
 
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'); 
 
87
            }
 
88
            if(isset($attrs['description'][0])) {
 
89
                $desc = $attrs['description'][0];
 
90
            }
 
91
            $this->typeCache[$cn] = array($img,$cn,$desc);
 
92
        }
 
93
        return($this->typeCache[$cn]);
 
94
    }
 
95
 
 
96
    public function setAcl($acl)
 
97
    {
 
98
        $this->acl = $acl;
 
99
    }
 
100
 
 
101
    public function execute()
 
102
    {
 
103
        // Call parent
 
104
        plugin::execute();
 
105
 
 
106
        $this->trustList->setAcl($this->getacl("accessTo"));
 
107
        $this->trustList->save_object();
 
108
 
 
109
        // Allow to select trusted machines from a list
 
110
        if (isset($_POST["add_ws"])){
 
111
            $this->trustSelect= new trustSelect($this->config,get_userinfo());
 
112
            $this->dialog= TRUE;
 
113
        }
 
114
 
 
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;
 
120
        }
 
121
 
 
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)), 
 
133
                            $attrs['cn'][0]);
 
134
                }
 
135
                $this->is_modified= TRUE;
 
136
                $this->trustList->update();
 
137
            }
 
138
            $this->trustSelect= NULL;
 
139
            $this->dialog= FALSE;
 
140
        }
 
141
 
 
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;
 
147
        }
 
148
 
 
149
 
 
150
        if ($this->trustSelect){
 
151
            session::set('filterBlacklist', array('cn' => array_values($this->accessTo)));
 
152
            return($this->trustSelect->execute());
 
153
        }
 
154
 
 
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"){
 
160
            $trustmode= 1;
 
161
            // pervent double disable tag in html code, this will disturb our clean w3c html
 
162
            $smarty->assign("trustmode",  $this->getacl("accessTo"));
 
163
 
 
164
        } elseif ($this->trustModel == "byhost"){
 
165
            $trustmode= 2;
 
166
            $smarty->assign("trusthide", "");
 
167
        } else {
 
168
            // pervent double disable tag in html code, this will disturb our clean w3c html
 
169
            $smarty->assign("trustmode",  $this->getacl("accessTo"));
 
170
            $trustmode= 0;
 
171
        }
 
172
        $smarty->assign("trustmode", $trustmode);
 
173
        $smarty->assign("trustmodes", array( 0 => _("disabled"), 1 => _("full access"),
 
174
                    2 => _("allow access to these hosts")));
 
175
 
 
176
 
 
177
        if((count($this->accessTo))==0)
 
178
            $smarty->assign("emptyArrAccess",true);
 
179
        else
 
180
            $smarty->assign("emptyArrAccess",false);
 
181
 
 
182
 
 
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__))));
 
188
    }
 
189
 
 
190
    public function save_object()
 
191
    {
 
192
 
 
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";
 
201
                } else {
 
202
                    $this->trustModel= "";
 
203
                }
 
204
                if ($this->trustModel != $saved){
 
205
                    $this->is_modified= TRUE;
 
206
                }
 
207
            }
 
208
        }
 
209
 
 
210
    }
 
211
 
 
212
    public function save()
 
213
    {
 
214
        plugin::save();
 
215
 
 
216
        /* Trust accounts */
 
217
        $objectclasses= array();
 
218
        foreach ($this->attrs['objectClass'] as $key => $class){
 
219
            if (preg_match('/trustAccount/i', $class)){
 
220
                continue;
 
221
            }
 
222
            $objectclasses[]= $this->attrs['objectClass'][$key];
 
223
        }
 
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;
 
232
                }
 
233
            }
 
234
        } else {
 
235
            if ($this->initially_was_account){
 
236
                $this->attrs['accessTo']= array();
 
237
                $this->attrs['trustModel']= array();
 
238
            }
 
239
        }
 
240
        $ldap = $this->config->get_ldap_link();
 
241
        $ldap->cd($this->dn);
 
242
        $this->cleanup();
 
243
        $ldap->modify($this->attrs);
 
244
 
 
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());
 
248
        }else{
 
249
            new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
 
250
        }
 
251
 
 
252
        if (!$ldap->success()){
 
253
            msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), 
 
254
                        $this->dn, LDAP_MOD,get_class()));
 
255
        }
 
256
    }
 
257
 
 
258
    public function get_multi_edit_values()
 
259
    {
 
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;
 
264
        }
 
265
        return($ret);
 
266
    }
 
267
 
 
268
    public function multiple_save_object()
 
269
    {
 
270
        plugin::multiple_save_object();
 
271
        if(isset($_POST["use_trustmode"])){
 
272
            $this->multi_boxes[] = "trustmode";
 
273
        }
 
274
 
 
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";
 
282
                } else {
 
283
                    $this->trustModel= "";
 
284
                }
 
285
                if ($this->trustModel != $saved){
 
286
                    $this->is_modified= TRUE;
 
287
                }
 
288
            }
 
289
        }
 
290
    }
 
291
 
 
292
    public function init_multiple_support($attrs,$all)
 
293
    {
 
294
        plugin::init_multiple_support($attrs,$all);
 
295
 
 
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";
 
300
        } else {
 
301
            $this->initially_was_account= FALSE;
 
302
            $this->trustModel= "";
 
303
        }
 
304
 
 
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;
 
310
            }
 
311
        }
 
312
        $this->trustList->setListData($this->accessTo);
 
313
    }
 
314
 
 
315
 
 
316
    public function getacl($attribute,$skip_write= FALSE)
 
317
    {
 
318
        $ui= get_userinfo();
 
319
        $skip_write |= $this->read_only;
 
320
        return  $ui->get_permissions($this->acl_base,$this->acl, $attribute,$skip_write);
 
321
    }
 
322
 
 
323
 
 
324
 
325
 
 
326
 
 
327
 
 
328
?>