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 }else{
37 $this->status = "new";
38 $this->orig_cn = false;
39 }
40 }
43 function execute()
44 {
45 /* Call parent execute */
46 plugin::execute();
48 /* Fill templating stuff */
49 $smarty = get_smarty();
50 $display = "";
52 if(isset($_POST['ImportUpload'])){
53 if(($_FILES['ImportFile']['error']!=0)){
54 print_red(_("Please select a valid file."));
55 }else
56 if(($_FILES['ImportFile']['size']==0)){
57 print_red(_("Selected file is empty."));
58 }else{
59 $str = utf8_encode(file_get_contents($_FILES['ImportFile']['tmp_name']));
60 $this->FAIscript = $str;
61 }
62 }
64 $used_tasks = $this->parent->getUsedFAItask($this->cn);
65 $tasks = $this->tasks;
66 foreach($this->tasks as $id => $task){
67 if(in_array($task,$used_tasks)){
68 unset($tasks[$id]);
69 }
70 }
71 $smarty->assign("tasks", $tasks);
73 /* Magic quotes GPC, escapes every ' " \, to solve some security risks
74 * If we post the escaped strings they will be escaped again
75 */
76 foreach($this->attributes as $attrs){
77 if(get_magic_quotes_gpc()){
78 $smarty->assign($attrs,htmlentities(stripslashes($this->$attrs)));
79 }else{
80 $smarty->assign($attrs,htmlentities($this->$attrs));
81 }
82 }
84 $display.= $smarty->fetch(get_template_path('faiHookEntry.tpl', TRUE));
85 return($display);
86 }
88 /* Save data to object */
89 function save_object()
90 {
91 if(isset($_POST['SubObjectFormSubmitted'])){
92 foreach($this->attributes as $attrs){
93 if(isset($_POST[$attrs])){
94 $this->$attrs = $_POST[$attrs];
95 }else{
96 $this->$attrs = "";
97 }
98 }
99 $this->FAIscript= recode("DOS..LATIN1", $this->FAIscript);
100 }
101 }
103 /* Check supplied data */
104 function check()
105 {
106 $message= array();
107 if(empty($this->FAIscript)) {
108 $message[]=_("Please enter a value for script.");
109 }
111 if(empty($this->cn)){
112 $message[] = _("Please enter a name.");
113 }
115 return ($message);
116 }
118 function save()
119 {
120 $tmp=array();
121 foreach($this->attributes as $attrs){
122 $tmp[$attrs] = $this->$attrs;
123 }
125 if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
126 $tmp['remove']['from'] = $this->orig_cn;
127 $tmp['remove']['to'] = $tmp['cn'];
128 }
130 $tmp['dn'] = $this->dn;
131 $tmp['status'] = $this->status;
132 return($tmp);
133 }
134 }
135 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
136 ?>