90ab341e1632c5ee552fda382a9ababb82a3c64a
1 <?php
3 class sudoldapEditRole extends plugin
4 {
5 /* Plugin specific values */
6 var $attributes = array("cn",
7 "description",
8 "sudoUser",
9 "sudoHost",
10 "sudoCommand",
11 "sudoRunAs",
12 "sudoOption");
14 var $objectclasses = array("sudoRole");
16 var $cn = "";
17 var $description = "";
18 var $sudoUser = "";
19 var $sudoHost = "";
20 var $sudoCommand = "";
21 var $sudoRunAs = "";
22 var $sudoOption = "";
24 var $isNew = true;
26 function sudoldapEditRole ($config, $dn= NULL, $attrs = array())
27 {
28 plugin::plugin ($config, $dn);
30 if(!count($attrs)){
31 $this->isNew = true;
32 }else{
33 $this->isNew = false;
34 foreach($this->attributes as $value){
35 if(isset($attrs[$value])){
36 $this->$value = $attrs[$value];
37 }
38 }
39 }
40 }
42 function execute()
43 {
44 /* Call parent execute */
45 plugin::execute();
48 /* Fill templating stuff */
49 $smarty= get_smarty();
50 $display= "";
52 $smarty->assign("cn", $this->cn);
53 $smarty->assign("description", $this->description);
54 $smarty->assign("sudoUser", $this->sudoUser);
55 $smarty->assign("sudoHost", $this->sudoHost);
56 $smarty->assign("sudoCommand", $this->sudoCommand);
57 $smarty->assign("sudoRunAs", $this->sudoRunAs);
58 $smarty->assign("sudoOption", $this->sudoOption);
60 /* Display template */
61 $display.= $smarty->fetch(
62 get_template_path('sudoldapeditrole.tpl', TRUE));
63 return($display);
64 }
66 /* Save data to object */
67 function save_object()
68 {
69 //plugin::save_object();
70 foreach($this->attributes as $attr){
71 if(isset($_POST[$attr])){
72 $this->$attr = $_POST[$attr];
73 }
74 }
75 }
78 /* Check supplied data */
79 function check()
80 {
81 }
84 /* Save to LDAP */
85 function save()
86 {
87 plugin::save();
88 $ldap= $this->config->get_ldap_link();
90 $this->dn = "cn=".$this->cn.",ou=SUDOers,".$this->config->current['BASE'];
91 $this->attrs['objectClass'] = array("sudoRole");
93 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
94 $ldap->cd($this->dn);
95 $ldap->add($this->attrs);
97 /* Display errors
98 */
99 if($ldap->get_error() != "Success"){
100 show_ldap_error("Record:".$ldap->get_error(), _("Saving failed!"));
101 }
103 }
106 }
108 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
109 ?>