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 }
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 $this->FAIscript = addslashes ($str);
69 }
70 }
72 /* File download requested */
73 if(isset($_GET['getFAIHook'])){
74 send_binary_content(stripslashes($this->FAIscript),$this->cn.".FAIhook");
75 }
77 /* Create download button*/
78 if($this->dn != "new" && $this->acl_is_readable("FAIscript")){
79 $smarty->assign("DownMe","<a href='?plug=".$_GET['plug']."&getFAIHook'>
80 <img src='images/save.png' alt='"._("Download")."' title='"._("Download")."' border=0 class='center'>
81 </a>");
82 }else{
83 $smarty->assign("DownMe","");
84 }
86 $used_tasks = $this->parent->getUsedFAItask($this->cn);
87 $tasks = $this->tasks;
88 foreach($this->tasks as $id => $task){
89 if(in_array($task,$used_tasks)){
90 unset($tasks[$id]);
91 }
92 }
93 $smarty->assign("tasks", $tasks);
95 /* Magic quotes GPC, escapes every ' " \, to solve some security risks
96 * If we post the escaped strings they will be escaped again
97 */
98 foreach($this->attributes as $attrs){
99 if(get_magic_quotes_gpc()){
100 $smarty->assign($attrs,(stripslashes($this->$attrs)));
101 }else{
102 $smarty->assign($attrs,($this->$attrs));
103 }
104 }
106 $tmp = $this->plInfo();
107 foreach($tmp['plProvidedAcls'] as $name => $translated){
108 $acl = $this->getacl($name, preg_match("/freeze/",$this->FAIstate));
109 $smarty->assign($name."ACL",$acl);
110 }
112 if(get_magic_quotes_gpc()){
113 $smarty->assign("FAIscript" , htmlentities(stripslashes($this->FAIscript)));
114 }else{
115 $smarty->assign("FAIscript" , htmlentities($this->FAIscript));
116 }
117 $smarty->assign("freeze" , preg_match("/freeze/",$this->FAIstate));
118 $display.= $smarty->fetch(get_template_path('faiHookEntry.tpl', TRUE));
119 return($display);
120 }
122 /* Save data to object */
123 function save_object()
124 {
125 if((isset($_POST['SubObjectFormSubmitted'])) && !preg_match("/^freeze/", $this->FAIstate)){
126 foreach($this->attributes as $attrs){
127 if($this->acl_is_writeable($attrs)){
128 if(isset($_POST[$attrs])){
129 $this->$attrs = $_POST[$attrs];
130 }else{
131 $this->$attrs = "";
132 }
133 }
134 }
135 }
136 }
138 /* Check supplied data */
139 function check()
140 {
141 /* Call common method to give check the hook */
142 $message= plugin::check();
144 if(isset($this->parent->SubObjects[$this->cn]) && $this->cn != $this->orig_cn){
145 $message[]= msgPool::duplicated(_("Name"));
146 }
148 if(empty($this->FAIscript)) {
149 $message[]= msgPool::required(_("Script"));
150 }
152 if(empty($this->cn)){
153 $message[]= msgPool::required(_("Name"));
154 }
156 return ($message);
157 }
159 function save()
160 {
161 $tmp=array();
162 foreach($this->attributes as $attrs){
163 $tmp[$attrs] = $this->$attrs;
164 }
166 /* Strip out dos newlines */
167 $tmp['FAIscript']= strtr($this->FAIscript, array("\x0D" => ""));
169 if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
170 $tmp['remove']['from'] = $this->orig_cn;
171 $tmp['remove']['to'] = $tmp['cn'];
172 }
174 $tmp['dn'] = $this->dn;
175 $tmp['status'] = $this->status;
176 return($tmp);
177 }
179 /* Return plugin informations for acl handling */
180 static function plInfo()
181 {
182 return (array(
183 "plShortName" => _("Hook entry"),
184 "plDescription" => _("FAI hook entry"),
185 "plSelfModify" => FALSE,
186 "plDepends" => array(),
187 "plPriority" => 21,
188 "plSection" => array("administration"),
189 "plCategory" => array("fai"),
190 "plProvidedAcls" => array(
191 "cn" => _("Name"),
192 "description" => _("Description"),
193 "FAItask" => _("Task"),
194 "FAIscript" => _("FAI script"))
195 ));
196 }
198 }
199 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
200 ?>