1 <?php
3 class goKioskService extends goService{
5 /* This plugin only writes its objectClass */
6 var $objectclasses = array("goEnvironmentServer");
7 var $attributes = array("gotoKioskProfile","cn");
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 $gotoKioskProfiles= array();
17 var $gotoKioskProfile = array();
19 var $server_path = "http://%cn/kiosk";
21 function goKioskService(&$config,$dn)
22 {
23 goService::goService($config,$dn);
25 $this->DisplayName = _("Kiosk profile service");
26 $this->baseDir = $this->config->search('environment', 'kioskpath',array('menu','tabs'));
27 $this->server_path = preg_replace("/%cn/", $this->cn, $this->server_path);
29 /* Load list of profiles and check if they still exists */
30 if ($this->baseDir == ""){
31 print_red(_("There is no KIOSKPATH defined in your gosa.conf. Can't manage kiosk profiles!"));
32 }else{
33 $this->gotoKioskProfiles = array();
34 if(isset($this->attrs['gotoKioskProfile']) && is_array($this->attrs['gotoKioskProfile'])){
35 for($i = 0 ; $i < $this->attrs['gotoKioskProfile']['count']; $i ++){
36 $url = $this->attrs['gotoKioskProfile'][$i];
37 $this->server_path = preg_replace("/\/[^\/]*$/","",$url);
38 $name= preg_replace("/^.*\//","",$url);
39 $this->gotoKioskProfiles[] = array('url' => $url ,
40 'name' => $name ,
41 'initial' =>TRUE,
42 'exists' => file_exists($this->baseDir."/".$name));
43 }
44 }
45 }
46 }
49 function remove_from_parent()
50 {
51 $ldap = $this->config->get_ldap_link();
52 $ldap->cd($this->config->current['BASE']);
53 $ldap->search("(&(objectClass=gotoEnvironment)(gotoKioskProfile=*/".$this->cn."/*))",array("cn"));
54 $str ="";
55 $cnt = 3;
56 while($cnt && $attrs = $ldap->fetch()){
57 $str .= $attrs['cn'][0].", ";
58 $cnt --;
59 }
60 $str = preg_replace("/, $/","",$str);
61 if($cnt != 3){
62 print_red(sprintf(_("Can not remove kiosk profile service, it is currently in use by following user(s) : %s."),$str));
63 }else{
64 goService::remove_from_parent();
65 }
66 }
69 function execute()
70 {
71 /* log actions */
72 if($this->is_account && !$this->view_logged){
73 $this->view_logged = TRUE;
74 new log("view","server/".get_class($this),$this->dn);
75 }
77 /* Fill templating stuff */
78 $smarty= get_smarty();
79 $display= "";
81 /* Download kiosk profile
82 */
83 if(isset($_GET['getkiosk'])){
84 $id = $_GET['getkiosk'];
85 foreach($this->gotoKioskProfiles as $profile){
86 if($profile['name'] == $id){
87 $name = $this->baseDir."/".$id;
88 if(file_exists($name)){
89 $content = file_get_contents($name);
90 send_binary_content($content,$id);
91 }
92 }
93 }
94 }
97 /* Add new kiosk profile
98 * in profile directory ($this->baseDir);
99 */
100 if((isset($_POST['profileAdd']))&&(isset($_FILES['newProfile']))){
101 $file = $_FILES['newProfile'];
102 if(!file_exists($this->baseDir.$file['name'])){
103 $tmp = array(
104 'url' => "" ,
105 'name' => $file['name'] ,
106 'initial' => FALSE,
107 'tmp_name'=> $file['tmp_name'],
108 'content' => file_get_contents($file['tmp_name']),
109 'exists' => TRUE);
110 $this->gotoKioskProfiles[] = $tmp;
111 }
112 if(!is_writeable($this->baseDir)){
113 print_red(sprintf(_("Can't save new kiosk profiles, possibly permission denied for folder: '%s'."),$this->baseDir));
114 }
115 }
117 $only_once = true;
118 foreach($_POST as $name => $value){
120 if((preg_match("/^delkiosk_/",$name))&&($only_once)){
122 /* Get id, name and path */
123 $only_once = false;
124 $id = preg_replace("/^delkiosk_/","",$name);
125 $id = preg_replace("/_.*$/","",$id);
126 $name = $this->gotoKioskProfiles[$id]['name'];
127 $filename = $this->baseDir."/".$name;
129 /* check if profile is still in use */
130 $ldap = $this->config->get_ldap_link();
131 $ldap->cd($this->config->current['BASE']);
132 $ldap->search("(&(objectClass=gotoEnvironment)(gotoKioskProfile=*".$name.")",array("cn","uid","gotoKioskProfile"));
133 $used_by = "";
134 $cnt = 3;
135 while(($attrs = $ldap->fetch()) && ($cnt)){
136 $cnt --;
137 $check = preg_replace("/^.*\//i","",$attrs['gotoKioskProfile'][0]);
138 if($check == $name){
139 $used_by .= $attrs['cn'][0].", ";
140 }
141 }
142 $used_by = preg_replace("/, $/","",$used_by);
143 if(!empty($used_by)){
144 print_red(sprintf(_("Can't remove kioks profile, it is still in use by the following objects '%s'."),$used_by));
145 }else{
146 if($this->gotoKioskProfiles[$id]['initial']){
147 $res = @unlink($filename);
148 if(!$res){
149 if(!is_writeable($filename)){
150 print_red(sprintf(_("Can't delete '%s'. Error was: permission denied."), $filename));
151 }
152 if(!file_exists($filename)){
153 print_red(sprintf(_("Can't delete '%s'. Error was: file doesn't exist."), $filename));
154 }
155 }
156 unset($this->gotoKioskProfiles[$id]);
157 }
158 }
159 }
160 }
162 /* Display list of profiles */
163 $divlist = new divSelectBox("KioskProfiles");
164 $divlist -> SetHeight (300);
165 foreach($this->gotoKioskProfiles as $key => $val ){
166 $divlist->AddEntry(array(
167 array("string"=>"<a href='?plug=".$_GET['plug']."&getkiosk=".$val['name']."'>".$val['name']."</a>"),
168 array("string"=>"<input type='image' src='images/edittrash.png'
169 class='center' alt='delete' name='delkiosk_".$key."'>" ,
170 "attach"=>" style='border-right: 0px;width:24px; text-align:center;' ")
171 ));
172 }
174 /* Assign all existing profiles to smarty */
175 $smarty->assign("divlist",$divlist->DrawList());
176 $smarty = get_smarty();
177 foreach($this->attributes as $attr){
178 $smarty->assign($attr,$this->$attr);
179 }
180 $smarty->assign("server_path",$this->server_path);
181 return($smarty->fetch(get_template_path("goKioskService.tpl",TRUE,dirname(__FILE__))));
182 }
186 function getListEntry()
187 {
188 $fields = goService::getListEntry();
189 $fields['Message'] = _("Kiosk profile service");
190 $fields['AllowEdit'] = TRUE;
191 $fields['AllowStart'] = false;
192 $fields['AllowStop'] = false;
193 $fields['AllowRestart'] = false;
194 return($fields);
195 }
197 function check()
198 {
199 $message = plugin::check();
200 return($message);
201 }
203 function save()
204 {
205 goService::save();
207 $method = $this->server_path."/";
208 $method = preg_replace("/\/\/*$/","/",$method);
209 $this->attrs['gotoKioskProfile'] = array();
210 foreach($this->gotoKioskProfiles as $profile){
211 if(!$profile['initial']){
213 $contents = $profile['content'];
214 $path = $this->baseDir."/".$profile['name'];
215 $fp = @fopen($path,"w");
216 if(!$fp){
217 print_red(_("Can't save new kiosk profiles, possibly permission denied for folder")." : ",$path);
218 }else{
219 fwrite($fp,$contents,strlen($contents));
220 $this->attrs['gotoKioskProfile'][] = $method.$profile['name'];
221 }
222 @unlink($profile['tmp_name']);
223 }else{
224 $this->attrs['gotoKioskProfile'][] = $method.$profile['name'];
225 }
226 }
227 $ldap = $this->config->get_ldap_link();
228 $ldap->cd($this->config->current['BASE']);
229 $ldap->cd($this->dn);
230 $ldap->modify($this->attrs);
231 if (!$ldap->success()){
232 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
233 }
234 }
237 function save_object()
238 {
239 if(isset($_POST['goKioskPosted'])){
240 goService::save_object();
241 if(isset($_POST['server_path'])){
242 $this->server_path = get_post("server_path");
243 }
244 }
245 }
248 /* Return plugin informations for acl handling */
249 static function plInfo()
250 {
251 return (array(
252 "plShortName" => _("Kiosk"),
253 "plDescription" => _("Kiosk profile management")." ("._("Services").")",
254 "plSelfModify" => FALSE,
255 "plDepends" => array(),
256 "plPriority" => 100,
257 "plSection" => array("administration"),
258 "plCategory" => array("server"),
260 "plProvidedAcls"=> array()
261 ));
262 }
263 }
264 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
265 ?>