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 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 $used_tasks = $this->parent->getUsedFAItask($this->cn);
75 $tasks = $this->tasks;
76 foreach($this->tasks as $id => $task){
77 if(in_array($task,$used_tasks)){
78 unset($tasks[$id]);
79 }
80 }
81 $smarty->assign("tasks", $tasks);
83 /* Magic quotes GPC, escapes every ' " \, to solve some security risks
84 * If we post the escaped strings they will be escaped again
85 */
86 foreach($this->attributes as $attrs){
87 if(get_magic_quotes_gpc()){
88 $smarty->assign($attrs,htmlentities(stripslashes($this->$attrs)));
89 }else{
90 $smarty->assign($attrs,htmlentities($this->$attrs));
91 }
92 }
94 $display.= $smarty->fetch(get_template_path('faiHookEntry.tpl', TRUE));
95 return($display);
96 }
98 /* Save data to object */
99 function save_object()
100 {
101 if(isset($_POST['SubObjectFormSubmitted'])){
102 foreach($this->attributes as $attrs){
103 if(isset($_POST[$attrs])){
104 $this->$attrs = $_POST[$attrs];
105 }else{
106 $this->$attrs = "";
107 }
108 }
109 $this->FAIscript= recode("DOS..LATIN1", $this->FAIscript);
110 }
111 }
113 /* Check supplied data */
114 function check()
115 {
116 $message= array();
117 if(empty($this->FAIscript)) {
118 $message[]=_("Please enter a value for script.");
119 }
121 if(empty($this->cn)){
122 $message[] = _("Please enter a name.");
123 }
125 return ($message);
126 }
128 function save()
129 {
130 $tmp=array();
131 foreach($this->attributes as $attrs){
132 $tmp[$attrs] = $this->$attrs;
133 }
135 if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
136 $tmp['remove']['from'] = $this->orig_cn;
137 $tmp['remove']['to'] = $tmp['cn'];
138 }
140 $tmp['dn'] = $this->dn;
141 $tmp['status'] = $this->status;
142 return($tmp);
143 }
144 }
145 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
146 ?>