c372b81eaa4d2df73082a756aa1f8b954d3a5270
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 /* Fill templating stuff */
46 $smarty = get_smarty();
47 $display = "";
49 if(isset($_POST['ImportUpload'])){
50 if(($_FILES['ImportFile']['error']!=0)){
51 print_red(_("Please select a valid file."));
52 }else
53 if(($_FILES['ImportFile']['size']==0)){
54 print_red(_("Selected file is empty."));
55 }else{
56 $str = utf8_encode(file_get_contents($_FILES['ImportFile']['tmp_name']));
57 $this->FAIscript = $str;
58 }
59 }
60 $smarty->assign("tasks", $this->tasks);
62 /* Magic quotes GPC, escapes every ' " \, to solve some security risks
63 * If we post the escaped strings they will be escaped again
64 */
65 foreach($this->attributes as $attrs){
66 if(get_magic_quotes_gpc()){
67 $smarty->assign($attrs,stripslashes($this->$attrs));
68 }else{
69 $smarty->assign($attrs,($this->$attrs));
70 }
71 }
73 $display.= $smarty->fetch(get_template_path('faiHookEntry.tpl', TRUE));
74 return($display);
75 }
77 /* Save data to object */
78 function save_object()
79 {
80 if(isset($_POST['SubObjectFormSubmitted'])){
81 foreach($this->attributes as $attrs){
82 if(isset($_POST[$attrs])){
83 $this->$attrs = $_POST[$attrs];
84 }else{
85 $this->$attrs = "";
86 }
87 }
88 $this->FAIscript= recode("DOS..LATIN1", $this->FAIscript);
89 }
90 }
92 /* Check supplied data */
93 function check()
94 {
95 $message= array();
96 if(empty($this->FAIscript)) {
97 $message[]=_("Please enter a value for script.");
98 }
100 if(empty($this->cn)){
101 $message[] = _("Please enter a name.");
102 }
104 return ($message);
105 }
107 function save()
108 {
109 $tmp=array();
110 foreach($this->attributes as $attrs){
111 $tmp[$attrs] = $this->$attrs;
112 }
114 if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
115 $tmp['remove']['from'] = $this->orig_cn;
116 $tmp['remove']['to'] = $tmp['cn'];
117 }
119 $tmp['dn'] = $this->dn;
120 $tmp['status'] = $this->status;
121 return($tmp);
122 }
123 }
124 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
125 ?>