8b49ea30bd3623605a2325854b706235422700f7
1 <?php
3 class goKioskService extends goService{
5 /* This plugin only writes its objectClass */
6 var $objectclasses = array("goEnvironmentServer");
7 var $attributes = array("gotoKioskProfile");
8 var $StatusFlag = "";
10 /* This class can't be assigned twice so it conflicts with itsself */
11 var $conflicts = array("goKioskService");
13 var $baseDir = "../kiosk";
14 var $filesToAttach = array();
15 var $cn = "unknown";
16 var $orig_cn = "unknown";
17 var $gotoKioskProfiles= array();
18 var $gotoKioskProfile = array();
19 var $server_path = "http://%cn/kiosk";
21 function goKioskService(&$config, $dn, $parent)
22 {
23 goService::goService($config,$dn);
25 /* Get the current object name.
26 */
27 if(isset($parent->parent->cn)){
28 $this->cn = &$parent->parent->cn;
29 }elseif(isset($this->attrs['cn'][0])){
30 $this->cn = $this->attrs['cn'][0];
31 }
32 $this->orig_cn = $this->cn;
34 $this->DisplayName = _("Kiosk profile service");
35 $this->baseDir = $this->config->get_cfg_value('environment', 'kioskPath');
36 $this->server_path = preg_replace("/%cn/", $this->cn, $this->server_path);
38 /* Load list of profiles and check if they still exists */
39 if ($this->baseDir == ""){
40 }else{
41 $this->gotoKioskProfiles = array();
42 if(isset($this->attrs['gotoKioskProfile']) && is_array($this->attrs['gotoKioskProfile'])){
43 for($i = 0 ; $i < $this->attrs['gotoKioskProfile']['count']; $i ++){
44 $url = $this->attrs['gotoKioskProfile'][$i];
45 $this->server_path = preg_replace("/\/[^\/]*$/","",$url);
46 $name= preg_replace("/^.*\//","",$url);
47 $this->gotoKioskProfiles[] = array('url' => $url ,
48 'name' => $name ,
49 'initial' =>TRUE,
50 'exists' => file_exists($this->baseDir."/".$name));
51 }
52 }
53 }
55 // Prepare lists
56 $this->kioskList = new sortableListing();
57 $this->kioskList->setDeleteable(true);
58 $this->kioskList->setInstantDelete(true);
59 $this->kioskList->setEditable(true);
60 $this->kioskList->setWidth("100%");
61 $this->kioskList->setHeight("200px");
62 $this->kioskList->setHeader(array(_("Profile")));
63 $this->kioskList->setColspecs(array('*','40px'));
64 $this->kioskList->setDefaultSortColumn(0);
65 }
68 function remove_from_parent()
69 {
70 $ldap = $this->config->get_ldap_link();
71 $ldap->cd($this->config->current['BASE']);
72 $ldap->search("(&(objectClass=gotoEnvironment)(gotoKioskProfile=*/".$this->orig_cn."/*))",array("cn"));
73 if ($ldap->count() != 0){
74 $obj= array();
75 while($attrs = $ldap->fetch()){
76 $obj[$ldap->getDN()]= $attrs['cn'][0];
77 }
78 msg_dialog::display(_("Error"), msgPool::stillInUse(_("Kiosk profile service"), msgPool::buildList($obj)), ERROR_DIALOG);
79 }else{
80 goService::remove_from_parent();
81 }
82 }
85 function execute()
86 {
87 /* log actions */
88 if($this->is_account && !$this->view_logged){
89 $this->view_logged = TRUE;
90 new log("view","server/".get_class($this),$this->dn);
91 }
93 /* Fill templating stuff */
94 $smarty= get_smarty();
95 $smarty->assign("baseDir", set_post($this->baseDir));
96 $smarty->assign("ThisACL", set_post($this->getacl("")));
97 $display= "";
99 /* Download kiosk profile
100 */
101 $this->kioskList->save_object();
102 $action = $this->kioskList->getAction();
103 if($action['action'] == 'edit'){
104 $id = $this->kioskList->getKey($action['targets'][0]);
105 foreach($this->gotoKioskProfiles as $profile){
106 $name = $this->baseDir."/".$this->gotoKioskProfiles[$id]['name'];
107 if(file_exists($name)){
108 $content = file_get_contents($name);
109 send_binary_content($content,$this->gotoKioskProfiles[$id]['name']);
110 }else{
111 msg_dialog::display(_("Warning"), sprintf(_("The profile does not exists '%s'!"),
112 $this->gotoKioskProfiles[$id]['name']), ERROR_DIALOG);
113 }
114 }
115 }
118 /* Add new kiosk profile
119 * in profile directory ($this->baseDir);
120 */
121 if((isset($_POST['profileAdd']))&&(isset($_FILES['newProfile'])) && $this->acl_is_writeable("")){
122 $file = $_FILES['newProfile'];
123 if(!file_exists($this->baseDir.$file['name'])){
124 $filename = gosa_file_name($file['tmp_name']);
125 $tmp = array(
126 'url' => "" ,
127 'name' => $file['name'] ,
128 'initial' => FALSE,
129 'tmp_name'=> $filename,
130 'content' => file_get_contents($filename),
131 'exists' => TRUE);
134 $used = array();
135 foreach($this->gotoKioskProfiles as $k){
136 $used[] = $k['name'];
137 }
138 if(in_array($file['name'], $used)){
139 msg_dialog::display(_("Warning"), msgPool::duplicated(_("Profile")), WARNING_DIALOG);
140 }else{
141 $this->gotoKioskProfiles[] = $tmp;
142 }
143 }
144 }
146 if($action['action'] == 'delete' && $this->acl_is_writeable("")){
147 $id = $this->kioskList->getKey($action['targets'][0]);
148 $name = $this->gotoKioskProfiles[$id]['name'];
149 $filename = $this->baseDir."/".$name;
151 /* check if profile is still in use */
152 $ldap = $this->config->get_ldap_link();
153 $ldap->cd($this->config->current['BASE']);
154 $ldap->search("(&(objectClass=gotoEnvironment)(gotoKioskProfile=*".$name.")",array("cn","uid","gotoKioskProfile"));
156 if ($ldap->count() != 0){
158 $obj= array();
159 $found= false;
160 while(($attrs = $ldap->fetch()) && ($cnt)){
161 $check = preg_replace("/^.*\//i","",$attrs['gotoKioskProfile'][0]);
162 if($check == $name){
163 $obj[$ldap->getDN()]= $attrs['cn'][0];
164 $found= true;
165 }
166 }
168 if ($found){
169 msg_dialog::display(_("Error"), msgPool::stillInUse(_("Kiosk profile"),
170 msgPool::buildList($obj)), ERROR_DIALOG);
171 }
172 }else{
173 if($this->gotoKioskProfiles[$id]['initial']){
174 $res = @unlink($filename);
175 if(!$res){
176 if(!is_writeable($filename)){
177 msg_dialog::display(_("Error"), msgPool::cannotDeleteFile($filename), ERROR_DIALOG);
178 }
179 if(!file_exists($filename)){
180 msg_dialog::display(_("Error"), msgPool::fileDoesNotExist($filename), ERROR_DIALOG);
181 }
182 }
183 unset($this->gotoKioskProfiles[$id]);
184 }
185 }
186 }
188 /* Display list of profiles */
189 $this->kioskList->setAcl($this->getacl(""));
190 $lData = array();
191 foreach($this->gotoKioskProfiles as $key => $val ){
192 $lData[$key] = array('data' => array($val['name']));
193 }
194 $this->kioskList->setListData($this->gotoKioskProfiles, $lData);
195 $this->kioskList->update();
197 /* Assign all existing profiles to smarty */
198 $smarty->assign("kioskList",$this->kioskList->render());
199 $smarty = get_smarty();
200 foreach($this->attributes as $attr){
201 $smarty->assign($attr, set_post($this->$attr));
202 }
203 $smarty->assign("server_path", set_post($this->server_path));
204 return($smarty->fetch(get_template_path("goKioskService.tpl",TRUE,dirname(__FILE__))));
205 }
209 function getListEntry()
210 {
211 $fields = goService::getListEntry();
212 $fields['Message'] = _("Kiosk profile service");
213 #$fields['AllowEdit'] = TRUE;
214 #$fields['AllowStart'] = false;
215 #$fields['AllowStop'] = false;
216 #$fields['AllowRestart'] = false;
217 return($fields);
218 }
220 function check()
221 {
222 $message = plugin::check();
223 return($message);
224 }
226 function save()
227 {
228 goService::save();
230 $method = $this->server_path."/";
231 $method = preg_replace("/\/\/*$/","/",$method);
232 $this->attrs['gotoKioskProfile'] = array();
233 foreach($this->gotoKioskProfiles as $profile){
234 if(!$profile['initial']){
236 $contents = $profile['content'];
237 $path = $this->baseDir."/".$profile['name'];
238 $fp = @fopen($path,"w");
239 if(!$fp){
240 msg_dialog::display(_("Error"), msgPool::cannotWriteFile($path), ERROR_DIALOG);
241 }else{
242 fwrite($fp,$contents,strlen($contents));
243 $this->attrs['gotoKioskProfile'][] = $method.$profile['name'];
244 }
245 @unlink($profile['tmp_name']);
246 }else{
247 $this->attrs['gotoKioskProfile'][] = $method.$profile['name'];
248 }
249 }
250 $ldap = $this->config->get_ldap_link();
251 $ldap->cd($this->config->current['BASE']);
252 $ldap->cd($this->dn);
253 $ldap->modify($this->attrs);
254 if (!$ldap->success()){
255 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
256 }
257 }
260 function save_object()
261 {
262 if(isset($_POST['goKioskPosted'])){
263 goService::save_object();
264 if(isset($_POST['server_path'])){
265 $this->server_path = get_post("server_path");
266 }
267 }
268 }
271 /* Return plugin informations for acl handling */
272 static function plInfo()
273 {
274 return (array(
275 "plShortName" => _("Kiosk"),
276 "plDescription" => _("Kiosk profile management")." ("._("Services").")",
277 "plSelfModify" => FALSE,
278 "plDepends" => array(),
279 "plPriority" => 100,
280 "plSection" => array("administration"),
281 "plCategory" => array("server"),
282 "plRequirements"=> array(
283 'ldapSchema' => array('goEnvironmentServer' => '>=2.7'),
284 'onFailureDisablePlugin' => array(get_class())
285 ),
287 "plProvidedAcls"=> array()
288 ));
289 }
290 }
291 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
292 ?>