1 <?php
3 class servRepositorySetup extends plugin
4 {
5 /* CLI vars */
6 var $cli_summary = "Manage FAI repositories";
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("Release","ParentServer","Url","cn");
13 var $objectclasses = array("whatever");
15 /* Attributes */
16 var $Release = "";
17 var $ParentServer = "";
18 var $Url = "";
19 var $Sections = array();
20 var $ParentServers = "";
21 var $initialy_was = false;
22 var $cn = "";
23 var $parent = "";
25 function servRepositorySetup ($config, $dn= NULL,$data = false)
26 {
27 plugin::plugin ($config, $dn);
28 if($data != false){
29 foreach(array("Sections","Release","Url","ParentServer","initialy_was") as $atr){
30 if(isset($data[$atr])){
31 $this->$atr = $data[$atr];
32 }
33 }
34 }
35 }
37 function GetName()
38 {
39 return($this->Release);
40 }
42 function is_new_name()
43 {
44 if(!$this->initialy_was){
45 return(true);
46 }else{
47 if($this->Release != $this->initialy_was){
48 return(true);
49 }
50 }
51 return(false);
52 }
56 function execute()
57 {
58 /* Call parent execute */
59 plugin::execute();
61 /* Fill templating stuff */
62 $smarty= get_smarty();
64 if((isset($_POST['AddSection']))&&(isset($_POST['SectionName']))&&(!empty($_POST['SectionName']))){
66 /* Replace multiple spaces with a single, and cut of white spaces (trim)*/
67 $val = preg_replace("/\ \ * /" , " ", trim($_POST['SectionName']));
69 /* check if there are more than one entry given ( "section1 section2 )*/
70 if(preg_match("/ /",$val)){
72 /* Generate list of new section names */
73 $vals = split(" ",$val);
75 /* Add new entries */
76 foreach($vals as $entry){
77 $entry = trim($entry);
78 $this->Sections[$entry]=$entry;
79 }
80 }else{
81 $this->Sections[$val]=$val;
82 }
83 }
85 foreach($_POST as $name => $value){
86 if(preg_match("/^delete_/",$name)){
88 $val = preg_replace("/^delete_/","",$name);
89 $val = base64_decode(preg_replace("/_.*$/","",$val));
91 if(isset($this->Sections[$val])){
92 unset($this->Sections[$val]);
93 }
94 }
95 }
97 $divlist = new divSelectBox("servRepositorySetup");
98 $divlist->setHeight("220");
100 $dellink = "<input type='image' src='images/edittrash.png' title='delete' alt='delete' name='delete_%s' value='%s'>";
102 foreach($this->Sections as $sec){
103 $divlist->AddEntry(array(
104 array("string"=>$sec),
105 array("string"=>sprintf($dellink,base64_encode($sec),$sec),"attach"=>"style='border-right:0px;width:20px;'")
106 ));
107 }
109 $smarty->assign("Sections",$divlist->DrawList());
111 /* Get && assign acls */
112 $tmp = $this->parent->plInfo();
113 foreach($tmp['plProvidedAcls'] as $name => $translated){
114 $smarty->assign($name."ACL",$this->parent->getacl($name));
115 }
117 /* Assign values */
118 foreach($this->attributes as $attr){
119 $smarty->assign($attr ,$this->$attr);
120 }
122 $tmp = $this->getParentServers();
123 $smarty->assign("ParentServers" ,$tmp);
124 $smarty->assign("ParentServerKeys",array_flip($tmp));
126 return($smarty->fetch(get_template_path('servRepositorySetup.tpl', TRUE)));
127 }
129 /* Save data to object */
130 function save_object()
131 {
132 plugin::save_object();
133 }
136 /* Check supplied data */
137 function check()
138 {
139 /* Call common method to give check the hook */
140 $message= plugin::check();
142 if(empty($this->Release)){
143 $message[]=_("Please enter a value for 'release'.");
144 }
146 if(empty($this->Url)){
147 $message[] = _("Please specify a valid value for 'url'.");
148 }
150 return ($message);
151 }
154 /* Save to LDAP */
155 function save()
156 {
157 $tmp = array();
158 $tmp['ParentServer'] = $this->ParentServer;
159 $tmp['Url'] = $this->Url;
160 $tmp['Release'] = $this->Release;
161 $tmp['Sections'] = $this->Sections;
162 return($tmp);
163 }
165 function getParentServers()
166 {
167 $ret = array();
168 $ldap = $this->config->get_ldap_link();
169 $ldap->cd($this->config->current['BASE']);
170 $ldap->search("(objectClass=FAIrepositoryServer)",array("*"));
171 while($attr = $ldap->fetch()){
172 if($attr['cn'][0] == $this->cn) continue;
173 $ret[$attr['cn'][0]]= $attr['cn'][0];
174 }
176 $ret = array_merge($ret,$this->GetHookElements());
178 $ret['none']= " ";
179 asort($ret);
180 return($ret);
181 }
183 /* this funtions calls a defined hook
184 and parses all additional serverdata
185 */
186 function GetHookElements()
187 {
188 $ret = array();
189 $cmd= search_config($this->config->data['TABS'], "servrepository", "REPOSITORY_HOOK");
190 if(!empty($cmd)){
191 $res = shell_exec($cmd);
192 $res2 = trim($res);
193 if(!$res){
194 print_red(sprintf(_("Can't execute specified REPOSITORY_HOOK '%s'. Please check your gosa.conf."),$cmd));
195 }elseif(empty($res2)){
196 print_red(sprintf(_("The specified REPOSITORY_HOOK '%s', specified in your gosa.conf, returns an empty string."),$cmd));
197 }else{
198 $tmp = split("\n",$res);
199 foreach($tmp as $hook){
200 /* skip empty */
201 if(empty($hook)) continue;
203 if(preg_match("/;/",$hook)){
204 $hookinfo = split(";",$hook);
205 $ret[$hookinfo[0]] = $hookinfo[0];
206 }else{
207 $ret[$hook] = $hook;
208 }
209 }
210 }
211 }
212 return($ret);
213 }
215 }
217 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
218 ?>