Servers = DAK::get_repositories_by_server($this->config);
if(count($this->Servers)){
$this->selected_Server = key($this->Servers);
}
}
/*! \brief Create HTML output for this plugin.
@return String HTML output.
*/
public function execute()
{
if(isset($_POST['search'])){
$this->refresh_list();
}
$smarty= get_smarty();
$smarty->assign("Servers" , $this->Servers);
$smarty->assign("selected_Server" , $this->selected_Server);
$smarty->assign("list",$this->CreateList());
return($smarty->fetch (get_template_path('dak_keyring.tpl', TRUE, dirname(__FILE__))));
}
/*! \brief Refresh the list of keys for the currently selected server
This function is automatically called when a key was added and removed.
*/
private function refresh_list()
{
$this->list = DAK::list_keys($this->Servers[$this->selected_Server]['MAC']);
}
/*! \brief Creates the HTML output representing the keylist
for this currently selected server
@return String HTML list containig all keys for the selected server.
*/
private function CreateList()
{
$divlist = new divlist("DAK_keyring");
$divlist->SetWidth("100%");
$divlist->SetHeight("450px");
$divlist->SetEntriesPerPage(0);
/* Set default col styles
*/
$s0 = "style='width:10px;'";
$s1 = "style='width:100px;'";
$s2 = "style='width:100px;'";
$s3 = "style='width:100px;'";
$s4 = "";
$s5 = "style='width:100px; border-right:0px;'";
/* Add header
*/
$h0 = array("string" => "", "attach" => $s0);
$h1 = array("string" => _("Key ID"), "attach" => $s1);
$h2 = array("string" => _("Length"), "attach" => $s2);
$h3 = array("string" => _("Validity"), "attach" => $s3);
$h4 = array("string" => _("UID"), "attach" => $s4);
$h5 = array("string" => _("Action"), "attach" => $s5);
$divlist->SetHeader(array($h0,$h1,$h2,$h3,$h4,$h5));
/* Add entries
*/
foreach($this->list as $key => $entry){
/* Check if all attributes are given
*/
if(!is_array($entry['UID'])){
$entry['UID'] = array($entry['UID']);
}
$key_id = $length = $valid = "";
if(isset($entry['ATTRIBUTES']['UID'])){
$key_id = $entry['ATTRIBUTES']['UID'];
}
if(isset($entry['ATTRIBUTES']['LENGTH'])){
$length = $entry['ATTRIBUTES']['LENGTH'];
}
if(isset($entry['ATTRIBUTES']['VALID'])){
$valid = $entry['ATTRIBUTES']['VALID'];
}
/* Create detail icon
*/
$hide = " ";
$down = " ";
$actions = "";
/* Add detailed entry
(All UIDs are listed, each in a single column)
*/
if(isset($entry['DETAILS']) && $entry['DETAILS'] == TRUE){
$first = TRUE;
foreach($entry['UID'] as $val){
$f0 = array("string" => "","attach" => $s0);
$f1 = array("string" => "","attach" => $s1);
$f2 = array("string" => "","attach" => $s2);
$f3 = array("string" => "","attach" => $s3);
$f4 = array("string" => htmlentities($val) ,"attach" => $s4);
$f5 = array("string" => "","attach" => $s5);
if($first){
$first = FALSE;
$f0 = array("string" => $hide ,"attach" => $s0);
$f1 = array("string" => $key_id ,"attach" => $s1);
$f2 = array("string" => $length ,"attach" => $s2);
$f3 = array("string" => $valid ,"attach" => $s3);
$f4 = array("string" => htmlentities($val) ,"attach" => $s4);
$f5 = array("string" => $actions ,"attach" => $s5);
}
$divlist->AddEntry(array($f0,$f1,$f2,$f3,$f4,$f5));
}
}else{
/* Add non detailed entries, just the first uid is displayed.
*/
if(count($entry['UID']) > 1){
$f0 = array("string" => $down, "attach" => $s0);
}else{
$f0 = array("string" => "", "attach" => $s0);
}
$f1 = array("string" => $key_id, "attach" => $s1);
$f2 = array("string" => $length, "attach" => $s2);
$f3 = array("string" => $valid, "attach" => $s3);
$f4 = array("string" => htmlentities($entry['UID'][0]), "attach" => $s4);
$f5 = array("string" => $actions,"attach" => $s5);
$divlist->AddEntry(array($f0,$f1,$f2,$f3,$f4,$f5));
}
}
return($divlist->DrawList());
}
/*! \brief Act on the HTML posts for this plugin
*/
public function save_object()
{
plugin::save_object();
/* Save html posts, like the selected repository server
*/
foreach($this->attributes as $attr){
if(isset($_POST[$attr])){
$this->$attr = get_post($attr);
}
}
/* Display details icon was clicked
*/
foreach($_POST as $name => $value){
if(preg_match("/^remove_key_/",$name)){
$id = preg_replace("/^remove_key_([0-9]*)_.*$/","\\1",$name);
$this->remove_key($id);
break;
}
if(preg_match("/^details_/",$name)){
$id = preg_replace("/^details_([0-9]*)_.*$/","\\1",$name);
if(isset($this->list[$id])){
if(!isset($this->list[$id]['DETAILS']) || !$this->list[$id]['DETAILS']){
$this->list[$id]['DETAILS'] = TRUE;
}else{
$this->list[$id]['DETAILS'] = FALSE;
}
break;
}
}
}
/* Import new keys
*/
if(isset($_POST['import_key']) && isset($_FILES['import'])){
if($_FILES['import']['size'] != 0){
$key = file_get_contents($_FILES['import']['tmp_name']);
if($this->import_key($key)){
$this->refresh_list();
}
}
}
}
/*! \brief Removes the given key from the keyring server.
@return Boolean TRUE in case of success else FALSE.
*/
private function remove_key($key)
{
if($this->list[$key]){
$mac = $this->Servers[$this->selected_Server]['MAC'];
return(DAK::remove_key($mac,$this->list[$key]['ATTRIBUTES']['UID']));
}
}
/*! \brief Imports a new key into the keyring for the currently selected server
@return Boolean TRUE in case of success else FALSE.
*/
private function import_key($key)
{
$mac = $this->Servers[$this->selected_Server]['MAC'];
return(DAK::import_key($mac,$key));
}
/*! \brief ACL plugin information
*/
static function plInfo()
{
return (array(
"plShortName" => _("DAK keyring")." ("._("Addon").")",
"plDescription" => _("DAK keyring management")." ("._("Addon").")",
"plSelfModify" => FALSE,
"plDepends" => array(),
"plPriority" => 98,
"plSection" => array("addon"),
"plCategory" => array("server"),
"plProvidedAcls" =>
array(
)
));
}
}
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
?>