1 <?php
3 class faiHookEntry extends plugin
4 {
6 /* attribute list for save action */
7 var $ignore_account= TRUE;
8 var $attributes = array("cn","description","FAIscript","FAItask");
9 var $objectclasses= array();
11 var $orig_cn = "";
12 var $tasks = array("chboot", "configure", "debconf", "extrbase", "faiend", "finish",
13 "install", "instsoft", "mirror", "mountdisks", "partition", "prepareapt",
14 "savelog", "softupdate", "sysinfo","updatebase", "error");
15 var $dn = "";
16 var $cn = "";
17 var $FAItask = "chboot";
18 var $FAIscript = "";
19 var $description = "";
20 var $status = "new";
21 var $parent = NULL;
22 var $FAIstate = "";
24 function faiHookEntry (&$config, $dn= NULL,$object=false)
25 {
26 plugin::plugin ($config, $dn);
27 if($dn != "new"){
28 $this->orig_cn= $object['cn'];
29 $this->dn=$object['dn'];
30 foreach($object as $name=>$value){
31 $oname = $name;
32 $this->$oname=$value;
33 }
35 if(isset($this->attrs['FAIstate'][0])){
36 $this->FAIstate = $this->attrs['FAIstate'][0];
37 }
39 }elseif(is_array($object)){
40 if(count($object)){
41 $this->orig_cn= $object['cn'];
42 $this->dn=$object['dn'];
43 foreach($object as $name=>$value){
44 $oname = $name;
45 $this->$oname=$value;
46 }
47 }else{
49 $this->status = "new";
50 $this->orig_cn = false;
51 }
52 }
53 }
56 function execute()
57 {
58 /* Call parent execute */
59 plugin::execute();
61 /* Fill templating stuff */
62 $smarty = get_smarty();
63 $display = "";
65 if(isset($_POST['ImportUpload'])){
66 if(($_FILES['ImportFile']['error']!=0)){
67 msg_dialog::display(_("Error"), _("Upload failed!"), ERROR_DIALOG);
68 }else
69 if(($_FILES['ImportFile']['size']==0)){
70 msg_dialog::display(_("Error"), _("Uploaded file is empty!"), ERROR_DIALOG);
71 }else{
72 $str = utf8_encode(file_get_contents($_FILES['ImportFile']['tmp_name']));
73 $this->FAIscript = $str;
74 }
75 }
77 /* File download requested */
78 if(isset($_GET['getFAIHook'])){
79 send_binary_content(stripslashes($this->FAIscript),$this->cn.".FAIhook");
80 }
82 /* Create download button*/
83 if($this->dn != "new" && $this->acl_is_readable("FAIscript")){
84 $smarty->assign("DownMe","<a href='?plug=".$_GET['plug']."&getFAIHook'>
85 <img src='images/save.png' alt='"._("Download")."' title='"._("Download")."' border=0 class='center'>
86 </a>");
87 }else{
88 $smarty->assign("DownMe","");
89 }
91 $used_tasks = $this->parent->getUsedFAItask($this->cn);
92 $tasks = $this->tasks;
93 foreach($this->tasks as $id => $task){
94 if(in_array($task,$used_tasks)){
95 unset($tasks[$id]);
96 }
97 }
98 $smarty->assign("tasks", $tasks);
100 /* Magic quotes GPC, escapes every ' " \, to solve some security risks
101 * If we post the escaped strings they will be escaped again
102 */
103 foreach($this->attributes as $attrs){
104 if(get_magic_quotes_gpc()){
105 $smarty->assign($attrs,(stripslashes($this->$attrs)));
106 }else{
107 $smarty->assign($attrs,($this->$attrs));
108 }
109 }
111 $tmp = $this->plInfo();
112 foreach($tmp['plProvidedAcls'] as $name => $translated){
113 $acl = $this->getacl($name);
114 if($this->FAIstate == "freezed"){
115 $acl = preg_replace("/w/","",$acl);
116 }
117 $smarty->assign($name."ACL",$acl);
118 }
120 if(get_magic_quotes_gpc()){
121 $smarty->assign("FAIscript" , htmlentities(stripslashes($this->FAIscript)));
122 }else{
123 $smarty->assign("FAIscript" , htmlentities($this->FAIscript));
124 }
125 $display.= $smarty->fetch(get_template_path('faiHookEntry.tpl', TRUE));
126 return($display);
127 }
129 /* Save data to object */
130 function save_object()
131 {
132 if((isset($_POST['SubObjectFormSubmitted'])) && ($this->FAIstate != "freeze")){
133 foreach($this->attributes as $attrs){
134 if($this->acl_is_writeable($attrs)){
135 if(isset($_POST[$attrs])){
136 $this->$attrs = $_POST[$attrs];
137 }else{
138 $this->$attrs = "";
139 }
140 }
141 }
142 }
143 }
145 /* Check supplied data */
146 function check()
147 {
148 /* Call common method to give check the hook */
149 $message= plugin::check();
151 if(isset($this->parent->SubObjects[$this->cn]) && $this->cn != $this->orig_cn){
152 $message[]= msgPool::duplicated(_("Name"));
153 }
155 if(empty($this->FAIscript)) {
156 $message[]= msgPool::required(_("Script"));
157 }
159 if(empty($this->cn)){
160 $message[]= msgPool::required(_("Name"));
161 }
163 return ($message);
164 }
166 function save()
167 {
168 $tmp=array();
169 foreach($this->attributes as $attrs){
170 $tmp[$attrs] = $this->$attrs;
171 }
173 /* Strip out dos newlines */
174 $tmp['FAIscript']= strtr($this->FAIscript, array("\x0D" => ""));
176 if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
177 $tmp['remove']['from'] = $this->orig_cn;
178 $tmp['remove']['to'] = $tmp['cn'];
179 }
181 $tmp['dn'] = $this->dn;
182 $tmp['status'] = $this->status;
183 return($tmp);
184 }
186 /* Return plugin informations for acl handling */
187 static function plInfo()
188 {
189 return (array(
190 "plShortName" => _("Hook entry"),
191 "plDescription" => _("FAI hook entry"),
192 "plSelfModify" => FALSE,
193 "plDepends" => array(),
194 "plPriority" => 21,
195 "plSection" => array("administration"),
196 "plCategory" => array("fai"),
197 "plProvidedAcls" => array(
198 "cn" => _("Name"),
199 "description" => _("Description"),
200 "FAItask" => _("Task"),
201 "FAIscript" => _("FAI script"))
202 ));
203 }
205 }
206 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
207 ?>