4ecd34188730b49db54371f4a50e09f8ffde1b6c
1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id: class_gotomasses.inc 10967 2008-05-20 13:18:12Z hickert $$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
24 /*! \brief The DAK keyring class used to manage DAK keyrings.
25 It provides remove/add key mehtods and lists all keys for a selected server.
26 */
27 class dakkeyring extends plugin
28 {
29 private $Servers = array();
30 private $selected_Server = array();
31 private $list = array();
32 public $attributes = array("selected_Server");
35 /*! \brief Creates a dak_keyring class.
36 @param The GOsa configuration object.
37 */
38 public function __construct($config)
39 {
40 plugin::plugin($config,NULL);
42 /* Collect release servers and store them
43 */
44 $this->Servers = DAK::get_repositories_by_server($this->config);
45 if(count($this->Servers)){
46 $this->selected_Server = key($this->Servers);
47 }
48 }
51 /*! \brief Create HTML output for this plugin.
52 @return String HTML output.
53 */
54 public function execute()
55 {
56 if(isset($_POST['search'])){
57 $this->refresh_list();
58 }
60 $smarty= get_smarty();
61 $smarty->assign("Servers" , $this->Servers);
62 $smarty->assign("selected_Server" , $this->selected_Server);
63 $smarty->assign("list",$this->CreateList());
64 return($smarty->fetch (get_template_path('dak_keyring.tpl', TRUE, dirname(__FILE__))));
65 }
68 /*! \brief Refresh the list of keys for the currently selected server
69 This function is automatically called when a key was added and removed.
70 */
71 private function refresh_list()
72 {
73 $details = array();
74 foreach($this->list as $entry){
75 if(isset($entry['DETAILS']) && $entry['DETAILS'] && isset($entry['ATTRIBUTES']['UID'])){
76 $details[] = $entry['ATTRIBUTES']['UID'];
77 }
78 }
80 $tmp = DAK::list_keys($this->Servers[$this->selected_Server]['MAC']);
81 $this->list = array();
82 foreach($tmp as $entry){
83 if(isset($entry['ATTRIBUTES']['UID']) && in_array($entry['ATTRIBUTES']['UID'],$details)){
84 $entry['DETAILS'] = TRUE;
85 }
86 $this->list[] = $entry;
87 }
88 }
91 /*! \brief Creates the HTML output representing the keylist
92 for this currently selected server
93 @return String HTML list containig all keys for the selected server.
94 */
95 private function CreateList()
96 {
97 $divlist = new divlist("DAK_keyring");
98 $divlist->SetWidth("100%");
99 $divlist->SetHeight("450px");
100 $divlist->SetEntriesPerPage(0);
102 /* Set default col styles
103 */
104 $s0 = "style='width:10px;'";
105 $s1 = "style='width:70px;'";
106 $s2 = "style='width:50px;'";
107 $s3 = "style='width:130px;'";
108 $s4 = "";
109 $s5 = "style='text-align: right;width:50px; border-right:0px;'";
111 /* Add header
112 */
113 $h0 = array("string" => "", "attach" => $s0);
114 $h1 = array("string" => _("Key ID"), "attach" => $s1);
115 $h2 = array("string" => _("Length"), "attach" => $s2);
116 $h3 = array("string" => _("Status"), "attach" => $s3);
117 $h4 = array("string" => _("UID"), "attach" => $s4);
118 $h5 = array("string" => _("Action"), "attach" => $s5);
119 $divlist->SetHeader(array($h0,$h1,$h2,$h3,$h4,$h5));
121 /* Add entries
122 */
123 foreach($this->list as $key => $entry){
125 /* Check if all attributes are given
126 */
127 if(!is_array($entry['UID'])){
128 $entry['UID'] = array($entry['UID']);
129 }
130 $key_id = $length = $created = $expired = $expires = "";
132 foreach(array("key_id"=>"UID","length"=>"LENGTH","created"=>"CREATED","expired"=>"EXPIRED","expires"=>"EXPIRES") as $var => $name){
133 if(isset($entry['ATTRIBUTES'][$name])){
134 $$var = $entry['ATTRIBUTES'][$name];
135 }
136 }
138 $status ="-";
139 $title = " title='".sprintf(_("Created: %s"),$created)."' ";
140 if(empty($expires) && empty($expired)) $status = "<font $title style='color:green;'>"._("Valid")."</font>";
141 if(!empty($expired)) $status = "<font $title style='color:red; font-size:bold'>"._("Expired: ").$expired."</font>";
142 if(!empty($expires)) $status = "<font $title style='color:green;'>"._("Expires: ").$expires."</font>";
144 /* Create detail icon
145 */
146 $hide = "<input type='image' name='details_".$key."' src='images/forward-arrow.png' alt='-' class='center'> ";
147 $down = "<input type='image' name='details_".$key."' src='images/down-arrow.png' alt='+' class='center'> ";
149 $actions = "<input type='image' class='center' alt='".msgPool::delButton()."'
150 src='images/lists/trash.png' name='remove_key_".$key."'>";
152 /* Add detailed entry
153 (All UIDs are listed, each in a single column)
154 */
155 if(isset($entry['DETAILS']) && $entry['DETAILS'] == TRUE){
156 $first = TRUE;
157 foreach($entry['UID'] as $val){
159 $f0 = array("string" => "","attach" => $s0);
160 $f1 = array("string" => "","attach" => $s1);
161 $f2 = array("string" => "","attach" => $s2);
162 $f3 = array("string" => "","attach" => $s3);
163 $f4 = array("string" => htmlentities(utf8_decode($val),ENT_QUOTES,"UTF-8"), "attach" => $s4);
164 $f5 = array("string" => "","attach" => $s5);
166 if($first){
167 $first = FALSE;
168 $f0 = array("string" => $hide ,"attach" => $s0);
169 $f1 = array("string" => $key_id ,"attach" => $s1);
170 $f2 = array("string" => $length ,"attach" => $s2);
171 $f3 = array("string" => $status ,"attach" => $s3);
172 $f4 = array("string" => htmlentities(utf8_decode($val),ENT_QUOTES,"UTF-8"), "attach" => $s4);
173 $f5 = array("string" => $actions ,"attach" => $s5);
174 }
175 $divlist->AddEntry(array($f0,$f1,$f2,$f3,$f4,$f5));
176 }
177 }else{
179 /* Add non detailed entries, just the first uid is displayed.
180 */
181 if(count($entry['UID']) > 1){
182 $f0 = array("string" => $down, "attach" => $s0);
183 }else{
184 $f0 = array("string" => "", "attach" => $s0);
185 }
186 $f1 = array("string" => $key_id, "attach" => $s1);
187 $f2 = array("string" => $length, "attach" => $s2);
188 $f3 = array("string" => $status, "attach" => $s3);
189 $f4 = array("string" => htmlentities(utf8_decode($entry['UID'][0]),ENT_QUOTES,"UTF-8"), "attach" => $s4);
190 $f5 = array("string" => $actions,"attach" => $s5);
191 $divlist->AddEntry(array($f0,$f1,$f2,$f3,$f4,$f5));
193 }
194 }
195 return($divlist->DrawList());
196 }
199 /*! \brief Act on the HTML posts for this plugin
200 */
201 public function save_object()
202 {
203 plugin::save_object();
205 /* Save html posts, like the selected repository server
206 */
207 foreach($this->attributes as $attr){
208 if(isset($_POST[$attr])){
209 $this->$attr = get_post($attr);
210 }
211 }
213 /* Display details icon was clicked
214 */
215 foreach($_POST as $name => $value){
216 if(preg_match("/^remove_key_/",$name)){
217 $id = preg_replace("/^remove_key_([0-9]*)_.*$/","\\1",$name);
218 $this->remove_key($id);
219 $this->refresh_list();
220 break;
221 }
223 if(preg_match("/^details_/",$name)){
224 $id = preg_replace("/^details_([0-9]*)_.*$/","\\1",$name);
225 if(isset($this->list[$id])){
226 if(!isset($this->list[$id]['DETAILS']) || !$this->list[$id]['DETAILS']){
227 $this->list[$id]['DETAILS'] = TRUE;
228 }else{
229 $this->list[$id]['DETAILS'] = FALSE;
230 }
231 break;
232 }
233 }
234 }
236 /* Import new keys
237 */
238 if(isset($_POST['import_key']) && isset($_FILES['import'])){
239 if($_FILES['import']['size'] != 0){
240 $key = file_get_contents($_FILES['import']['tmp_name']);
241 if($this->import_key($key)){
242 $this->refresh_list();
243 }
244 }
245 }
246 }
249 /*! \brief Removes the given key from the keyring server.
250 @return Boolean TRUE in case of success else FALSE.
251 */
252 private function remove_key($key)
253 {
254 if($this->list[$key]){
255 $mac = $this->Servers[$this->selected_Server]['MAC'];
256 return(DAK::remove_key($mac,$this->list[$key]['ATTRIBUTES']['UID']));
257 }
258 }
261 /*! \brief Imports a new key into the keyring for the currently selected server
262 @return Boolean TRUE in case of success else FALSE.
263 */
264 private function import_key($key)
265 {
266 $mac = $this->Servers[$this->selected_Server]['MAC'];
267 return(DAK::import_key($mac,$key));
268 }
271 /*! \brief ACL plugin information
272 */
273 static function plInfo()
274 {
275 return (array(
276 "plShortName" => _("DAK keyring")." ("._("Addon").")",
277 "plDescription" => _("DAK keyring management")." ("._("Addon").")",
278 "plSelfModify" => FALSE,
279 "plDepends" => array(),
280 "plPriority" => 98,
281 "plSection" => array("addon"),
282 "plCategory" => array("server"),
283 "plProvidedAcls" =>
284 array(
285 )
286 ));
287 }
288 }
289 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
290 ?>