Code

Added new service
[gosa.git] / plugins / admin / systems / class_goShareServer.inc
1 <?php
3 class goShareServer extends plugin{
5   var $cli_summary      = "This plugin is used within the ServerService Pluign \nand indicates that this server supports shares.";
6   var $cli_description  = "Some longer text\nfor help";
7   var $cli_parameters   = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
9   /* This plugin only writes its objectClass */
10   var $objectclasses    = array("goShareServer");
11   var $attributes       = array("goShareServerStatus","goExportEntry");
12   var $StatusFlag       = "goShareServerStatus";
14   /* This class can't be assigned twice so it conflicts with itsself */
15   var $conflicts        = array("goShareServer");
17   var $DisplayName      = "";
18   var $dn               = NULL;
19   var $acl;
21   var $goShareServerStatus  = "";
22   var $goExportEntry        = array();
23   var $allow_mounts         = false;
25   function goShareServer($config,$dn)
26   {
27     plugin::plugin($config,$dn);
29     $this->DisplayName = _("Shares");
31     $tmp =array();
32     if(isset($this->attrs['goExportEntry'])){
33       if(isset($this->attrs['goExportEntry']['count'])){
34         for($i= 0; $i<$this->attrs['goExportEntry']['count']; $i++){
35           $entry= $this->attrs['goExportEntry'][$i];
36           $tmp[preg_replace('/\|.*$/', '', $entry)]= $entry;
37         }
38       }
39     } 
40     $this->goExportEntryList = $tmp;
42     $ldap = $this->config->get_ldap_link();
43     $avl_objectclasses = $ldap->get_objectclasses();
44     if (isset($avl_objectclasses["mount"])) {
45       $this->allow_mounts = true;
46     }
47   }
50   function execute()
51   { 
52     $smarty = get_smarty(); 
55     if((isset($_POST['DelNfsEnt']))&&(isset($_POST['goExportEntryList']))){
56       if($this->allow_mounts){
57         foreach($_POST['goExportEntryList'] as $entry){
58           $this->deleteFromMountList($this->goExportEntryList[$entry]);
59         }
60       }
61       foreach($_POST['goExportEntryList'] as $entry){
62         $this->deleteFromList($entry);
63       }
64     }
66     if(isset($_POST['NewNfsAdd'])){
67       $this->oldone = NULL;
68       $this->o_subWindow = new servnfs($this->config,$this->acl, $this->allow_mounts, $this->dn);
69       $this->dialog = true;
70     }
72     if((isset($_POST['NewNfsEdit']))&&(isset($_POST['goExportEntryList']))){
73       $entry = $this->goExportEntryList[$_POST['goExportEntryList'][0]];
74       $add_mount=isset($this->mounts_to_add[$entry]);
75       $this->oldone=$entry;
76       $this->o_subWindow = new servnfs($this->config,$this->acl,$this->allow_mounts,$this->dn,$entry,$add_mount);
77       $this->dialog = true;
78     }
79     if(isset($this->o_subWindow)){
80       $this->o_subWindow->save_object(TRUE);
81     }
83     /* Save NFS setup */
84     if(isset($_POST['NFSsave'])){
85       if(count($this->o_subWindow->check())>0){
86         foreach($this->o_subWindow->check() as $msg) {
87           print_red($msg);
88         }
89       }else{
90         $this->o_subWindow->save_object();
91         $newone = $this->o_subWindow->save();
92         $this->addToList($newone);
93         if($this->allow_mounts){
94           if($this->oldone) {
95             $this->deleteFromMountList($this->oldone);
96           }
97           if ($this->o_subWindow->should_create_mount()) {
98             $this->addToMountList($newone);
99           }
100         }
101         unset($this->o_subWindow);
102         $this->dialog = false;
103       }
104     }
106     /* Cancel NFS setup */
107     if(isset($_POST['NFScancel'])){
108       $this->oldone = NULL;
109       unset($this->o_subWindow);
110       $this->dialog = false;
111     }
113     /* Execute NFS setup dialog*/
114     if(isset($this->o_subWindow)){
115       return $this->o_subWindow->execute();
116     }
122     foreach($this->attributes as $attr){
123       $smarty->assign($attr,$this->$attr);
124       $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
125     }
126     $tellSmarty= array();
127     ksort($this->goExportEntryList);
128     foreach($this->goExportEntryList as $name=>$values){
129       $tmp = split("\|",$values);
130       $tellSmarty[$name] = $tmp[0]." ".$tmp[4]." (".$tmp[2].")";
131     }
132     $smarty->assign("goExportEntry",array_keys($tellSmarty));
133     $smarty->assign("goExportEntryKeys",($tellSmarty));
134     $smarty->assign("goExportEntryACL", chkacl($this->acl, "goExportEntry"));
137     return($smarty->fetch(get_template_path("goShareServer.tpl",TRUE,dirname(__FILE__))));
138   }
141   function getListEntry()
142   {
143     $flag = $this->StatusFlag;
144     $fields['Status']     = $this->$flag;
145     $fields['Message']    = _("Shares");
146     $fields['AllowStart'] = true;
147     $fields['AllowStop']  = true;
148     $fields['AllowReset'] = true;
149     $fields['AllowRemove']= true;
150     $fields['AllowEdit']  = true;
151     return($fields);
152   }
155   function remove_from_parent()
156   {
157     plugin::remove_from_parent();
158     /* Check if this is a new entry ... add/modify */
159     $ldap = $this->config->get_ldap_link();
160     $ldap->cat($this->dn,array("objectClass"));
161     if($ldap->count()){
162       $ldap->cd($this->dn);
163       $ldap->modify($this->attrs);
164     }else{
165       $ldap->cd($this->dn);
166       $ldap->add($this->attrs);
167     }
168     show_ldap_error($ldap->get_error());
169   }
172   function save()
173   {
174     plugin::save();
176     /* Arrays */
177     foreach (array("goExportEntryList"=>"goExportEntry") as $source => $destination){
178       $this->attrs[$destination]= array();
179       foreach ($this->$source as $element){
180         $this->attrs[$destination][]= $element;
181       }
182     }
185     /* Process netatalk mounts */
186     if($this->allow_mounts) {
187       $this->process_mounts();
188     }
191     /* Check if this is a new entry ... add/modify */
192     $ldap = $this->config->get_ldap_link();
193     $ldap->cat($this->dn,array("objectClass"));
194     if($ldap->count()){
195       $ldap->cd($this->dn);
196       $ldap->modify($this->attrs);
197     }else{
198       $ldap->cd($this->dn);
199       $ldap->add($this->attrs);
200     }
201     show_ldap_error($ldap->get_error());
202   }
205   /* Directly save new status flag */
206   function setStatus($value)
207   {
208     $ldap = $this->config->get_ldap_link();
209     $ldap->cd($this->dn);
210     $ldap->cat($this->dn,array("objectClass"));
212     if($ldap->count()){
213       $attrs =array();
214       foreach(array() as $req) {
215         if(!isset($attrs[$req])){
216           if(empty($this->$req)){
217             print_red(sprintf(_("The required attribute '%s' is not set."),$req));
218           }else{
219             $attrs[$req] = $this->$req;
220           }
221         }else{
222           $attrs[$req] = $attrs[$req][0];
223         }
224       }
226       $tmp = $ldap->fetch();
227       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
228         $attrs['objectClass'][] = $tmp['objectClass'][$i];
229       }    
230       if(!in_array("goShareServer",$attrs['objectClass'])){
231         $attrs['objectClass'][] = "goShareServer";
232       }
234       $flag = $this->StatusFlag;
235       $attrs[$flag] = $value;
236       $this->$flag = $value;
237       $ldap->modify($attrs);
238       show_ldap_error($ldap->get_error());
239     }    
240   }
243   function check()
244   { 
245     $message = plugin::check();
246     return($message);
247   }
250   function save_object()
251   {
252     if(isset($_POST['goShareServerPosted'])){
253       plugin::save_object();
254     }
255   } 
257   function addToList($entry){
258     $key =  key($entry);
259     $this->goExportEntryList[$key]=$entry[$key];
260   }
262   function deleteFromList($id){
263     unset($this->goExportEntryList[$id]);
264   }
268 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
269 ?>