c73d2e886a54b9820edeac61c0aa99266349e588
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"){
83 $smarty->assign("DownMe","<a href='getFAIscript.php?id=".base64_encode($this->dn)."'>
84 <input type='button' value='"._("Download")."'>
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 foreach($this->attributes as $attr){
111 if(($this->FAIstate == "freeze") || (chkacl($this->acl,$attr)!= "")){
112 $smarty->assign($attr."ACL"," disabled ");
113 }else{
114 $smarty->assign($attr."ACL"," ");
115 }
116 }
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'])) && ($this->FAIstate != "freeze")){
126 foreach($this->attributes as $attrs){
127 if(isset($_POST[$attrs])){
128 $this->$attrs = $_POST[$attrs];
129 }else{
130 $this->$attrs = "";
131 }
132 }
133 }
134 }
136 /* Check supplied data */
137 function check()
138 {
139 /* Call common method to give check the hook */
140 $message= plugin::check();
142 if(empty($this->FAIscript)) {
143 $message[]=_("Please enter a value for script.");
144 }
146 if(empty($this->cn)){
147 $message[] = _("Please enter a name.");
148 }
150 return ($message);
151 }
153 function save()
154 {
155 $tmp=array();
156 foreach($this->attributes as $attrs){
157 $tmp[$attrs] = $this->$attrs;
158 }
160 /* Strip out dos newlines */
161 $tmp['FAIscript']= strtr($this->FAIscript, array("\x0D" => ""));
163 if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
164 $tmp['remove']['from'] = $this->orig_cn;
165 $tmp['remove']['to'] = $tmp['cn'];
166 }
168 $tmp['dn'] = $this->dn;
169 $tmp['status'] = $this->status;
170 return($tmp);
171 }
172 }
173 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
174 ?>