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 msg_dialog::display(_("Configuration error"), msgPool::cmdnotfound("KIOSKPATH",_("Kiosk profile service")), ERROR_DIALOG);
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 if ($ldap->count() != 0){
55 $obj= array();
56 while($attrs = $ldap->fetch()){
57 $obj[$ldap->getDN()]= $attrs['cn'][0];
58 }
59 msg_dialog::display(_("Error"), msgPool::stillInUse(_("Kiosk profile service"), msgPool::buildList($obj)), ERROR_DIALOG);
60 }else{
61 goService::remove_from_parent();
62 }
63 }
66 function execute()
67 {
68 /* log actions */
69 if($this->is_account && !$this->view_logged){
70 $this->view_logged = TRUE;
71 new log("view","server/".get_class($this),$this->dn);
72 }
74 /* Fill templating stuff */
75 $smarty= get_smarty();
76 $display= "";
78 /* Download kiosk profile
79 */
80 if(isset($_GET['getkiosk'])){
81 $id = $_GET['getkiosk'];
82 foreach($this->gotoKioskProfiles as $profile){
83 if($profile['name'] == $id){
84 $name = $this->baseDir."/".$id;
85 if(file_exists($name)){
86 $content = file_get_contents($name);
87 send_binary_content($content,$id);
88 }
89 }
90 }
91 }
94 /* Add new kiosk profile
95 * in profile directory ($this->baseDir);
96 */
97 if((isset($_POST['profileAdd']))&&(isset($_FILES['newProfile']))){
98 $file = $_FILES['newProfile'];
99 if(!file_exists($this->baseDir.$file['name'])){
100 $tmp = array(
101 'url' => "" ,
102 'name' => $file['name'] ,
103 'initial' => FALSE,
104 'tmp_name'=> $file['tmp_name'],
105 'content' => file_get_contents($file['tmp_name']),
106 'exists' => TRUE);
107 $this->gotoKioskProfiles[] = $tmp;
108 }
109 }
111 $only_once = true;
112 foreach($_POST as $name => $value){
114 if((preg_match("/^delkiosk_/",$name))&&($only_once)){
116 /* Get id, name and path */
117 $only_once = false;
118 $id = preg_replace("/^delkiosk_/","",$name);
119 $id = preg_replace("/_.*$/","",$id);
120 $name = $this->gotoKioskProfiles[$id]['name'];
121 $filename = $this->baseDir."/".$name;
123 /* check if profile is still in use */
124 $ldap = $this->config->get_ldap_link();
125 $ldap->cd($this->config->current['BASE']);
126 $ldap->search("(&(objectClass=gotoEnvironment)(gotoKioskProfile=*".$name.")",array("cn","uid","gotoKioskProfile"));
128 if ($ldap->count() != 0){
130 $obj= array();
131 $found= false;
132 while(($attrs = $ldap->fetch()) && ($cnt)){
133 $check = preg_replace("/^.*\//i","",$attrs['gotoKioskProfile'][0]);
134 if($check == $name){
135 $obj[$ldap->getDN()]= $attrs['cn'][0];
136 $found= true;
137 }
138 }
140 if ($found){
141 msg_dialog::display(_("Error"), msgPool::stillInUse(_("Kiosk profile"), msgPool::buildList($obj)), ERROR_DIALOG);
142 }
143 }else{
144 if($this->gotoKioskProfiles[$id]['initial']){
145 $res = @unlink($filename);
146 if(!$res){
147 if(!is_writeable($filename)){
148 msg_dialog::display(_("Error"), msgPool::cannotDeleteFile($filename), ERROR_DIALOG);
149 }
150 if(!file_exists($filename)){
151 msg_dialog::display(_("Error"), msgPool::fileDoesNotExist($filename), ERROR_DIALOG);
152 }
153 }
154 unset($this->gotoKioskProfiles[$id]);
155 }
156 }
157 }
158 }
160 /* Display list of profiles */
161 $divlist = new divSelectBox("KioskProfiles");
162 $divlist -> SetHeight (300);
163 foreach($this->gotoKioskProfiles as $key => $val ){
164 $divlist->AddEntry(array(
165 array("string"=>"<a href='?plug=".$_GET['plug']."&getkiosk=".$val['name']."'>".$val['name']."</a>"),
166 array("string"=>"<input type='image' src='images/edittrash.png'
167 class='center' alt='delete' name='delkiosk_".$key."'>" ,
168 "attach"=>" style='border-right: 0px;width:24px; text-align:center;' ")
169 ));
170 }
172 /* Assign all existing profiles to smarty */
173 $smarty->assign("divlist",$divlist->DrawList());
174 $smarty = get_smarty();
175 foreach($this->attributes as $attr){
176 $smarty->assign($attr,$this->$attr);
177 }
178 $smarty->assign("server_path",$this->server_path);
179 return($smarty->fetch(get_template_path("goKioskService.tpl",TRUE,dirname(__FILE__))));
180 }
184 function getListEntry()
185 {
186 $fields = goService::getListEntry();
187 $fields['Message'] = _("Kiosk profile service");
188 $fields['AllowEdit'] = TRUE;
189 $fields['AllowStart'] = false;
190 $fields['AllowStop'] = false;
191 $fields['AllowRestart'] = false;
192 return($fields);
193 }
195 function check()
196 {
197 $message = plugin::check();
198 return($message);
199 }
201 function save()
202 {
203 goService::save();
205 $method = $this->server_path."/";
206 $method = preg_replace("/\/\/*$/","/",$method);
207 $this->attrs['gotoKioskProfile'] = array();
208 foreach($this->gotoKioskProfiles as $profile){
209 if(!$profile['initial']){
211 $contents = $profile['content'];
212 $path = $this->baseDir."/".$profile['name'];
213 $fp = @fopen($path,"w");
214 if(!$fp){
215 msg_dialog::display(_("Error"), msgPool::cannotWriteFile($path), ERROR_DIALOG);
216 }else{
217 fwrite($fp,$contents,strlen($contents));
218 $this->attrs['gotoKioskProfile'][] = $method.$profile['name'];
219 }
220 @unlink($profile['tmp_name']);
221 }else{
222 $this->attrs['gotoKioskProfile'][] = $method.$profile['name'];
223 }
224 }
225 $ldap = $this->config->get_ldap_link();
226 $ldap->cd($this->config->current['BASE']);
227 $ldap->cd($this->dn);
228 $ldap->modify($this->attrs);
229 if (!$ldap->success()){
230 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
231 }
232 }
235 function save_object()
236 {
237 if(isset($_POST['goKioskPosted'])){
238 goService::save_object();
239 if(isset($_POST['server_path'])){
240 $this->server_path = get_post("server_path");
241 }
242 }
243 }
246 /* Return plugin informations for acl handling */
247 static function plInfo()
248 {
249 return (array(
250 "plShortName" => _("Kiosk"),
251 "plDescription" => _("Kiosk profile management")." ("._("Services").")",
252 "plSelfModify" => FALSE,
253 "plDepends" => array(),
254 "plPriority" => 100,
255 "plSection" => array("administration"),
256 "plCategory" => array("server"),
258 "plProvidedAcls"=> array()
259 ));
260 }
261 }
262 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
263 ?>