From 632ddd217c167e49dcbb48a19055e822cebf0223 Mon Sep 17 00:00:00 2001 From: opensides Date: Thu, 27 Mar 2008 21:33:13 +0000 Subject: [PATCH] - Cleanead up for first beta git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5-plugins@10038 594d385d-05f5-0310-b6e9-bd551577e9d8 --- sudo-ldap/addons/sudo/class_sudoldap.inc | 183 ++++++++++++++++++ .../addons/sudo/class_sudoldapEditRole.inc | 108 +++++++++++ sudo-ldap/addons/sudo/main.inc | 111 +++++++++++ sudo-ldap/addons/sudo/sudoldap.tpl | 17 ++ sudo-ldap/addons/sudo/sudoldapeditrole.tpl | 42 ++++ sudo-ldap/gen_locale.sh | 169 ++++++++++++++++ sudo-ldap/plugin.dsc | 5 + 7 files changed, 635 insertions(+) create mode 100644 sudo-ldap/addons/sudo/class_sudoldap.inc create mode 100644 sudo-ldap/addons/sudo/class_sudoldapEditRole.inc create mode 100644 sudo-ldap/addons/sudo/main.inc create mode 100644 sudo-ldap/addons/sudo/sudoldap.tpl create mode 100644 sudo-ldap/addons/sudo/sudoldapeditrole.tpl create mode 100755 sudo-ldap/gen_locale.sh create mode 100644 sudo-ldap/plugin.dsc diff --git a/sudo-ldap/addons/sudo/class_sudoldap.inc b/sudo-ldap/addons/sudo/class_sudoldap.inc new file mode 100644 index 000000000..7090d93a8 --- /dev/null +++ b/sudo-ldap/addons/sudo/class_sudoldap.inc @@ -0,0 +1,183 @@ + + \version 1.00 + \date 22.03.2008 + + This class provides the functionality to read and write all attributes + relevant for sudo-ldap from/to the LDAP. + */ + +class sudoldap extends plugin +{ + /* Definitions */ + var $plHeadline = "sudo-ldap"; + var $plDescription = "This does something"; + + /* Plugin specific values */ + var $attributes = array( "cn", + "description", + "sudoUser", + "sudoHost", + "sudoCommand", + "sudoRunAs", + "sudoOption"); + + var $objectclasses = array("sudoRole"); + var $Roles = array(); + var $dialog = NULL; + + /* constructor, if 'dn' is set, the node loads the given + 'dn' from LDAP */ + function sudoldap ($config, $dn= NULL, $parent= NULL){ + /* Configuration is fine, allways */ + $this->config= $config; + /* Load bases attributes */ + plugin::plugin($config, $dn, $parent); + $ldap= $this->config->get_ldap_link(); + } // function + + /* execute generates the html output for this node */ + function execute($isCopyPaste = false){ + /* Call parent execute */ + plugin::execute(); + $display= ""; + $smarty= get_smarty(); + $this->Roles = $this->getRoles(); + + /* Edited or Added zone + */ + if((isset($_POST['SaveRoleChanges'])) && is_object($this->dialog)){ + $this->dialog->save_object(); + + /* Check for errors + */ + if(count($this->dialog->check())){ + foreach($this->dialog->check() as $msgs){ + print_red($msgs); + } + }else{ + /* add new/edited zone + */ + $ret = $this->dialog->save(); + //if(!$this->dialog->isNew){ + // unset($this->Roles[$this->dialog->OldRoleName]); + //} + $this->Roles[$ret['cn']] = $ret; + $this->dialog = NULL; + } + } + + /* Cancel zone edit / new + */ + if(isset($_POST['CancelRoleChanges'])){ + $this->dialog = NULL; + } + + /* Add empty new zone + */ + //if(isset($_POST['AddRole']) && chkacl($this->acl,"sudoldap") == ""){ + if(isset($_POST['AddRole'])){ + $this->dialog = new sudoldapEditRole($this->config); + } + + /* Check for edit role request + */ + $once = false; + foreach( $_POST as $name => $value){ + + /* check all post for edit request + */ + + //if(preg_match("/^editRole_/",$name)&&!$once + // && chkacl($this->acl,"sudoldap") == ""){ + if(preg_match("/^editRole_/",$name)&&!$once){ + $once =true; + $tmp = preg_replace("/^editRole_/","",$name); + $tmp = base64_decode(preg_replace("/_.*$/","",$tmp)); + $this->dialog= new sudoldapeditRole($this->config, + $this->dn, + $this->Roles[$tmp]); + } // if () + + /* check posts for delete zone + */ + + //if(preg_match("/^delRole_/",$name)&&!$once + // && chkacl($this->acl,"sudoldap") == ""){ + if(preg_match("/^delRole_/",$name)&&!$once){ + $once =true; + $tmp = preg_replace("/^delRole_/","",$name); + $tmp = base64_decode(preg_replace("/_.*$/","",$tmp)); + + /* Initiate deletion + */ + + $this->RemoveRole($tmp); + } // if () + + } // foreach() + + /* Show dialog + */ + if($this->dialog!= NULL){ + $this->dialog->save_object(); + $this->dialog->parent = $this; + return($this->dialog->execute()); + } + + $RoleList = new divSelectBox("sudoRoles"); + $RoleList->SetHeight(300); + $editImg = " + "; + + foreach($this->Roles as $role => $values ){ + $link = "%s"; + $RoleList->AddEntry( + array( + array("string" => sprintf($link,base64_encode($role),$role)), + array("string" => str_replace("%s",base64_encode($role),$editImg)) + ) + ); + } // foreach() + + $smarty->assign("sudoldapACL",chkacl($this->acl,"sudoldap")); + $smarty->assign("RoleList",$RoleList->DrawList()); + + $display.= $smarty->fetch(get_template_path('sudoldap.tpl', TRUE)); + + return($display); + } // function + + function getRoles(){ + $ret = array(); + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ldap->search("(objectClass=sudoRole)",$this->attributes); + while ($attrs= $ldap->fetch()){ + $cn= $attrs['cn'][0]; + foreach($this->attributes as $value){ + if(isset($attrs[$value])){ + $ret[$cn][$value] = $attrs[$value][0]; + } // if() + } // foreach() + } // while() + return($ret); + } + + function RemoveRole($cn){ + if($cn!=""){ + $ldap= $this->config->get_ldap_link(); + $dn = "cn=".$cn.",ou=SUDOers,".$this->config->current['BASE']; + $ldap->cd($dn); + $ldap->rmdir_recursive($dn); + show_ldap_error($ldap->get_error(), _("Removing DNS entries failed")); + unset($this->Roles[$cn]); + } // if() + } // function + +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/sudo-ldap/addons/sudo/class_sudoldapEditRole.inc b/sudo-ldap/addons/sudo/class_sudoldapEditRole.inc new file mode 100644 index 000000000..64f0761a8 --- /dev/null +++ b/sudo-ldap/addons/sudo/class_sudoldapEditRole.inc @@ -0,0 +1,108 @@ +isNew = true; + }else{ + $this->isNew = false; + foreach($this->attributes as $value){ + if(isset($attrs[$value])){ + $this->$value = $attrs[$value]; + } + } + } + } + + function execute() + { + /* Call parent execute */ + plugin::execute(); + + + /* Fill templating stuff */ + $smarty= get_smarty(); + $display= ""; + + $smarty->assign("cn", $this->cn); + $smarty->assign("description", $this->description); + $smarty->assign("sudoUser", $this->sudoUser); + $smarty->assign("sudoHost", $this->sudoHost); + $smarty->assign("sudoCommand", $this->sudoCommand); + $smarty->assign("sudoRunAs", $this->sudoRunAs); + $smarty->assign("sudoOption", $this->sudoOption); + + /* Display template */ + $display.= $smarty->fetch( + get_template_path('sudoldapeditrole.tpl', TRUE)); + return($display); + } + + /* Save data to object */ + function save_object() + { + //plugin::save_object(); + foreach($this->attributes as $attr){ + if(isset($_POST[$attr])){ + $this->$attr = $_POST[$attr]; + } + } + } + + + /* Check supplied data */ + function check() + { + } + + + /* Save to LDAP */ + function save() + { + plugin::save(); + $ldap= $this->config->get_ldap_link(); + + $this->dn = "cn=".$this->cn.",ou=SUDOers,".$this->config->current['BASE']; + $this->attrs['objectClass'] = array("sudoRole"); + + $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn)); + $ldap->cd($this->dn); + $ldap->add($this->attrs); + + /* Display errors + */ + if($ldap->get_error() != "Success"){ + show_ldap_error("Record:".$ldap->get_error(), _("Saving failed!")); + } + } + + +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/sudo-ldap/addons/sudo/main.inc b/sudo-ldap/addons/sudo/main.inc new file mode 100644 index 000000000..1d57e66ed --- /dev/null +++ b/sudo-ldap/addons/sudo/main.inc @@ -0,0 +1,111 @@ + + + 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 + */ + +/* Clear display */ +$display= ""; + +if (!$remove_lock){ + + /* Reset requested? */ + if (isset($_POST['edit_cancel']) || + (isset($_GET['reset']) && $_GET['reset'] == 1)){ + + del_lock ($ui->dn); + sess_del ('edit'); + sess_del ('sudoldap'); + } + + /* Create sudoldap object on demand */ + if (!isset($_SESSION['sudoldap']) || (isset($_GET['reset']) && $_GET['reset'] == 1)){ + $_SESSION['sudoldap']= new sudoldap ($config, $ui->dn); + } + $sudoldap= $_SESSION['sudoldap']; + + /* save changes back to object */ + if (isset ($_SESSION['edit'])){ + $sudoldap->save_object (); + } + + /* Enter edit mode? */ + if ((isset($_POST['edit'])) && (!isset( $_SESSION['edit']))){ + + /* Check locking */ + if (($username= get_lock($ui->dn)) != ""){ + $_SESSION['back_plugin']= $plug; + gen_locked_message ($username, $ui->dn); + exit (); + } + + /* Lock the current entry */ + add_lock ($ui->dn, $ui->dn); + $_SESSION['dn']= $ui->dn; + $_SESSION['edit']= TRUE; + } + + /* Adjust acl's to mode */ + if (isset($_SESSION['edit'])){ + $acl= get_permissions ($ui->dn, $ui->subtreeACL); + $sudoldap->acl= get_module_permission($acl, "sudoldap", $ui->dn); + } else { + $acl= get_permissions ($ui->dn, $ui->subtreeACL); + $editacl= get_module_permission($acl, "sudoldap", $ui->dn); + $sudoldap->acl= "#none#"; + } + + /* save changes to LDAP and disable edit mode */ + $info= ""; + if (isset($_POST['edit_finish'])){ + + /* Perform checks */ + $message= $sudoldap->check (); + + /* No errors, save object */ + if (count ($message) == 0){ + $sudoldap->save (); + gosa_log ("SUDO/ldap object'".$ui->dn."' has been saved"); + $sudoldap->acl= "#none#"; + $editacl= get_module_permission($acl, "sudoldap", $ui->dn); + del_lock ($ui->dn); + sess_del ('edit'); + + /* Remove from session */ + sess_del ('sudoldap'); + } else { + /* Errors found, show message */ + show_errors ($message); + } + } + + /* Execute formular */ + $display.= $sudoldap->execute (); + + /* Store changes in session */ + if (isset ($_SESSION['edit'])){ + $_SESSION['sudoldap']= $sudoldap; + } + + /* Page header*/ + $display= print_header(get_template_path('images/posix.png'), + _("sudo-ldap"), $info).$display; + +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/sudo-ldap/addons/sudo/sudoldap.tpl b/sudo-ldap/addons/sudo/sudoldap.tpl new file mode 100644 index 000000000..0f609735a --- /dev/null +++ b/sudo-ldap/addons/sudo/sudoldap.tpl @@ -0,0 +1,17 @@ + + + + +
+

{t}Sudo Roles{/t}

+ {$RoleList} + + +
+ diff --git a/sudo-ldap/addons/sudo/sudoldapeditrole.tpl b/sudo-ldap/addons/sudo/sudoldapeditrole.tpl new file mode 100644 index 000000000..d4f42c61a --- /dev/null +++ b/sudo-ldap/addons/sudo/sudoldapeditrole.tpl @@ -0,0 +1,42 @@ +

{t}sudo-ldap role{/t}

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{t}cn{/t}{$must}
{t}description{/t}{$must}
{t}sudoUser{/t}{$must}
{t}sudoHost{/t}{$must}
{t}sudoCommand{/t}{$must}
{t}sudoRunAs{/t}{$must}
{t}sudoOption{/t}{$must}
+
+

+ + +

+
+ diff --git a/sudo-ldap/gen_locale.sh b/sudo-ldap/gen_locale.sh new file mode 100755 index 000000000..4960be833 --- /dev/null +++ b/sudo-ldap/gen_locale.sh @@ -0,0 +1,169 @@ +#!/bin/sh + +generate_po() { + ORIG=`pwd` + TEMPDIR="/tmp/gosa-locale" + TRUE=`which true` + + echo + echo "Creating temporary directory..." + [ -d $TEMPDIR ] && rm -rf $TEMPDIR + mkdir $TEMPDIR + + echo "Creating copy of GOsa..." + tar c . | tar x -C $TEMPDIR + + echo "Converting .tpl files..." + pushd . &> /dev/null + cd $TEMPDIR + + for template in $(find . -name '*.tpl'); do + echo "* converting .tpl files: $(basename $template)" + sed -e 's/{t}/!g' $template > $template.new + mv $template.new $template + done + + for class in $(find . -name 'class_*.inc'); do + echo "* converting class_*.inc files: $(basename $class)" + sed -e 's/\($pl[DH][^=]*\)= *"\([^"]*\)";$/\1= _("\2");/g' $class > $class.new + mv $class.new $class + done + + echo "Extracting languages..." + rm locale/messages.po + find . -name '*.[ctpi][ophn][nlpc]' | xgettext -f - --keyword=must -d Domain -L PHP -n -o locale/messages.po + + echo "Merging po files with existing ones" + error=0 + for f in locale/??/LC_MESSAGES; do + echo -n "* merging $f/messages.po: " + [ -f $f/messages.po ] && msgmerge $f/messages.po locale/messages.po --output-file=$f/messages.po.new &> /dev/null + + # Do an extra check for dummy dir 'locale/en/LC_MESSAGES' + if [ $? -ne 0 ]; then + [ "$f" == "locale/en/LC_MESSAGES" ] && $TRUE + fi + + if [ $? -eq 0 ]; then + echo "done"; + else + echo "failed"; + error=1 + fi + + done + + echo "Copying new po files, making backups..." + find . -name messages.po | while read f; do + + if [ -f $ORIG/$f ]; then + mv $ORIG/$f $ORIG/$f.orig + else + continue + fi + + echo $f | grep -q "locale/messages.po" + if [ $? -ne 0 ]; then + echo "* replaced $ORIG/$f" + cp $f.new $ORIG/$f + else + cp $f $ORIG/$f + fi + + done + + rm -rf $TEMPDIR + + echo + error=0 + if [ $error -eq 0 ]; then + if [ $ASSUME_Y -eq 1 ]; then + find $ORIG/ -type f -name 'messages.po.orig' -exec rm -f {} \; + else + read -p "Do you want to erase the message.po.orig files? (y/n)" -n1 ans + + if [ "$ans" == "y" -o "$ans" == "Y" ]; then + find $ORIG/ -type f -name 'messages.po.orig' -exec rm -f {} \; + fi + fi + + else + echo "There were errors during the transition. Please fix!" + exit 1 + fi + +cat <<-EOF + +--------------------------------------------------------------------- + +Now edit all files that have been replaced above (i.e. using kbabel +or gtranslator) and mail the changes to gosa@oss.gonicus.de to be +included in the next release. + +To see the changes you've made in GOsa, run "msgfmt messages.po" on +your freshly edited files and restart your apache after that. Set +the webbrowser to the language you've edited and go back to the +login screen. + +--------------------------------------------------------------------- + +EOF + + popd &> /dev/null +} + +compile_po() +{ + po='messages.po' + mo='messages.mo' + + echo "Compiling po files..." + for f in locale/??/LC_MESSAGES; do + + if [ -f $f/$po ]; then + echo "* compiling $f/$po" + msgfmt $f/$po -o $f/$mo + else + echo "! skipped $f/$po - does not exist" + error=1 + continue + fi + + done +} + +# +# MAIN +# +GENERATE=0 +COMPILE=0 +ASSUME_Y=0 +while getopts ":cgyh" opt +do + case $opt in + c) COMPILE=1 + ;; + g) GENERATE=1; + ;; + y) ASSUME_Y=1; + ;; + h|--help) + echo "Usage: $(basename $0) [-c] [-g] [-y]" + echo " -c compile existing po files into mo files" + echo " -g extract strings from GOsa and generate po files" + echo " -y assume yes" + exit 1 + ;; + esac +done +shift $(($OPTIND - 1)) + +# Default to generate +if [ $GENERATE -eq 0 -a $COMPILE -eq 0 ]; then + GENERATE=1 +fi + +[ $GENERATE -eq 1 ] && generate_po +[ $COMPILE -eq 1 ] && compile_po + +# vim:tabstop=2:expandtab:shiftwidth=2:syntax:ruler: diff --git a/sudo-ldap/plugin.dsc b/sudo-ldap/plugin.dsc new file mode 100644 index 000000000..8d4f4842d --- /dev/null +++ b/sudo-ldap/plugin.dsc @@ -0,0 +1,5 @@ +[gosa-plugin] +name = sudo +description = "Sudo manager" +version = 2.5 +author = "Guido Serra " -- 2.30.2