07a8db4d63e374c2fd59545a112193564ec838ee
1 <?php
3 class trustModeDialog extends plugin
4 {
5 public $attributes = array("accessTo","trustModel");
6 public $accessTo = array();
7 public $trustModel = "";
8 public $trustSelect = NULL;
10 function __construct(&$config, $dn, $parent = NULL)
11 {
12 plugin::plugin($config, $dn, $parent);
14 $this->accessTo = array();
15 $this->trustModel= "";
16 $this->is_account = FALSE;
17 if(isset($this->attrs['trustModel'][0])){
18 $this->is_account = TRUE;
19 $this->trustModel= $this->attrs['trustModel'][0];
20 if (isset($this->attrs['accessTo'])){
21 for ($i= 0; $i<$this->attrs['accessTo']['count']; $i++){
22 $tmp= $this->attrs['accessTo'][$i];
23 $this->accessTo[$tmp]= $tmp;
24 }
25 }
27 }
28 $this->initially_was_account = $this->is_account;
30 }
32 public function setAcl($acl)
33 {
34 $this->acl = $acl;
35 }
37 public function execute()
38 {
39 // Call parent
40 plugin::execute();
42 // Allow to select trusted machines from a list
43 if (isset($_POST["add_ws"])){
44 $this->trustSelect= new trustSelect($this->config,get_userinfo());
45 $this->dialog= TRUE;
46 }
48 // Cancel trust and group dialog
49 if (isset($_POST['add_ws_cancel'])){
50 $this->groupSelect= NULL;
51 $this->trustSelect= NULL;
52 $this->dialog= FALSE;
53 }
55 // Add selected machines to trusted ones.
56 if (isset($_POST["add_ws_finish"]) && $this->trustSelect){
57 $trusts = $this->trustSelect->detectPostActions();
58 if(isset($trusts['targets'])){
59 $headpage = $this->trustSelect->getHeadpage();
60 foreach($trusts['targets'] as $id){
61 $attrs = $headpage->getEntry($id);
62 $this->accessTo[$attrs['cn'][0]]= $attrs['cn'][0];
63 }
64 ksort($this->accessTo);
65 $this->is_modified= TRUE;
66 }
67 $this->trustSelect= NULL;
68 $this->dialog= FALSE;
69 }
71 // Remove machine from trusted ones.
72 if (isset($_POST["delete_ws"]) && isset($_POST['workstation_list'])){
73 foreach($_POST['workstation_list'] as $name){
74 unset ($this->accessTo[$name]);
75 }
76 $this->is_modified= TRUE;
77 }
80 if ($this->trustSelect){
81 session::set('filterBlacklist', array('cn' => array_values($this->accessTo)));
82 return($this->trustSelect->execute());
83 }
85 /* Work on trust modes */
86 $smarty = get_smarty();
87 $smarty->assign("trusthide", " disabled ");
88 $smarty->assign("trustmodeACL", $this->getacl("accessTo"));
89 if ($this->trustModel == "fullaccess"){
90 $trustmode= 1;
91 // pervent double disable tag in html code, this will disturb our clean w3c html
92 $smarty->assign("trustmode", $this->getacl("accessTo"));
94 } elseif ($this->trustModel == "byhost"){
95 $trustmode= 2;
96 $smarty->assign("trusthide", "");
97 } else {
98 // pervent double disable tag in html code, this will disturb our clean w3c html
99 $smarty->assign("trustmode", $this->getacl("accessTo"));
100 $trustmode= 0;
101 }
102 $smarty->assign("trustmode", $trustmode);
103 $smarty->assign("trustmodes", array( 0 => _("disabled"), 1 => _("full access"),
104 2 => _("allow access to these hosts")));
107 if((count($this->accessTo))==0)
108 $smarty->assign("emptyArrAccess",true);
109 else
110 $smarty->assign("emptyArrAccess",false);
112 $smarty->assign("accessTo",$this->accessTo);
114 $smarty->assign($smarty->assign("use_trustmode",in_array("trustmode", $this->multi_boxes)));
115 $smarty->assign("multiple_support" , $this->multiple_support_active);
116 return($smarty->fetch(get_template_path("generic.tpl",TRUE, dirname(__FILE__))));
117 }
119 public function save_object()
120 {
122 /* Trust mode - special handling */
123 if(preg_match("/w/", $this->getacl("accessTo"))){
124 if (isset($_POST['trustmode'])){
125 $saved= $this->trustModel;
126 if ($_POST['trustmode'] == "1"){
127 $this->trustModel= "fullaccess";
128 } elseif ($_POST['trustmode'] == "2"){
129 $this->trustModel= "byhost";
130 } else {
131 $this->trustModel= "";
132 }
133 if ($this->trustModel != $saved){
134 $this->is_modified= TRUE;
135 }
136 }
137 }
139 }
141 public function save()
142 {
143 plugin::save();
145 /* Trust accounts */
146 $objectclasses= array();
147 foreach ($this->attrs['objectClass'] as $key => $class){
148 if (preg_match('/trustAccount/i', $class)){
149 continue;
150 }
151 $objectclasses[]= $this->attrs['objectClass'][$key];
152 }
153 $this->attrs['objectClass']= $objectclasses;
154 if ($this->trustModel != ""){
155 $this->attrs['objectClass'][]= "trustAccount";
156 $this->attrs['trustModel']= $this->trustModel;
157 $this->attrs['accessTo']= array();
158 if ($this->trustModel == "byhost"){
159 foreach ($this->accessTo as $host){
160 $this->attrs['accessTo'][]= $host;
161 }
162 }
163 } else {
164 if ($this->initially_was_account){
165 $this->attrs['accessTo']= array();
166 $this->attrs['trustModel']= array();
167 }
168 }
169 $ldap = $this->config->get_ldap_link();
170 $ldap->cd($this->dn);
171 $this->cleanup();
172 $ldap->modify($this->attrs);
173 echo $ldap->get_error();
174 }
176 public function get_multi_edit_values()
177 {
178 $ret = plugin::get_multi_edit_values();
179 if(in_array("trustmode",$this->multi_boxes)){
180 $ret['trustModel'] = $this->trustModel;
181 $ret['accessTo'] = $this->accessTo;
182 }
183 return($ret);
184 }
186 public function multiple_save_object()
187 {
188 plugin::multiple_save_object();
189 if(isset($_POST["use_trustmode"])){
190 $this->multi_boxes[] = "trustmode";
191 }
193 if(preg_match("/w/", $this->getacl("accessTo"))){
194 if (isset($_POST['trustmode'])){
195 $saved= $this->trustModel;
196 if ($_POST['trustmode'] == "1"){
197 $this->trustModel= "fullaccess";
198 } elseif ($_POST['trustmode'] == "2"){
199 $this->trustModel= "byhost";
200 } else {
201 $this->trustModel= "";
202 }
203 if ($this->trustModel != $saved){
204 $this->is_modified= TRUE;
205 }
206 }
207 }
208 }
210 public function init_multiple_support($attrs,$all)
211 {
212 plugin::init_multiple_support($attrs,$all);
214 if (isset($this->multi_attrs['trustModel'])){
215 $this->trustModel= $this->multi_attrs['trustModel'][0];
216 $this->initially_was_account= TRUE;
217 $this->multi_boxes[] = "trustmode";
218 } else {
219 $this->initially_was_account= FALSE;
220 $this->trustModel= "";
221 }
223 $this->accessTo = array();
224 if (isset($this->multi_attrs['accessTo'])){
225 for ($i= 0; $i<$this->multi_attrs['accessTo']['count']; $i++){
226 $tmp= $this->multi_attrs['accessTo'][$i];
227 $this->accessTo[$tmp]= $tmp;
228 }
229 }
231 }
234 public function getacl($attribute,$skip_write= FALSE)
235 {
236 $ui= get_userinfo();
237 $skip_write |= $this->read_only;
238 return $ui->get_permissions($this->acl_base,$this->acl, $attribute,$skip_write);
239 }
242 }
246 ?>