summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d8c417e)
raw | patch | inline | side by side (parent: d8c417e)
author | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Mon, 16 Apr 2007 12:42:08 +0000 (12:42 +0000) | ||
committer | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Mon, 16 Apr 2007 12:42:08 +0000 (12:42 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@6055 594d385d-05f5-0310-b6e9-bd551577e9d8
contrib/gosa.conf | patch | blob | history | |
plugins/addons/gotomasses/class_gotomasses.inc | [new file with mode: 0644] | patch | blob |
plugins/addons/gotomasses/contents.tpl | [new file with mode: 0644] | patch | blob |
plugins/addons/gotomasses/main.inc | [new file with mode: 0644] | patch | blob |
diff --git a/contrib/gosa.conf b/contrib/gosa.conf
index 791db7d47cd670c5428cad3c9cd1f64562c2d3cd..4b93ae49e48906873b3d53abd03a06ed645fbfcf 100644 (file)
--- a/contrib/gosa.conf
+++ b/contrib/gosa.conf
path="plugins/addons/ldapmanager" />
<plugin acl="notifications" class="msgplug" icon="notifications.png"
path="plugins/addons/notifications" />
+<!--
+ <plugin acl="gotomasses" class="gotomasses" icon="system.png"
+ path="plugins/addons/gotomasses" />
+-->
</section>
</menu>
diff --git a/plugins/addons/gotomasses/class_gotomasses.inc b/plugins/addons/gotomasses/class_gotomasses.inc
--- /dev/null
@@ -0,0 +1,218 @@
+<?php
+
+class gotomasses extends plugin
+{
+ /* Definitions */
+ var $plHeadline = "Mass machine";
+ var $plDescription = "This does something";
+
+ /* attribute list for save action */
+ var $attributes= array();
+ var $objectclasses= array();
+
+ /* Source file that contains the csv data */
+ var $file_to_read = "Undefined"; #Set in constructor
+
+ /* Parsed csv content */
+ var $contents = array();
+
+
+ function gotomasses($config, $dn= NULL)
+ {
+ /* Define source file */
+ $this->file_to_read = CONFIG_DIR."/gotomasses_machines";
+
+ /* Include config object */
+ $this->config= $config;
+
+ $this->load_csv_data();
+ }
+
+
+ function get_object_groups()
+ {
+ $ret = array();
+ $ldap = $this->config->get_ldap_link();
+ $ldap->cd($this->config->current['BASE']);
+ $ldap->search("(&(objectClass=gosaGroupOfNames)(cn=*))",array("cn"));
+ while($attrs = $ldap->fetch()){
+ $ret [$attrs['cn'][0]] = $attrs['cn'][0];
+ }
+ return($ret);
+ }
+
+
+ function execute()
+ {
+ if(isset($_POST['export_gotomass_csv'])){
+ $data = "";
+ foreach($this->contents as $val){
+ $data .= $val['MAC'].", ".$val['OG']."\n";
+ }
+ header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
+ header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
+ header("Cache-Control: no-cache");
+ header("Pragma: no-cache");
+ header("Cache-Control: post-check=0, pre-check=0");
+ header("Content-type: text/plain");
+ if (preg_match('/MSIE 5.5/', $_SERVER['HTTP_USER_AGENT']) ||
+ preg_match('/MSIE 6.0/', $_SERVER['HTTP_USER_AGENT'])){
+ header('Content-Disposition: filename="gotomass.csv"');
+ } else {
+ header('Content-Disposition: attachment; filename="gotomass.csv";');
+ }
+ echo $data;
+ exit();
+ }
+
+ /* Import given file */
+ if(isset($_POST['import_gotomass_csv']) && isset($_FILES['mass_file'])){
+ $str = @file_get_contents($_FILES['mass_file']['tmp_name']);
+ if(empty($str)){
+ print_red(_("Uploaded file seams to be empty, import aborted."));
+ }else{
+ $this->load_csv_data($str);
+ }
+ }
+
+ if(isset($_POST['add_new_entry'])){
+ $this->contents[] = array("MAC" => "", "OG" => "");
+ }
+
+
+ /* Call parent execute */
+ plugin::execute();
+ $smarty= get_smarty();
+ $smarty->assign("ogs", $this->get_object_groups());
+ $smarty->assign("contents", $this->contents);
+ $smarty->assign("launchimage","images/launch.png");
+ return ($smarty->fetch (get_template_path('contents.tpl', TRUE)));
+ }
+
+
+ function load_csv_data($data = NULL)
+ {
+
+ if($data == NULL){
+ if(!file_exists($this->file_to_read) || !is_readable($this->file_to_read)){
+ print_red(sprintf(_("Can't locate or read goto masses csv storage file '%s'."),$this->file_to_read));
+ return(FALSE);
+ }
+
+ $fp = @fopen($this->file_to_read,"r");
+ if(!$fp){
+ print_red(sprintf(_("Can't read goto masses csv storage file '%s'."),$this->file_to_read));
+ return(FALSE);
+ }
+
+ $this->contents =array();
+
+ while(!feof($fp)){
+ $str = trim(fgets($fp,512));
+
+ /* Get mac address */
+ $og = trim(preg_replace("/^[^,;]*(,|;)/","",$str));
+ $mac = preg_replace("/(,|;).*$/","",$str);
+
+ if(!empty($og) || !empty($mac)){
+ $this->contents[] = array("MAC" => $mac , "OG" => $og);
+ }
+ }
+ fclose($fp);
+ }else{
+ $this->contents =array();
+ $rows = split("\n",$data);
+ foreach($rows as $str){
+
+ /* Get mac address */
+ $og = trim(preg_replace("/^[^,;]*(,|;)/","",$str));
+ $mac = preg_replace("/(,|;).*$/","",$str);
+
+ if(!empty($og) || !empty($mac)){
+ $this->contents[] = array("MAC" => $mac , "OG" => $og);
+ }
+ }
+ }
+ }
+
+
+ function save_csv_data()
+ {
+ if(!file_exists($this->file_to_read) || !is_writeable($this->file_to_read)){
+ print_red(sprintf(_("Can't locate or write goto masses csv storage file '%s'."),$this->file_to_read));
+ }else{
+
+ $fp = @fopen($this->file_to_read,"w");
+
+ if(!$fp){
+ print_red(sprintf(_("Can't write goto masses csv storage file '%s'."),$this->file_to_read));
+ }else{
+ $data = "";
+ foreach($this->contents as $val){
+ $data .= $val['MAC'].", ".$val['OG']."\n";
+ }
+ fwrite($fp,$data,strlen($data));
+ fclose($fp);
+ }
+ }
+ }
+
+
+ function save_object()
+ {
+ if(isset($_POST['gotomasses'])){
+
+ /* Check for input changes */
+ $ogs = $this->get_object_groups();
+ foreach($this->contents as $id => $data){
+ if(isset($_POST['mac_'.$id])){
+ $this->contents[$id]['MAC'] = $_POST['mac_'.$id];
+ }
+ if(isset($_POST['og_'.$id]) && in_array_ics($_POST['og_'.$id],$ogs)){
+ $this->contents[$id]['OG'] = $_POST['og_'.$id];
+ }
+ }
+
+ /* check for remove requests */
+ $once = TRUE;
+ foreach($_POST as $name => $value){
+ if(preg_match("/^remove_[0-9]*_(x|y)$/",$name) && $once){
+ $once = FALSE;
+ $id = preg_replace("/^remove_/","",$name);
+ $id = preg_replace("/_(x|y)$/","",$id);
+
+ if(isset($this->contents[$id])){
+ unset($this->contents[$id]);
+ }
+ }
+ }
+
+ /* Write back all changes */
+ if(isset($_POST['save_gotomass_changes'])){
+ $this->save_csv_data();
+ }
+
+ /* Reload data from csv file ? */
+ if(isset($_POST['reload_gotomass_data'])){
+ $this->load_csv_data();
+ }
+ }
+ }
+
+
+ function plInfo()
+ {
+ return (array(
+ "plShortName" => _("Mass machine deployment"),
+ "plDescription" => _("Mass machine deployment addon"),
+ "plSelfModify" => FALSE,
+ "plDepends" => array(),
+ "plPriority" => 0,
+ "plSection" => array("addon"),
+ "plCategory" => array("mass_machines" => array("objectClass" => "none", "description" => _("Mass machine deployment"))),
+ "plProvidedAcls" => array()
+ ));
+ }
+}
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
diff --git a/plugins/addons/gotomasses/contents.tpl b/plugins/addons/gotomasses/contents.tpl
--- /dev/null
@@ -0,0 +1,77 @@
+<div class="contentboxh">
+ <p class="contentboxh"><img src="{$launchimage}" align="right" alt="[F]">
+ {t}Options{/t}
+ </p>
+</div>
+<div class="contentboxb">
+
+ <table summary="" width="100%" class="contentboxb" style="border-top:1px solid #B0B0B0; padding:0px;">
+ <tr>
+ <td>
+ <input type='submit' name='export_gotomass_csv' value='{t}Export{/t}'>
+ <input type='file' name='mass_file'>
+
+ <input type='submit' name='import_gotomass_csv' value='{t}Import{/t}'>
+ </td>
+ </tr>
+ </table>
+</div>
+ <table summary="" width="100%" class="contentboxb">
+ <tr>
+ <td>
+ <b>{t}No.{/t}</b>
+ </td>
+ <td>
+ <b>{t}Mac address{/t}</b>
+ </td>
+ <td>
+ <b>{t}Object group{/t}</b>
+ </td>
+ <td style='text-align:right'>
+ <b>{t}Options{/t}</b>
+ </td>
+ </tr>
+ {foreach from=$contents item=val key=key}
+
+ <tr>
+ <td>
+ {$key+1}
+ </td>
+ <td>
+ <input name='mac_{$key}' type='text' value='{$contents.$key.MAC}'>
+ </td>
+ <td>
+ <select name='og_{$key}' title='{t}Select object group{/t}'>
+ {html_options options=$ogs selected=$contents.$key.OG}
+ </select>
+ </td>
+ <td style='text-align:right'>
+ <input type='image' name='remove_{$key}' src='images/edittrash.png'
+ title='{t}Remove this entry{/t}'>
+ </td>
+ </tr>
+
+ {/foreach}
+ <tr>
+ <td>
+ -
+ </td>
+ <td>
+ -
+ </td>
+ <td>
+ -
+ </td>
+ <td style='text-align:right'>
+ <input type='submit' name='add_new_entry' value='{t}New entry{/t}'>
+ </td>
+ </tr>
+ </table>
+<p> </p>
+<div class="contentboxb" style="border-top: 1px solid #B0B0B0; padding:0px;">
+ <p class="contentboxb" style='text-align:right'>
+ <input type='submit' name='reload_gotomass_data' value='{t}Discard changes{/t}'>
+ <input type='submit' name='save_gotomass_changes' value='{t}Apply changes{/t}'>
+ </p>
+</div>
+<input type='hidden' name='gotomasses' value='1'>
diff --git a/plugins/addons/gotomasses/main.inc b/plugins/addons/gotomasses/main.inc
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+/*
+ This code is part of GOsa (https://gosa.gonicus.de)
+ Copyright (C) 2003 Cajus Pollmeier
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+if (!$remove_lock){
+
+ /* Create gotomasses object on demand */
+ if (!isset($_SESSION['gotomasses']) || (isset($_GET['reset']) && $_GET['reset'] == 1)){
+ $_SESSION['gotomasses']= new gotomasses ($config);
+ $_SESSION['gotomasses']->set_acl_category("gotomasses");
+ }
+ $gotomasses= $_SESSION['gotomasses'];
+
+ /* Execute formular */
+ $display= $gotomasses->save_object();
+ $display= $gotomasses->execute ();
+ $display.= "<input type=\"hidden\" name=\"ignore\">\n";
+
+ /* Page header*/
+ $display= print_header(get_template_path('images/system.png'), _("Mass machine deployment")).$display;
+
+ /* Store changes in session */
+ $_SESSION['gotomasses']= $gotomasses;
+}