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, NULL);
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 }
34 }elseif(is_array($object)){
35 if(count($object)){
36 $this->orig_cn= $object['cn'];
37 $this->dn=$object['dn'];
38 foreach($object as $name=>$value){
39 $oname = $name;
40 $this->$oname=$value;
41 }
42 }else{
44 $this->status = "new";
45 $this->orig_cn = false;
46 }
47 }
48 }
51 function execute()
52 {
53 /* Call parent execute */
54 plugin::execute();
56 /* Fill templating stuff */
57 $smarty = get_smarty();
58 $display = "";
60 if(isset($_POST['ImportUpload'])){
61 if(($_FILES['ImportFile']['error']!=0)){
62 msg_dialog::display(_("Error"), msgPool::incorrectUpload(), ERROR_DIALOG);
63 }else
64 if(($_FILES['ImportFile']['size']==0)){
65 msg_dialog::display(_("Error"), msgPool::incorrectUpload(_("file is empty")), ERROR_DIALOG);
66 }else{
67 $str = utf8_encode(file_get_contents($_FILES['ImportFile']['tmp_name']));
68 $str = preg_replace("/[\r]/","",$str);
69 $this->FAIscript = addslashes ($str);
70 }
71 }
73 /* File download requested */
74 if(isset($_GET['getFAIHook'])){
75 send_binary_content(stripslashes($this->FAIscript),$this->cn.".FAIhook");
76 }
78 /* Create download button*/
79 if($this->dn != "new" && $this->acl_is_readable("FAIscript")){
80 $smarty->assign("DownMe","<a href='?plug=".$_GET['plug']."&getFAIHook'>
81 <img src='images/save.png' alt='"._("Download")."' title='"._("Download")."' border=0 class='center'>
82 </a>");
83 }else{
84 $smarty->assign("DownMe","");
85 }
87 $used_tasks = $this->parent->getUsedFAItask($this->cn);
88 $tasks = $this->tasks;
89 foreach($this->tasks as $id => $task){
90 if(in_array($task,$used_tasks)){
91 unset($tasks[$id]);
92 }
93 }
94 $smarty->assign("tasks", $tasks);
96 /* Magic quotes GPC, escapes every ' " \, to solve some security risks
97 * If we post the escaped strings they will be escaped again
98 */
99 foreach($this->attributes as $attrs){
100 if(get_magic_quotes_gpc()){
101 $smarty->assign($attrs,(stripslashes($this->$attrs)));
102 }else{
103 $smarty->assign($attrs,($this->$attrs));
104 }
105 }
107 $tmp = $this->plInfo();
108 foreach($tmp['plProvidedAcls'] as $name => $translated){
109 $acl = $this->getacl($name, preg_match("/freeze/",$this->FAIstate));
110 $smarty->assign($name."ACL",$acl);
111 }
113 if(get_magic_quotes_gpc()){
114 $smarty->assign("FAIscript" , htmlentities(stripslashes($this->FAIscript)));
115 }else{
116 $smarty->assign("FAIscript" , htmlentities($this->FAIscript));
117 }
118 $smarty->assign("freeze" , preg_match("/freeze/",$this->FAIstate));
119 $display.= $smarty->fetch(get_template_path('faiHookEntry.tpl', TRUE));
120 return($display);
121 }
123 /* Save data to object */
124 function save_object()
125 {
126 if((isset($_POST['SubObjectFormSubmitted'])) && !preg_match("/^freeze/", $this->FAIstate)){
127 foreach($this->attributes as $attrs){
128 if($this->acl_is_writeable($attrs)){
129 if(isset($_POST[$attrs])){
130 $this->$attrs = $_POST[$attrs];
131 }else{
132 $this->$attrs = "";
133 }
134 }
135 }
136 }
137 }
139 /* Check supplied data */
140 function check()
141 {
142 /* Call common method to give check the hook */
143 $message= plugin::check();
145 if(isset($this->parent->SubObjects[$this->cn]) && $this->cn != $this->orig_cn){
146 $message[]= msgPool::duplicated(_("Name"));
147 }
149 $c = trim($this->cn);
150 if($c == ""){
151 $message[] = msgPool::required(_("Name"));
152 }
153 if(preg_match("/[^a-z0-9_\-]/i",$c)){
154 $message[] = msgPool::invalid(_("Name"),$c,"/[a-z0-9_\-]/i");
155 }
157 $s = trim($this->FAIscript);
158 if($s == ""){
159 $message[]= msgPool::required(_("Script"));
160 }
162 return ($message);
163 }
165 function save()
166 {
167 $tmp=array();
168 foreach($this->attributes as $attrs){
169 $tmp[$attrs] = $this->$attrs;
170 }
172 /* Strip out dos newlines */
173 $tmp['FAIscript']= strtr($this->FAIscript, array("\x0D" => ""));
175 if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
176 $tmp['remove']['from'] = $this->orig_cn;
177 $tmp['remove']['to'] = $tmp['cn'];
178 }
180 $tmp['dn'] = $this->dn;
181 $tmp['status'] = $this->status;
182 return($tmp);
183 }
185 /* Return plugin informations for acl handling */
186 static function plInfo()
187 {
188 return (array(
189 "plShortName" => _("Hook entry"),
190 "plDescription" => _("FAI hook entry"),
191 "plSelfModify" => FALSE,
192 "plDepends" => array(),
193 "plPriority" => 21,
194 "plSection" => array("administration"),
195 "plCategory" => array("fai"),
196 "plProvidedAcls" => array(
197 "cn" => _("Name"),
198 "description" => _("Description"),
199 "FAItask" => _("Task"),
200 "FAIscript" => _("FAI script"))
201 ));
202 }
204 }
205 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
206 ?>