From: hickert Date: Mon, 18 Oct 2010 09:08:49 +0000 (+0000) Subject: Moved config mangement plugin X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=91b9be4ec1b30e3916bbfb34e339b60f67470fd7;p=gosa.git Moved config mangement plugin git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@20076 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-plugins/goto/admin/ConfigManagement/AddItemDialog.tpl b/gosa-plugins/goto/admin/ConfigManagement/AddItemDialog.tpl new file mode 100644 index 000000000..2d9823c07 --- /dev/null +++ b/gosa-plugins/goto/admin/ConfigManagement/AddItemDialog.tpl @@ -0,0 +1,21 @@ + +

{t}Add item{/t}

+ +{t}Please specify a name for the item to add, this name has to be uniq within the item configuration.{/t} +
+ +
+ +

+ {$itemCfg.name} -  {$itemCfg.description} +

+ +{t}Name{/t}:  + +
+ +
+ + +
+ diff --git a/gosa-plugins/goto/admin/ConfigManagement/DeviceConfig-filter.xml b/gosa-plugins/goto/admin/ConfigManagement/DeviceConfig-filter.xml new file mode 100644 index 000000000..183ddd4ce --- /dev/null +++ b/gosa-plugins/goto/admin/ConfigManagement/DeviceConfig-filter.xml @@ -0,0 +1,26 @@ + + + + + true + Device + auto + default + - + + + + default + + + DeviceItems + $ + + + cn + 0.5 + 3 + + + + diff --git a/gosa-plugins/goto/admin/ConfigManagement/DeviceConfig-list.tpl b/gosa-plugins/goto/admin/ConfigManagement/DeviceConfig-list.tpl new file mode 100644 index 000000000..813a1f533 --- /dev/null +++ b/gosa-plugins/goto/admin/ConfigManagement/DeviceConfig-list.tpl @@ -0,0 +1,21 @@ +
+ +
+

{$HEADLINE} {$SIZELIMIT}

+
+ + + + + + + +
{$RELOAD}{t}Base{/t} {$RELEASE}{$ACTIONS}{$FILTER}
+
+
+ + {$LIST} +
+ +
+ diff --git a/gosa-plugins/goto/admin/ConfigManagement/DeviceConfig-list.xml b/gosa-plugins/goto/admin/ConfigManagement/DeviceConfig-list.xml new file mode 100644 index 000000000..9a6812df0 --- /dev/null +++ b/gosa-plugins/goto/admin/ConfigManagement/DeviceConfig-list.xml @@ -0,0 +1,87 @@ + + + + + false + false + false + true + + + 1 + + %TYPES% + + + + + |20px;c|||170px;r| + + + %{filter:objectType(dn,objectClass)} + + + + %{filter:departmentLink(row,dn,description)} + 2 + + + + %{filter:objectType(dn,objectClass)} + + + + + cn + string + %{filter:link(row,dn,"%s",cn,pid)} + true + + + + + description + string + %{filter:link(row,dn,"%s",description,pid)} + true + + + + + %{filter:actions(dn,row,objectClass)} + + +
+ + + + %ITEMS% + + + remove + entry + images/lists/trash.png + + + + + + + + + editEntry + entry + images/lists/edit.png + + + + + remove + entry + images/lists/trash.png + + + + + +
diff --git a/gosa-plugins/goto/admin/ConfigManagement/DeviceConfig.tpl b/gosa-plugins/goto/admin/ConfigManagement/DeviceConfig.tpl new file mode 100644 index 000000000..0bb627e8c --- /dev/null +++ b/gosa-plugins/goto/admin/ConfigManagement/DeviceConfig.tpl @@ -0,0 +1,12 @@ +

{t}Device Config{/t}

+{$navigationList} + + +
+ +{$containerName} ({$containerDescription}) + +

+{$template} +

+ diff --git a/gosa-plugins/goto/admin/ConfigManagement/TemplateEngine.tpl b/gosa-plugins/goto/admin/ConfigManagement/TemplateEngine.tpl new file mode 100644 index 000000000..e60c5ae1c --- /dev/null +++ b/gosa-plugins/goto/admin/ConfigManagement/TemplateEngine.tpl @@ -0,0 +1,11 @@ +

Bla

