83396e99214b69922e0ca0744cb0c14042d09b3c
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 function faiHookEntry ($config, $dn= NULL,$object=false)
27 {
28 plugin::plugin ($config, $dn);
29 if($dn != "new"){
30 $this->orig_cn= $object['cn'];
31 $this->dn=$object['dn'];
32 foreach($object as $name=>$value){
33 $oname = $name;
34 $this->$oname=$value;
35 }
36 }elseif(is_array($object)){
37 if(count($object)){
38 $this->orig_cn= $object['cn'];
39 $this->dn=$object['dn'];
40 foreach($object as $name=>$value){
41 $oname = $name;
42 $this->$oname=$value;
43 }
44 }else{
46 $this->status = "new";
47 $this->orig_cn = false;
48 }
49 }
50 }
53 function execute()
54 {
55 /* Call parent execute */
56 plugin::execute();
58 /* Fill templating stuff */
59 $smarty = get_smarty();
60 $display = "";
62 if(isset($_POST['ImportUpload'])){
63 if(($_FILES['ImportFile']['error']!=0)){
64 print_red(_("Please select a valid file."));
65 }else
66 if(($_FILES['ImportFile']['size']==0)){
67 print_red(_("Selected file is empty."));
68 }else{
69 $str = utf8_encode(file_get_contents($_FILES['ImportFile']['tmp_name']));
70 $this->FAIscript = $str;
71 }
72 }
74 /* Create download button*/
75 if($this->dn != "new"){
76 $smarty->assign("DownMe","<a href='getFAIscript.php?id=".base64_encode($this->dn)."' target='_blank'>
77 <input type='button' value='"._("Download")."'>
78 </a>");
79 }else{
80 $smarty->assign("DownMe","");
81 }
83 $used_tasks = $this->parent->getUsedFAItask($this->cn);
84 $tasks = $this->tasks;
85 foreach($this->tasks as $id => $task){
86 if(in_array($task,$used_tasks)){
87 unset($tasks[$id]);
88 }
89 }
90 $smarty->assign("tasks", $tasks);
92 /* Magic quotes GPC, escapes every ' " \, to solve some security risks
93 * If we post the escaped strings they will be escaped again
94 */
95 foreach($this->attributes as $attrs){
96 if(get_magic_quotes_gpc()){
97 $smarty->assign($attrs,htmlentities(stripslashes($this->$attrs)));
98 }else{
99 $smarty->assign($attrs,htmlentities($this->$attrs));
100 }
101 }
103 $display.= $smarty->fetch(get_template_path('faiHookEntry.tpl', TRUE));
104 return($display);
105 }
107 /* Save data to object */
108 function save_object()
109 {
110 if(isset($_POST['SubObjectFormSubmitted'])){
111 foreach($this->attributes as $attrs){
112 if(isset($_POST[$attrs])){
113 $this->$attrs = $_POST[$attrs];
114 }else{
115 $this->$attrs = "";
116 }
117 }
118 }
119 }
121 /* Check supplied data */
122 function check()
123 {
124 $message= array();
125 if(empty($this->FAIscript)) {
126 $message[]=_("Please enter a value for script.");
127 }
129 if(empty($this->cn)){
130 $message[] = _("Please enter a name.");
131 }
133 return ($message);
134 }
136 function save()
137 {
138 $tmp=array();
139 foreach($this->attributes as $attrs){
140 $tmp[$attrs] = $this->$attrs;
141 }
143 /* Strip out dos newlines */
144 $tmp['FAIscript']= strtr($this->FAIscript, array("\x0D" => ""));
146 if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
147 $tmp['remove']['from'] = $this->orig_cn;
148 $tmp['remove']['to'] = $tmp['cn'];
149 }
151 $tmp['dn'] = $this->dn;
152 $tmp['status'] = $this->status;
153 return($tmp);
154 }
155 }
156 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
157 ?>