1 <?php
3 class faiHookEntry extends plugin
4 {
5 /* CLI vars */
6 var $cli_summary= "Manage server basic objects";
7 var $cli_description= "Some longer text\nfor help";
8 var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10 /* attribute list for save action */
11 var $ignore_account= TRUE;
12 var $attributes = array("cn","description","FAIscript","FAItask");
13 var $objectclasses= array();
15 var $orig_cn = "";
16 var $tasks = array("chboot", "configure", "debconf", "extrbase", "faiend", "finish",
17 "install", "instsoft", "mirror", "mountdisks", "partition", "prepareapt",
18 "savelog", "softupdate", "sysinfo","updatebase");
19 var $dn = "";
20 var $cn = "";
21 var $FAItask = "";
22 var $FAIscript = "";
23 var $description = "";
24 var $status = "new";
26 var $FAIstate = "";
28 function faiHookEntry ($config, $dn= NULL,$object=false)
29 {
30 plugin::plugin ($config, $dn);
31 if($dn != "new"){
32 $this->orig_cn= $object['cn'];
33 $this->dn=$object['dn'];
34 foreach($object as $name=>$value){
35 $oname = $name;
36 $this->$oname=$value;
37 }
39 if(isset($this->attrs['FAIstate'][0])){
40 $this->FAIstate = $this->attrs['FAIstate'][0];
41 }
43 }elseif(is_array($object)){
44 if(count($object)){
45 $this->orig_cn= $object['cn'];
46 $this->dn=$object['dn'];
47 foreach($object as $name=>$value){
48 $oname = $name;
49 $this->$oname=$value;
50 }
51 }else{
53 $this->status = "new";
54 $this->orig_cn = false;
55 }
56 }
57 }
60 function execute()
61 {
62 /* Call parent execute */
63 plugin::execute();
65 /* Fill templating stuff */
66 $smarty = get_smarty();
67 $display = "";
69 if(isset($_POST['ImportUpload'])){
70 if(($_FILES['ImportFile']['error']!=0)){
71 print_red(_("Please select a valid file."));
72 }else
73 if(($_FILES['ImportFile']['size']==0)){
74 print_red(_("Selected file is empty."));
75 }else{
76 $str = utf8_encode(file_get_contents($_FILES['ImportFile']['tmp_name']));
77 $this->FAIscript = $str;
78 }
79 }
81 /* Create download button*/
82 if($this->dn != "new" && $this->acl_is_readable("FAIscript")){
83 $smarty->assign("DownMe","<a href='getFAIscript.php?id=".base64_encode($this->dn)."'>
84 <img src='images/save.png' alt='"._("Download")."' title='"._("Download")."' border=0 class='center'>
85 </a>");
86 }else{
87 $smarty->assign("DownMe","");
88 }
90 $used_tasks = $this->parent->getUsedFAItask($this->cn);
91 $tasks = $this->tasks;
92 foreach($this->tasks as $id => $task){
93 if(in_array($task,$used_tasks)){
94 unset($tasks[$id]);
95 }
96 }
97 $smarty->assign("tasks", $tasks);
99 /* Magic quotes GPC, escapes every ' " \, to solve some security risks
100 * If we post the escaped strings they will be escaped again
101 */
102 foreach($this->attributes as $attrs){
103 if(get_magic_quotes_gpc()){
104 $smarty->assign($attrs,htmlentities(stripslashes($this->$attrs)));
105 }else{
106 $smarty->assign($attrs,htmlentities($this->$attrs));
107 }
108 }
110 $tmp = $this->plInfo();
111 foreach($tmp['plProvidedAcls'] as $name => $translated){
112 $acl = $this->getacl($name);
113 if($this->FAIstate == "freezed"){
114 $acl = preg_replace("/w/","",$acl);
115 }
116 $smarty->assign($name."ACL",$acl);
117 }
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'])) && ($this->FAIstate != "freeze")){
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(empty($this->FAIscript)) {
146 $message[]=_("Please enter a value for script.");
147 }
149 if(empty($this->cn)){
150 $message[] = _("Please enter a name.");
151 }
153 return ($message);
154 }
156 function save()
157 {
158 $tmp=array();
159 foreach($this->attributes as $attrs){
160 $tmp[$attrs] = $this->$attrs;
161 }
163 /* Strip out dos newlines */
164 $tmp['FAIscript']= strtr($this->FAIscript, array("\x0D" => ""));
166 if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
167 $tmp['remove']['from'] = $this->orig_cn;
168 $tmp['remove']['to'] = $tmp['cn'];
169 }
171 $tmp['dn'] = $this->dn;
172 $tmp['status'] = $this->status;
173 return($tmp);
174 }
176 /* Return plugin informations for acl handling */
177 function plInfo()
178 {
179 return (array(
180 "plShortName" => _("Hook entry"),
181 "plDescription" => _("FAI hook entry"),
182 "plSelfModify" => FALSE,
183 "plDepends" => array(),
184 "plPriority" => 21,
185 "plSection" => array("administration"),
186 "plCategory" => array("fai"),
187 "plProvidedAcls" => array(
188 "cn" => _("Name"),
189 "description" => _("Description"),
190 "FAItask" => _("Task"),
191 "FAIscript" => _("FAI script"))
192 ));
193 }
195 }
196 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
197 ?>