+ +{$template} + +
+ +
+ + +
+ diff --git a/gosa-plugins/goto/admin/ConfigManagement/TemplateWidget_textEditor.tpl b/gosa-plugins/goto/admin/ConfigManagement/TemplateWidget_textEditor.tpl new file mode 100644 index 000000000..4f2ae450e --- /dev/null +++ b/gosa-plugins/goto/admin/ConfigManagement/TemplateWidget_textEditor.tpl @@ -0,0 +1,12 @@ +{if $write_protect} + {t}The text is write protected, due to its encoding. Editing may break it!{/t} +
+ +{/if} + +
+   + +
diff --git a/gosa-plugins/goto/admin/ConfigManagement/class_AddItemDialog.inc b/gosa-plugins/goto/admin/ConfigManagement/class_AddItemDialog.inc new file mode 100644 index 000000000..461508f5f --- /dev/null +++ b/gosa-plugins/goto/admin/ConfigManagement/class_AddItemDialog.inc @@ -0,0 +1,61 @@ +config = $config; + $this->itemCfg = $itemCfg; + $this->itemType = $itemType; + } + + function execute() + { + $smarty = get_smarty(); + $smarty->assign('itemCfg', set_post($this->itemCfg)); + $smarty->assign('itemName', set_post($this->itemName)); + return($smarty->fetch(get_template_path('goto/Config/AddItemDialog.tpl', TRUE))); + } + + function getItemCfg() + { + return($this->itemCfg); + } + + function getName() + { + return($this->itemName); + } + + function getItemType() + { + return($this->itemType); + } + + function save_object() + { + if(isset($_POST['itemName'])){ + $this->itemName = get_post('itemName'); + } + } + + function check() + { + $message = array(); + if(empty($this->itemName)){ + $message[] = msgPool::required(_("Name")); + }else + if(!tests::is_uid($this->itemName)){ + $message[] = msgPool::invalid(_("Name")); + } + return($message); + } +} + +?> diff --git a/gosa-plugins/goto/admin/ConfigManagement/class_DeviceConfig.inc b/gosa-plugins/goto/admin/ConfigManagement/class_DeviceConfig.inc new file mode 100644 index 000000000..b6b28d0ca --- /dev/null +++ b/gosa-plugins/goto/admin/ConfigManagement/class_DeviceConfig.inc @@ -0,0 +1,630 @@ +TemplateEngine = new TemplateEngine($config); + $this->TemplateEngine->setTemplate('puppet.tpl'); + $this->config = $config; + + // Set storage points - We do not have any - We just create a fake list which lists all items + $this->storagePoints = array(""); + + // Try to initialize + $this->init(); + $this->rebuildListing(); + } + + + /*! \brief Sets the installation method to the given method. + * Updates the template engine and adds the initial root + * object for the selected method. + * @param The method to use. + * @return TRUE on success else FALSE. + */ + function setInstallMethod($str) + { + $this->is_account = FALSE; + if(!isset($this->allItemConfigurations[$str])){ + $this->itemConfig = array(); + $this->invalidInstallMethod =TRUE; + $this->errorMessage = sprintf(_("Invalid installation method selected '%s'!"), $str); + msg_dialog::display(_("Setup"), $this->errorMessage, ERROR_DIALOG); + return(FALSE); + }else{ + + $this->itemConfig = $this->allItemConfigurations[$str]['items']; + $this->invalidInstallMethod =FALSE; + $this->TemplateEngine->load($this->itemConfig); + + // Detect root item, its name is / + $root = NULL; + foreach($this->itemConfig as $key => $item){ + if($item['name'] == '/') { + $root = $key; + break; + } + } + if(!$root){ + $this->errorMessage = sprintf(_("Installation method '%s' is invalid, no root object found!"), $str); + msg_dialog::display(_("Setup"), $this->errorMessage , ERROR_DIALOG); + $this->initFailed = TRUE; + $this->itemConfig = array(); + return(FALSE); + } + + // Set current item to 'root', this is the minimum to get things running. + $idRoot = $this->addItem($root,'root',array()); + $this->rootItemID = $idRoot; + $this->setCurrentItem($idRoot); + $this->setSelectedListItemID($idRoot); + $this->is_account = TRUE; + $this->rebuildListing(); + return(TRUE); + } + } + + + /*! \brief Intializes this plugin + * All available installation methods will be loaded + * and populated. + */ + function init() + { + // Reset erros + $this->rpcError = $this->initFailed = FALSE; + + // Load configuration via rpc. + $rpc = $this->config->getRpcHandle(); + + // Populate install methods on success. + $res = $rpc->getSupportedInstallMethods(); + if(!$rpc->success()){ + $this->rpcError = TRUE; + $this->errorMessage = $rpc->get_error();; + return; + } + $this->allItemConfigurations = $res; + if(!count($this->allItemConfigurations)){ + $this->errorMessage = _("No selectable install methods returned!"); + msg_dialog::display(_("Setup"), $this->errorMessage , ERROR_DIALOG); + $this->initFailed = TRUE; + return; + } + } + + + /*! \brief Add a new child-item to the currently selected one. + * + * @param String type The 'type' of the new object, eg. 'KickstartTemplate' + * @param String name The 'name' of the new object. + * @param Array values The initial values for this object. + * @return + */ + function addItem($type,$name, $values = array()) + { + if(!isset($this->itemConfig[$type])){ + echo "Invalid type {$type}, skipping item!
"; + return; + } + + // Add missing values with the item-type defaults. + $allValuesSet = TRUE; + foreach($this->itemConfig[$type]['options'] as $oName => $oValue){ + if(!isset($values[$oName])){ + $values[$oName] = (isset($oValue['default']))?$oValue['default']:""; + } + } + + // Get the currently selected entry, its the parent for the newly + // added one. + $current = &$this->currentItem; + + // Create a FAKE base to be able to use the management lists + // which are currently ldap and thus dn based. + $base = (isset($current['base']))? ",".$current['base'] : ''; + $base = "{$type}={$name}{$base}"; + + + if(isset($this->mappingBaseToID[$base])){ + echo "Cannot add entry, dn already in use! {$base}
"; + return(null); + } + + // Get next free item slot. + $id = ($this->lastItemID ++); + $new = array( + 'base' => $base, + 'children' => array(), + 'id' => $id, + 'type' => $type, + 'name' => $name, + 'values' => $values); + + // Append the entry to the list of all items. + $this->allConfiguredItems[$id] = $new; + + // Create a child referenc, this creates some kind of entry tree. + $current['children'][$id] = &$this->allConfiguredItems[$id]; + + // Add entries to the list of base and id mappings + // this allows us to easily detect the base for an id and vice versa. + $this->mappingBaseToID[$id] = $base; + $this->mappingBaseToID[$base] = $id; + return($id); + } + + + /*! \brief Selects an item as active. + * All further add and remove actions will be performed + * on the obejcts children. + * @param String The 'id' of the item we want to select. + * @return + */ + function setCurrentItem($item) + { + if(!isset($this->allConfiguredItems[$item])){ + echo "Invalid item name {$name}! Skipping selection!"; + return; + } + + // Set the new item info. + $this->currentItem = &$this->allConfiguredItems[$item]; + $this->currentItemType = $this->currentItem['type']; + $this->currentItemDescriptor = $this->itemConfig[$this->currentItem['type']]; + } + + + /*! \brief Removes a given item ID. + * @param String The 'id' of the item we want to remove. + * @return + */ + function removeItem($id, &$data = NULL) + { + if($data === NULL){ + $data = &$this->allConfiguredItems; + } + + // Remove the item and its children + if(isset($data[$id])){ + foreach($data[$id]['children'] as $cid => $item){ + $this->removeItem($cid, $data); + } + unset($data[$id]); + } + + // Remove to current id from sub entries + foreach($data as $key => $item){ + $this->removeItem($id, $data[$key]['children']); + } + } + + + /*! \brief Initiate item edit. + * An action send from the management list. + * @param See management::editEntry + * @return + */ + function editEntry($action="",$target=array(),$all=array(), + $altTabClass ="", $altTabType = "", $altAclCategory="") + { + $this->setCurrentItem($target[0]); + $this->dialogObject = $this->TemplateEngine; + $this->skipFooter = TRUE; + $this->dialog = TRUE; + + // Update the template engine to use another type of item and + // some other values. + $this->TemplateEngine->setValues($this->currentItemType,$this->currentItem['values']); + } + + + /*! \brief Save changes for the currently edited item. + */ + function saveItemChanges() + { + // Save eventually changed values + if($this->currentItem){ + + // Check if everything is fine. + $msgs = $this->TemplateEngine->save_object(); + $msgs = $this->TemplateEngine->check(); + if(count($msgs)){ + msg_dialog::displayChecks($msgs); + }else{ + foreach($this->TemplateEngine->getWidgets() as $widget){ + $this->currentItem['values'][$widget->getName()] = $widget->getValue(); + } + $this->closeDialogs(); + } + } + } + + + /*! \brief React on open requests from the management list + */ + function openEntry($action="",$target=array(),$all=array(), + $altTabClass ="", $altTabType = "", $altAclCategory="") + { + $this->setSelectedListItemID($target[0]); + } + + + /*! \brief Overridden render method of class mangement. + * this allows us to add a release selection box. + */ + function renderList() + { + // In case of an error abort here. + if($this->rpcError || $this->initFailed || $this->invalidInstallMethod){ + $smarty = get_smarty(); + $smarty->assign('initFailed', $this->initFailed); + $smarty->assign('rpcError', $this->rpcError); + $smarty->assign('invalidInstallMethod', $this->invalidInstallMethod); + $smarty->assign('error', $this->errorMessage); + return($smarty->fetch(get_template_path('goto/Config/failed.tpl', TRUE))); + } + + // Do we represent a valid account + if (!$this->is_account){ + $str = "\"\" ". + msgPool::noValidExtension("GOsa").""; + return($str); + } + + // Collect item container list to be able to render the fake-base selector + if(!$this->itemContainerSelector){ + $this->itemContainerSelector = new ItemSelector( + $this->getContainerList(), + $this->base, + $this->allConfiguredItems[$this->rootItemID]['base']); + }else{ + $this->itemContainerSelector->setBases($this->getContainerList()); + } + $this->itemContainerSelector->update(true); + $this->itemContainerSelector->setBase($this->base); + + session::set('DEVICE_ITEMS', $this->allConfiguredItems); + $this->rebuildListing(); + $filter = $this->getFilter(); + $headpage = $this->getHeadpage(); + + $headpage->update(); + $smarty = get_smarty(); + $smarty->assign("RELEASE", $this->itemContainerSelector->render()); + $display = $headpage->render(); + return($this->getHeader().$display); + } + + + /*! \brief Build up a list of items useable for the itemSelector. + */ + function getContainerList($array = NULL) + { + $array = ($array == NULL)?$this->allConfiguredItems[$this->rootItemID]: $array; + $ret[$array['base']] = $array['type']; + if(count($array['children'])){ + foreach($array['children'] as $subItem){ + $ret = array_merge($ret, $this->getContainerList($subItem)); + } + } + return($ret); + } + + + /*! \brief Update the management class and tell her which + * items are available for the itemSelector (baseSelector). + */ + function rebuildListing() + { + // Build filter + if (session::global_is_set(get_class($this)."_filter")){ + $filter= session::global_get(get_class($this)."_filter"); + } else { + $filter = new filter(get_template_path("goto/Config/DeviceConfig-filter.xml", true)); + $filter->setObjectStorage($this->storagePoints); + } + $this->setFilter($filter); + + // Load service xml file and fill in placeholders + $contents =file_get_contents(get_template_path("goto/Config/DeviceConfig-list.xml", true)); + + // Build up device-list configuration + $types =""; + $images = array(); + $images[] = 'images/lists/edit.png'; + $images[] = 'images/caps.png'; + $images[] = 'images/lists/trash.png'; + $images[] = 'images/filter.png'; + $images[] = 'images/find.png'; + $i = 0; + foreach($this->itemConfig as $type => $item){ + $desc = $item['description']; + $img = $images[$i++]; + $types .= + " ". + " ". + " {$type}". + " Device". + " dummy". + " {$img}". + " "; + } + $contents = preg_replace("/%TYPES%/", $types, $contents); + + + $items = ""; + $i = 0; + foreach($this->addableContainerItems as $item){ + $desc = $this->itemConfig[$item]['description']; + $img = $images[$i++]; + $items .= + "". + " add_{$item}". + " entry". + " {$img}". + " ". + ""; + } + + if(!empty($items)){ + $items = + + "". + " sub". + " images/lists/element.png[new]". + " ". + " {$items}". + ""; + } + + $contents = preg_replace("/%ITEMS%/", $items, $contents); + + $headpage = new listing($contents,TRUE); + $headpage->setBase($this->base); + $headpage->setFilter($filter); + + parent::__construct($this->config, $this->ui, "services", $headpage); + + // Register default actions + $this->registerAction("new", "newEntry"); + $this->registerAction("edit", "openEntry"); // !! We forward 'edit' to 'open' to have a department like navigation. + $this->registerAction("editEntry", "editEntry"); + + $this->registerAction("saveItemChanges", "saveItemChanges"); + $this->registerAction("cancelItemEdit", "closeDialogs"); + $this->registerAction("cancelItemAdd", "closeDialogs"); + $this->registerAction("saveItemAdd", "saveItemAdd"); + foreach($this->itemConfig as $name => $item){ + $this->registerAction("add_{$name}", "newEntry"); + } + } + + + /*! \brief This method intiates the object creation. + * + * @param String 'action' The name of the action which was the used as trigger. + * @param Array 'target' A list of object dns, which should be affected by this method. + * @param Array 'all' A combination of both 'action' and 'target'. + */ + function newEntry($action="",$target=array(),$all=array(), + $altTabClass ="", $altTabType = "", $altAclCategory="") + { + $toAdd = preg_replace("/^add_/", "",$action); + $itemToAdd = $this->itemConfig[$toAdd]; + + $this->dialogObject = new AddItemDialog($this->config,$toAdd,$itemToAdd); + $this->dialog = true; + } + + + /*! \brief Saves newly created items and adds them as child to + * the currently selected item. + */ + function saveItemAdd() + { + if(!$this->dialogObject instanceOf AddItemDialog) return; + + $msgs = $this->dialogObject->save_object(); + $msgs = $this->dialogObject->check(); + if(count($msgs)){ + msg_dialog::displayChecks($msgs); + }else{ + $itemName = $this->dialogObject->getName(); + $itemCfg = $this->dialogObject->getItemCfg(); + $itemType = $this->dialogObject->getItemType(); + + $this->setCurrentItem($this->mappingBaseToID[$this->base]); + + $this->addItem($itemType, $itemName); + $this->closeDialogs(); + +# $this->setCurrentItem($itemName); +# $this->dialogObject = $this->TemplateEngine; +# $this->skipFooter = TRUE; +# $this->dialog = TRUE; + + } + } + + + /*! \brief Keep track of posted values, some may be interesting for us. + * Tell the template engine to take care of posted values too. + * @param String + * @return + */ + function save_object() + { + if(isset($_POST['retryInit'])){ + $this->init(); + return; + } + + // Do nothing else in case of an error + if($this->rpcError || $this->initFailed) return; + + // Add sub-module requested. + if(isset($_POST['addSubModule']) && isset($_POST['subModule'])){ + $sub = get_post('subModule'); + if(in_array($sub, $this->currentItemDescriptor['container'])){ + + // Check if this is a valid item + if(!isset($this->itemConfig[$sub])) { + echo "Invalid item type '{$sub}'!"; + $values = array(); + }else{ + $values = $this->itemConfig[$sub]['options']; + } + $name = 'test'.rand(0,99999); + $this->addItem($sub,$name,$values); + } + } + + // Get the selected item-id from the item list and populate it. + if($this->itemContainerSelector){ + $this->itemContainerSelector->update(); + $id = $this->mappingBaseToID[$this->itemContainerSelector->getBase()]; + $this->setSelectedListItemID($id); + } + } + + + /* \brief Updates the currenlty seleted item in the management list + */ + function setSelectedListItemID($id) + { + $this->base = $this->mappingBaseToID[$id]; + $type = $this->allConfiguredItems[$id]['type']; + $this->addableContainerItems = $this->itemConfig[$type]['container']; + } + + + /*! \brief Forward plugin acls + */ + function set_acl_base($base) + { + $this->acl_base = $base; + } + + + /*! \brief Forward plugin acls + */ + function set_acl_category($category) + { + $this->acl_category = $category; + } + + function save() + { + foreach($this->allConfiguredItems as $name => $item){ + foreach($item['values'] as $oName => $oValue){ + if(!is_array($oValue)) $oValue = array($oValue); + foreach($oValue as $val){ + echo "
{$name} -- {$item['type']}: {$oName}: {$val}"; + } + } + } + } + + + /*! \brief Initiates the removal for the given entries + * and displays a confirmation dialog. + * + * @param String 'action' The name of the action which was the used as trigger. + * @param Array 'target' A list of object dns, which should be affected by this method. + * @param Array 'all' A combination of both 'action' and 'target'. + */ + protected function removeEntryRequested($action="",$target=array(),$all=array()) + { + foreach($target as $id){ + $this->removeItem($id); + } + } + + + // Inject user actions + function detectPostActions() + { + if($this->rpcError || $this->initFailed) return(array('action' => '')); + + $action = management::detectPostActions(); + if(isset($_POST['saveItemEdit'])) $action['action'] = "saveItemChanges"; + if(isset($_POST['saveItemAdd'])) $action['action'] = "saveItemAdd"; + if(isset($_POST['cancelItemEdit'])) $action['action'] = "cancelItemEdit"; + if(isset($_POST['cancelItemAdd'])) $action['action'] = "cancelItemAdd"; + return($action); + } + + + function closeDialogs() + { + parent::closeDialogs(); + $this->dialog = false; + } + + + function check() + { + return(array()); + } + + function getRootItemId() + { + return($this->rootItemID); + } +} +?> diff --git a/gosa-plugins/goto/admin/ConfigManagement/class_ItemSelector.inc b/gosa-plugins/goto/admin/ConfigManagement/class_ItemSelector.inc new file mode 100644 index 000000000..f4186de38 --- /dev/null +++ b/gosa-plugins/goto/admin/ConfigManagement/class_ItemSelector.inc @@ -0,0 +1,25 @@ + diff --git a/gosa-plugins/goto/admin/ConfigManagement/class_TemplateEngine.inc b/gosa-plugins/goto/admin/ConfigManagement/class_TemplateEngine.inc new file mode 100644 index 000000000..577079f29 --- /dev/null +++ b/gosa-plugins/goto/admin/ConfigManagement/class_TemplateEngine.inc @@ -0,0 +1,154 @@ +config = &$config; + } + + + /*! \brief Load/Sets the instruction-set to use for the current + * device configuration. + * A device configruation tells us what options + * an item can have and what children. + * @param Array The instruction set to use. + */ + function load($array) + { + $this->data = $array; + } + + + /*! \brief Set the template which will be used to generate + * the HTML content for this configuration session. + * @param String A template filename. + */ + function setTemplate($tmpl) + { + $this->template = $tmpl; + } + + + /*! \brief Returns the list of widgets which are currently used + * by the template engine to render the plugin. + * @return Array A list of widgets. + */ + function getWidgets() + { + return($this->widgets); + } + + + /*! \brief Sets the current item type we want to render + * E.g. 'KickstartTemplate' and the corresponding values. + * + * @param String The name of the item we want to render now. + * @param Array The initial value. + */ + function setValues($name, $values) + { + // Set the current item type and reset the widget list. + $this->itemType = $name; + $this->widgets = array(); + + // Do nothing if something seems to be wrong. + if(!isset($this->data[$this->itemType])){ + echo "Undefined item type '{$name}'!
"; + return; + } + + // Get the options provided by the item and create widget for them. + $data = $this->data[$this->itemType]; + if(isset($data['options']) && count($data['options'])){ + foreach($data['options'] as $name => $item){ + $widgetClassName = "TemplateWidget_{$item['type']}"; + + // Check if the widget is available, if it is not, use a default (string). + if(!class_available($widgetClassName)){ + echo "Unknown widget class {$widgetClassName}! Falling back to default widget.
"; + $widgetClassName = "TemplateWidget_string"; + } + + // Prepare the value for the widget + $value = $values[$name]; + $syntax = (isset($item['syntax']))? $item['syntax']: ""; + $providedValues = (isset($item['values']))? $item['values']: array(); + + // Create the new widget. + $this->widgets[$name] = new $widgetClassName($this->config, $name, + $value, + $item['description'], + $syntax, + $item['required'], + $item['type'], + $item['display'], + $providedValues); + } + } + } + + + function execute(){ + return($this->render()); + } + + + /*! \brief Creates the HTML content for the given list of widgets + * @return String The HTML content. + */ + function render() + { + $smarty = get_smarty(); + $smarty->assign("type", $this->itemType); + + // Tell smarty the HTML-content for each widget and the name that should be + // displayed. + foreach($this->widgets as $widget){ + $smarty->assign($widget->getName(), $widget->render()); + $smarty->assign($widget->getName()."Name", $widget->getDisplayName()); + } + $template = $smarty->fetch(get_template_path("goto/Config/{$this->template}", TRUE)); + + $smarty->assign('template', $template); + return($smarty->fetch(get_template_path("goto/Config/TemplateEngine.tpl", TRUE))); + } + + + /*! \brief Keep track of posted values. + */ + function save_object() + { + foreach($this->widgets as $widget){ + $widget->save_object(); + } + } + + + /*! \brief Check widget values and return a list of errors. + */ + function check() + { + $msgs = array(); + foreach($this->widgets as $widget){ + $msgs = array_merge($msgs, $widget->check()); + } + return($msgs); + } +} + + +?> diff --git a/gosa-plugins/goto/admin/ConfigManagement/class_TemplateWidget.inc b/gosa-plugins/goto/admin/ConfigManagement/class_TemplateWidget.inc new file mode 100644 index 000000000..45f4fae03 --- /dev/null +++ b/gosa-plugins/goto/admin/ConfigManagement/class_TemplateWidget.inc @@ -0,0 +1,122 @@ +config = &$config; + $this->name = $name; + $this->value = $value; + $this->description = $description; + $this->required = $required; + $this->type = $type; + $this->syntax = $syntax; + $this->values = $values; + $this->display = $display; + $class = get_class(); + $this->postName = "{$class}_{$this->name}"; + } + + + /*! \brief Returns the display-name for the current widget. + * @return String The display-name for the widget, this + * name will usually be rendered infront of input fields. + */ + function getDisplayName() + { + $must = ($this->required)?"*":""; + return($this->display.$must); + } + + + /*! \brief Returns the description for the widget. + */ + function getDescription() + { + return($this->description); + } + + + /*! \brief Generates the HTML code for the widget. + * @return The HTML content for the widget. + */ + function render() + { + return(""); + } + + + /*! \brief Keep track of posted values. + */ + function save_object() + { + if(isset($_POST[$this->postName])){ + $this->value = get_post($this->postName); + } + } + + + /*! \brief Returns the current value. + * @return Mixed The widgets value. + */ + function getValue() + { + return($this->value); + } + + + /*! \brief Returns the name of the widget. + * @param String The widgets name. + */ + function getName() + { + return($this->name); + } + + + /*! \brief Sets a new value for the widget. + * @param String The new value. + */ + function setValue($value) + { + $this->value = $value; + } + + + /*! \brief Check the value entry using the provieded syntax. + * @return Array Returns a list of errors + */ + function check() + { + if($this->required && empty($this->value)){ + return(array(msgPool::required($this->display))); + } + if(!empty($this->value) && !empty($this->syntax) && !preg_match("/".$this->syntax."/", $this->value)){ + return(array(msgPool::invalid($this->display, $this->value, "/".$this->syntax."/"))); + } + return(array()); + } +} +?> diff --git a/gosa-plugins/goto/admin/ConfigManagement/class_TemplateWidget_checkbox.inc b/gosa-plugins/goto/admin/ConfigManagement/class_TemplateWidget_checkbox.inc new file mode 100644 index 000000000..cd6cb1b0f --- /dev/null +++ b/gosa-plugins/goto/admin/ConfigManagement/class_TemplateWidget_checkbox.inc @@ -0,0 +1,19 @@ +postName}' "; + if($this->value) $str .= " checked "; + $str .= ">"; + return($str); + } + + function save_object() + { + $this->value = isset($_POST[$this->postName]); + } +} +?> diff --git a/gosa-plugins/goto/admin/ConfigManagement/class_TemplateWidget_combobox.inc b/gosa-plugins/goto/admin/ConfigManagement/class_TemplateWidget_combobox.inc new file mode 100644 index 000000000..d0a306926 --- /dev/null +++ b/gosa-plugins/goto/admin/ConfigManagement/class_TemplateWidget_combobox.inc @@ -0,0 +1,22 @@ +postName}'>"; + foreach($this->values as $name => $value){ + if($name == $this->value){ + $str .= "\n"; + }else{ + $str .= "\n"; + } + } + $str .= ""; + return($str); + } +} +?> diff --git a/gosa-plugins/goto/admin/ConfigManagement/class_TemplateWidget_file.inc b/gosa-plugins/goto/admin/ConfigManagement/class_TemplateWidget_file.inc new file mode 100644 index 000000000..4c26fe32e --- /dev/null +++ b/gosa-plugins/goto/admin/ConfigManagement/class_TemplateWidget_file.inc @@ -0,0 +1,34 @@ +description); + if(mb_strlen($this->value) == 0){ + $ret = ""._("No file uploaded yet").""; + $ret.= "
+ postName}\" + name=\"{$this->postName}\" + type=\"file\" + size=\"20\" + maxlength=\"255\" + accept=\"*.*\"> "; + $ret.= ""; + }else{ + $ret = ""._("File uploaded").": ".mb_strlen($this->value)." "._("Bytes"); + $ret.= " "; + } + return($ret); + } + + function save_object() + { + if(isset($_POST["{$this->postName}_Upload"]) && isset($_FILES[$this->postName]['tmp_name'])){ + $this->value = file_get_contents($_FILES[$this->postName]['tmp_name']); + } + if(isset($_POST["{$this->postName}_Remove"])) $this->value =""; + } +} + +?> diff --git a/gosa-plugins/goto/admin/ConfigManagement/class_TemplateWidget_fixedList.inc b/gosa-plugins/goto/admin/ConfigManagement/class_TemplateWidget_fixedList.inc new file mode 100644 index 000000000..0f9809728 --- /dev/null +++ b/gosa-plugins/goto/admin/ConfigManagement/class_TemplateWidget_fixedList.inc @@ -0,0 +1,86 @@ +listWidget= new sortableListing($this->value); + $this->listWidget->setEditable(false); + $this->listWidget->setDeleteable(true); + $this->listWidget->setColspecs(array('*')); + $this->listWidget->setWidth("100%"); + $this->listWidget->setHeight("70px"); + $this->listWidget->setAcl("rwcdm"); + } + + function getAvailableOptions() + { + $tmp = array(); + foreach($this->values as $key => $name){ + if(!in_array($key, $this->value)){ + $tmp[$key]=$name; + } + } + return($tmp); + } + + function render() + { + $str = ""; + + // Build up list data + $data = $this->value; + foreach($this->value as $key => $name){ + $lData[$key] = array('data' => array($this->values[$name])); + } + $this->listWidget->setListData($data, $lData); + $this->listWidget->update(); + $str .= $this->listWidget->render(); + $str .= ""; + $str .= ""; + return($str); + } + + function save_object() + { + $this->listWidget->save_object(); + $action = $this->listWidget->getAction(); + if($action['action'] == 'delete'){ + $id = $this->listWidget->getKey($action['targets'][0]); + unset($this->value[$id]); + $this->value = array_values($this->value); + } + + if(isset($_POST["{$this->postName}_Add"]) && isset($_POST["{$this->postName}_Input"])){ + $input = get_post("{$this->postName}_Input"); + + if(!empty($input) && !empty($this->syntax) && !preg_match("/".$this->syntax."/", $input)){ + msg_dialog::displayChecks(array(msgPool::invalid($this->display, $input, "/".$this->syntax."/"))); + }elseif(!empty($input)){ + $this->value[] = $input; + } + } + } + + /*! \brief Check the value entry using the provieded syntax. + * @return Array Returns a list of errors + */ + function check() + { + if($this->required && empty($this->value)){ + return(array(msgPool::required($this->display))); + } + return(array()); + } +} + + +?> diff --git a/gosa-plugins/goto/admin/ConfigManagement/class_TemplateWidget_list.inc b/gosa-plugins/goto/admin/ConfigManagement/class_TemplateWidget_list.inc new file mode 100644 index 000000000..d95da2c57 --- /dev/null +++ b/gosa-plugins/goto/admin/ConfigManagement/class_TemplateWidget_list.inc @@ -0,0 +1,64 @@ +listWidget= new sortableListing($this->value); + $this->listWidget->setEditable(false); + $this->listWidget->setDeleteable(true); + $this->listWidget->setColspecs(array('*')); + $this->listWidget->setWidth("100%"); + $this->listWidget->setHeight("70px"); + $this->listWidget->setAcl("rwcdm"); + } + + + function render() + { + $str = ""; + $this->listWidget->setListData($this->value); + $this->listWidget->update(); + $str .= $this->listWidget->render(); + $str .= ""; + $str .= ""; + return($str); + } + + function save_object() + { + $this->listWidget->save_object(); + $action = $this->listWidget->getAction(); + if($action['action'] == 'delete'){ + $id = $this->listWidget->getKey($action['targets'][0]); + unset($this->value[$id]); + $this->value = array_values($this->value); + } + + if(isset($_POST["{$this->postName}_Add"]) && isset($_POST["{$this->postName}_Input"])){ + $input = get_post("{$this->postName}_Input"); + + if(!empty($input) && !empty($this->syntax) && !preg_match("/".$this->syntax."/", $input)){ + msg_dialog::displayChecks(array(msgPool::invalid($this->display, $input, "/".$this->syntax."/"))); + }elseif(!empty($input)){ + $this->value[] = $input; + } + } + } + + /*! \brief Check the value entry using the provieded syntax. + * @return Array Returns a list of errors + */ + function check() + { + if($this->required && empty($this->value)){ + return(array(msgPool::required($this->display))); + } + return(array()); + } +} + + +?> diff --git a/gosa-plugins/goto/admin/ConfigManagement/class_TemplateWidget_string.inc b/gosa-plugins/goto/admin/ConfigManagement/class_TemplateWidget_string.inc new file mode 100644 index 000000000..2bf3ccca0 --- /dev/null +++ b/gosa-plugins/goto/admin/ConfigManagement/class_TemplateWidget_string.inc @@ -0,0 +1,18 @@ +description); + $value = set_post($this->value); + + $name = " name=\"{$this->postName}\" "; + $value = " value=\"{$value}\" "; + $title = (empty($this->description))?"": " title=\"{$desc}\""; + + return(""); + } +} + +?> diff --git a/gosa-plugins/goto/admin/ConfigManagement/class_TemplateWidget_textEditor.inc b/gosa-plugins/goto/admin/ConfigManagement/class_TemplateWidget_textEditor.inc new file mode 100644 index 000000000..93b7951c1 --- /dev/null +++ b/gosa-plugins/goto/admin/ConfigManagement/class_TemplateWidget_textEditor.inc @@ -0,0 +1,75 @@ +mb_extension = function_exists("mb_detect_encoding"); + if($this->mb_extension){ + $this->enc_before_edit = mb_detect_encoding($this->value); + if($this->enc_before_edit != "ASCII"){ + $this->write_protect = TRUE; + } + } + } + + + function render() + { + $smarty = get_smarty(); + $smarty->assign("postName", set_post($this->postName)); + $smarty->assign("write_protect", set_post($this->write_protect)); + $smarty->assign("value", set_post($this->value)); + return($smarty->fetch(get_template_path("TemplateWidget_textEditor.tpl", TRUE, dirname(__FILE__)))); + } + + + function save_object() + { + TemplateWidget::save_object(); + if(isset($_POST['editAnyway'])) $this->write_protect = FALSE; + + if(isset($_POST['ImportUpload'])){ + if(($_FILES['ImportFile']['error']!=0)){ + msg_dialog::display(_("Error"), msgPool::incorrectUpload(), ERROR_DIALOG); + }elseif(($_FILES['ImportFile']['size']==0)){ + msg_dialog::display(_("Error"), msgPool::incorrectUpload(_("file is empty")), ERROR_DIALOG); + }else{ + $str = file_get_contents($_FILES['ImportFile']['tmp_name']); + $this->value = $str; + + // Check encoding again + if($this->mb_extension){ + $this->enc_before_edit = mb_detect_encoding($this->value); + if($this->enc_before_edit != "ASCII"){ + $this->write_protect = TRUE; + } + } + } + } + $this->enc_after_edit = mb_detect_encoding($this->value); + } + + + /*! \brief Check the value entry using the provieded syntax. + * @return Array Returns a list of errors + */ + function check() + { + $msgs = TemplateWidget::check(); + if($this->mb_extension && !$this->write_protect && $this->enc_after_edit !== $this->enc_before_edit ){ + $msg = sprintf(_("The text encodig has changed from '%s' to '%s'. Do you really want to save?"), + "".$this->enc_before_edit."","".$this->enc_after_edit.""); + $msgs[] = $msg; + $this->enc_before_edit = $this->enc_after_edit; + } + return($msgs); + } +} +?> diff --git a/gosa-plugins/goto/admin/ConfigManagement/class_TemplateWidget_textarea.inc b/gosa-plugins/goto/admin/ConfigManagement/class_TemplateWidget_textarea.inc new file mode 100644 index 000000000..030dd1156 --- /dev/null +++ b/gosa-plugins/goto/admin/ConfigManagement/class_TemplateWidget_textarea.inc @@ -0,0 +1,16 @@ +description); + return(""); + } + +} + +?> diff --git a/gosa-plugins/goto/admin/ConfigManagement/class_filterDeviceItems.inc b/gosa-plugins/goto/admin/ConfigManagement/class_filterDeviceItems.inc new file mode 100644 index 000000000..d6dd7c912 --- /dev/null +++ b/gosa-plugins/goto/admin/ConfigManagement/class_filterDeviceItems.inc @@ -0,0 +1,57 @@ + $item){ + if($item['base'] == $base){ + $data = $item['children']; + break;; + } + } + + // Prepare filter, strip out regex regex related chars, except for * + $filter = preg_replace('/\*/','____STAR____', $filter); + $filter = preg_quote($filter,'/'); + $filter = preg_replace('/____STAR____/','.*', $filter); + + // Add entries + $ret = array(); + foreach($data as $item){ + filterDeviceItems::addEntry($ret, $item, $scope == 'sub', $filter); + } + return($ret); + } + + static function addEntry(&$ret, $item, $recursive = FALSE, $filter) + { + if(preg_match("/".$filter."/",$item['name'])){ + $entry = array(); + $entry['dn'] = $item['id']; + $entry[] = 'dn'; + $entry['cn'] = array($item['name'], 'count' => 1); + $entry[] = 'cn'; + $entry['id'] = array($item['id'], 'count' => 1); + $entry[] = 'id'; + $entry['description'] = array($item['type'], 'count' => 1); + $entry[] = 'description'; + $entry['objectClass'] = array($item['type'],'count' => 1); + $entry[] = 'objectClass'; + $entry['count'] = 5; + $ret[] = $entry; + } + + if($recursive && isset($item['children']) && count($item['children'])){ + foreach($item['children'] as $item){ + filterDeviceItems::addEntry($ret, $item, $recursive,$filter); + } + } + + } +} + +?> diff --git a/gosa-plugins/goto/admin/ConfigManagement/failed.tpl b/gosa-plugins/goto/admin/ConfigManagement/failed.tpl new file mode 100644 index 000000000..6a65bc398 --- /dev/null +++ b/gosa-plugins/goto/admin/ConfigManagement/failed.tpl @@ -0,0 +1,12 @@ +{if $rpcError} +

{t}Error{/t}

+ {msgPool type=rpcError p1=$error} + +{elseif $initFailed} +

{t}Communication failed{/t}

+ {msgPool type=rpcError p1=$error} + +{elseif $invalidInstallMethod} +

{t}Configuration error {/t}

+ {msgPool type=rpcError p1=$error} +{/if} diff --git a/gosa-plugins/goto/admin/ConfigManagement/puppet.tpl b/gosa-plugins/goto/admin/ConfigManagement/puppet.tpl new file mode 100644 index 000000000..8b8d95b56 --- /dev/null +++ b/gosa-plugins/goto/admin/ConfigManagement/puppet.tpl @@ -0,0 +1,39 @@ +{if $type == 'PuppetModule'} + + + + + +
+ + + + + + + + + + + + + +
{$nameName}{$name}
{$descriptionName}{$description}
{$versionName}{$version}
+
+ {$dependencyName}:
+ {$dependency} +
+{/if} +{if $type == 'PuppetTemplate'} + + + + + + + + + +
{$nameName}{$name}
{$dataName}{$data}
+ +{/if}