Code

5a23ea4979aecc181caf441685565ed654044bd0
[gosa.git] / plugins / admin / fai / class_faiHookEntry.inc
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       = "chboot";
22   var $FAIscript     = "";
23   var $description   = "";
24   var $status        = "new";
25   var $parent        = NULL;
26   var $FAIstate      = "";
27   
28   function faiHookEntry (&$config, $dn= NULL,$object=false)
29   {
30     plugin::plugin ($config, $dn);
31     if($dn != "new"){
32       $this->orig_cn= $object['cn'];
33       $this->dn=$object['dn'];
34       foreach($object as $name=>$value){
35         $oname = $name;
36         $this->$oname=$value;
37       }
39       if(isset($this->attrs['FAIstate'][0])){
40         $this->FAIstate = $this->attrs['FAIstate'][0];
41       }
43     }elseif(is_array($object)){
44       if(count($object)){
45         $this->orig_cn= $object['cn'];
46         $this->dn=$object['dn'];
47         foreach($object as $name=>$value){
48           $oname = $name;
49           $this->$oname=$value;
50         }
51       }else{
53         $this->status = "new";
54         $this->orig_cn       = false;
55       }
56     }
57   }
60   function execute()
61   {
62         /* Call parent execute */
63         plugin::execute();
65     /* Fill templating stuff */
66     $smarty     = get_smarty();
67     $display = "";
68         
69     if(isset($_POST['ImportUpload'])){
70       if(($_FILES['ImportFile']['error']!=0)){
71         print_red(_("Please select a valid file."));
72       }else
73       if(($_FILES['ImportFile']['size']==0)){
74         print_red(_("Selected file is empty."));
75       }else{
76         $str = utf8_encode(file_get_contents($_FILES['ImportFile']['tmp_name']));
77         $this->FAIscript = $str;
78       }
79     }
81     /* Create download button*/
82     if($this->dn != "new" && $this->acl_is_readable("FAIscript")){
83       $smarty->assign("DownMe","<a href='getFAIscript.php?id=".base64_encode($this->dn)."'>
84           <img src='images/save.png' alt='"._("Download")."' title='"._("Download")."' border=0 class='center'>
85         </a>");
86     }else{
87       $smarty->assign("DownMe","");  
88     }
90     $used_tasks = $this->parent->getUsedFAItask($this->cn);
91     $tasks = $this->tasks;
92     foreach($this->tasks as $id => $task){
93       if(in_array($task,$used_tasks)){
94         unset($tasks[$id]);
95       }
96     }
97     $smarty->assign("tasks", $tasks);
99      /* Magic quotes GPC, escapes every ' " \, to solve some security risks
100      * If we post the escaped strings they will be escaped again
101      */
102     foreach($this->attributes as $attrs){
103       if(get_magic_quotes_gpc()){
104         $smarty->assign($attrs,(stripslashes($this->$attrs)));
105       }else{
106         $smarty->assign($attrs,($this->$attrs));
107       }
108     }
110     $tmp = $this->plInfo();
111     foreach($tmp['plProvidedAcls'] as $name => $translated){
112       $acl = $this->getacl($name);
113       if($this->FAIstate == "freezed"){
114         $acl = preg_replace("/w/","",$acl);
115       }
116       $smarty->assign($name."ACL",$acl);
117     }
118    
119     if(get_magic_quotes_gpc()){
120       $smarty->assign("FAIscript" , htmlentities(stripslashes($this->FAIscript)));
121     }else{
122       $smarty->assign("FAIscript" , htmlentities($this->FAIscript));
123     }
124     $display.= $smarty->fetch(get_template_path('faiHookEntry.tpl', TRUE));
125     return($display);
126   }
128   /* Save data to object */
129   function save_object()
130   {
131     if((isset($_POST['SubObjectFormSubmitted'])) && ($this->FAIstate != "freeze")){
132       foreach($this->attributes as $attrs){
133         if($this->acl_is_writeable($attrs)){
134           if(isset($_POST[$attrs])){
135             $this->$attrs = $_POST[$attrs];
136           }else{
137             $this->$attrs = "";
138           }
139         }
140       }
141     }
142   }
144   /* Check supplied data */
145   function check()
146   {
147     /* Call common method to give check the hook */
148     $message= plugin::check();
150     if(isset($this->parent->SubObjects[$this->cn]) && $this->cn != $this->orig_cn){
151       $message[] =_("There is already a hook with the given name.");
152     }
154     if(empty($this->FAIscript)) {
155       $message[]=_("Please enter a value for script.");
156     }
158     if(empty($this->cn)){
159       $message[] = _("Please enter a name.");
160     }
162     return ($message);
163   }
164  
165   function save()
166   {
167     $tmp=array();
168     foreach($this->attributes as $attrs){ 
169       $tmp[$attrs] = $this->$attrs;
170     }
172     /* Strip out dos newlines */
173     $tmp['FAIscript']= strtr($this->FAIscript, array("\x0D" => ""));
175     if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
176       $tmp['remove']['from']  = $this->orig_cn;
177       $tmp['remove']['to']    = $tmp['cn'];
178     }
179   
180     $tmp['dn']      = $this->dn;  
181     $tmp['status']  = $this->status;  
182     return($tmp);
183   }
185     /* Return plugin informations for acl handling */
186   function plInfo()
187   {
188     return (array(
189           "plShortName" => _("Hook entry"),
190           "plDescription" => _("FAI hook entry"),
191           "plSelfModify"  => FALSE,
192           "plDepends"     => array(),
193           "plPriority"    => 21,
194           "plSection"     => array("administration"),
195           "plCategory"    => array("fai"),
196           "plProvidedAcls" => array(
197             "cn"                => _("Name"),
198             "description"       => _("Description"),
199             "FAItask"           => _("Task"),
200             "FAIscript"         => _("FAI script"))
201           ));
202   }
205 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
206 ?>