From: hickert Date: Mon, 16 Apr 2007 12:42:08 +0000 (+0000) Subject: Addon for #25 Plugin for mass-deployment of machines X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=e4cdaf002777f409d27a343308afce70be30b974;p=gosa.git Addon for #25 Plugin for mass-deployment of machines git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@6055 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/contrib/gosa.conf b/contrib/gosa.conf index 791db7d47..4b93ae49e 100644 --- a/contrib/gosa.conf +++ b/contrib/gosa.conf @@ -75,6 +75,10 @@ path="plugins/addons/ldapmanager" /> + diff --git a/plugins/addons/gotomasses/class_gotomasses.inc b/plugins/addons/gotomasses/class_gotomasses.inc new file mode 100644 index 000000000..108022afb --- /dev/null +++ b/plugins/addons/gotomasses/class_gotomasses.inc @@ -0,0 +1,218 @@ +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 new file mode 100644 index 000000000..ac756ee78 --- /dev/null +++ b/plugins/addons/gotomasses/contents.tpl @@ -0,0 +1,77 @@ +
+

[F] + {t}Options{/t}  +

+
+
+ + + + + +
+ + + + +
+
+ + + + + + + + {foreach from=$contents item=val key=key} + + + + + + + + + {/foreach} + + + + + + +
+ {t}No.{/t} + + {t}Mac address{/t} + + {t}Object group{/t} + + {t}Options{/t} +
+ {$key+1} + + + + + + +
+  - + +  - + +  - + + +
+

 

+
+

+ + +

+
+ diff --git a/plugins/addons/gotomasses/main.inc b/plugins/addons/gotomasses/main.inc new file mode 100644 index 000000000..89dea8fb8 --- /dev/null +++ b/plugins/addons/gotomasses/main.inc @@ -0,0 +1,40 @@ +set_acl_category("gotomasses"); + } + $gotomasses= $_SESSION['gotomasses']; + + /* Execute formular */ + $display= $gotomasses->save_object(); + $display= $gotomasses->execute (); + $display.= "\n"; + + /* Page header*/ + $display= print_header(get_template_path('images/system.png'), _("Mass machine deployment")).$display; + + /* Store changes in session */ + $_SESSION['gotomasses']= $gotomasses; +}