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 }
63 $smarty->assign("tasks", $this->tasks);
65 /* Magic quotes GPC, escapes every ' " \, to solve some security risks
66 * If we post the escaped strings they will be escaped again
67 */
68 foreach($this->attributes as $attrs){
69 if(get_magic_quotes_gpc()){
70 $smarty->assign($attrs,stripslashes($this->$attrs));
71 }else{
72 $smarty->assign($attrs,($this->$attrs));
73 }
74 }
76 $display.= $smarty->fetch(get_template_path('faiHookEntry.tpl', TRUE));
77 return($display);
78 }
80 /* Save data to object */
81 function save_object()
82 {
83 if(isset($_POST['SubObjectFormSubmitted'])){
84 foreach($this->attributes as $attrs){
85 if(isset($_POST[$attrs])){
86 $this->$attrs = $_POST[$attrs];
87 }else{
88 $this->$attrs = "";
89 }
90 }
91 $this->FAIscript= recode("DOS..LATIN1", $this->FAIscript);
92 }
93 }
95 /* Check supplied data */
96 function check()
97 {
98 $message= array();
99 if(empty($this->FAIscript)) {
100 $message[]=_("Please enter a value for script.");
101 }
103 if(empty($this->cn)){
104 $message[] = _("Please enter a name.");
105 }
107 return ($message);
108 }
110 function save()
111 {
112 $tmp=array();
113 foreach($this->attributes as $attrs){
114 $tmp[$attrs] = $this->$attrs;
115 }
117 if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
118 $tmp['remove']['from'] = $this->orig_cn;
119 $tmp['remove']['to'] = $tmp['cn'];
120 }
122 $tmp['dn'] = $this->dn;
123 $tmp['status'] = $this->status;
124 return($tmp);
125 }
126 }
127 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
128 ?>