Code

Added playground
authorcajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 2 Nov 2007 11:12:32 +0000 (11:12 +0000)
committercajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 2 Nov 2007 11:12:32 +0000 (11:12 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.6-playground@7713 594d385d-05f5-0310-b6e9-bd551577e9d8

13 files changed:
gosa.conf [new file with mode: 0644]
include/autoload-data.inc [new file with mode: 0644]
include/autoload.inc [new file with mode: 0644]
include/class_ConfigManager.inc [new file with mode: 0644]
include/class_LdapAttributeFactory.inc [new file with mode: 0644]
include/class_LdapManager.inc [new file with mode: 0644]
include/class_LdapObject.inc [new file with mode: 0644]
include/class_ObjectList.inc [new file with mode: 0644]
include/class_ObjectListIterator.inc [new file with mode: 0644]
include/class_ObjectListViewport.inc [new file with mode: 0644]
include/class_Registry.inc [new file with mode: 0644]
test [new file with mode: 0755]
update-gosa [new file with mode: 0755]

diff --git a/gosa.conf b/gosa.conf
new file mode 100644 (file)
index 0000000..c03ca2a
--- /dev/null
+++ b/gosa.conf
@@ -0,0 +1,119 @@
+; This is a gosa.conf sample configuration file. All values - except ldap* - can be
+; overloaded by an LDAP based configuration.
+
+;------------------------------------------------------------------------------
+
+; GONICUS GmbH configuration. Most features directly in the configuration.
+
+[gonicus]
+
+; Location configuration
+display-name = "GONICUS GmbH"
+language = "de"
+timezone = "Europe/Berlin"
+
+; Basic settings
+config = "ou=gosa,ou=configs,ou=systems,dc=gonicus,dc=de"
+compile-dir = "/var/spool/gosa"
+
+; Debugging/Reporting
+debug-level = DEBUG_LDAP
+visible-errors = true
+
+; Optimizing
+compressed-output = true
+
+; Session relevant settings
+session-lifetime = 4711
+session-restore = true
+
+; Display relevant settings
+list-summary = true
+theme = "default"
+
+; Checks if GOsa should take care about your security. ignore, warn, force are allowed values.
+ssl-mode = "ignore"
+
+; Snapshot objects
+enable-snapshots = true
+snapshot="ldap://ldap01.gonicus.de/dc=snapshots"
+snapshot-admin="cn=ldapadmin,dc=gonicus,dc=de"
+snapshot-password="secret"
+
+; LDAP definition
+ldap = "ldap://ldap01.gonicus.de/dc=gonicus,dc=de"
+ldap-admin = "cn=ldapadmin,dc=gonicus,dc=de"
+ldap-password = "secret"
+
+ldap2 = "ldap://ldap02.gonicus.de/dc=intranet,dc=gonicus,dc=de"
+ldap2-admin = "cn=ldapadmin,dc=intranet,dc=gonicus,dc=de"
+ldap2-password = "secret"
+ldap2-mode = "tls"
+
+;------------------------------------------------------------------------------
+
+; LHM configuration. Most features in LDAP.
+
+[lhm]
+display-name = "Landeshauptstadt München"
+ldap = "ldap://ldap01.muenchen.de/o=Landeshauptstadt München,c=de"
+ldap-admin = "cn=ldapadmin,c=de"
+ldap-password = "secret"
+
+;------------------------------------------------------------------------------
+
+; Global plugin pre-configuration
+
+[plugin/generic]
+id-gen = "/usr/local/bin/idgen"
+strict-ids = true
+dn-attribute = "cn"
+personal-title-in-dn = false
+base = "ou=people"
+
+[plugin/groups]
+rfc2307bis = false
+base = "ou=groups"
+
+[plugin/departments]
+honour-unit-tagging = false
+
+[plugin/unix]
+primary-group-filter = false
+check = "/usr/local/bin/check_unix.sh"
+postcreate = "/usr/local/bin/postcreate_unix.sh"
+uid-base = 1000
+gid-base = 1000
+min-id = 100
+;base-hook =
+
+[plugin/samba]
+enable = false
+samba-version = 3
+rid-base = 1000
+sid = 0815-4711
+hash-generator = "/usr/bin/mkntpasswd"
+id-mapping = true
+
+[plugin/mail]
+mail-method =
+cyrus-unix-style = true
+
+[plugin/password]
+use-sasl-for-kerberos = true
+disable-methods = "clear,crypt"
+default-hash = "md5"
+password-minimal-length = 10
+password-minimal-differ = 3
+password-policy-checker = "/usr/local/bin/policy-checker.sh"
+allow-auth-by-mail = false
+
+[plugin/network]
+auto-detect = "/usr/local/bin/autodetect.sh"
+
+[plugin/mailqueue]
+queue-script = "/usr/local/bin/queue-script.sh"
+
+[plugin/environment]
+kiosk-path = "/var/spool/kiosk"
+ppd-path = "/var/spool/ppds"
diff --git a/include/autoload-data.inc b/include/autoload-data.inc
new file mode 100644 (file)
index 0000000..f8e0159
--- /dev/null
@@ -0,0 +1,14 @@
+<?php
+$class_mapping= array(
+                "Registry" => "include/class_Registry.inc",
+                "ConfigManagerException" => "include/class_ConfigManager.inc",
+                "ConfigManager" => "include/class_ConfigManager.inc",
+                "AutoloadException" => "include/autoload.inc",
+                "ObjectListException" => "include/class_ObjectList.inc",
+                "ObjectList" => "include/class_ObjectList.inc",
+                "ObjectListViewportException" => "include/class_ObjectListViewport.inc",
+                "ObjectListViewport" => "include/class_ObjectListViewport.inc",
+                "ObjectListIteratorException" => "include/class_ObjectListIterator.inc",
+                "ObjectListIterator" => "include/class_ObjectListIterator.inc",
+);
+?>
\ No newline at end of file
diff --git a/include/autoload.inc b/include/autoload.inc
new file mode 100644 (file)
index 0000000..fb57108
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+
+/* This function needs the pre-defined class mapping from autoload-data.inc */
+require_once("autoload-data.inc");
+
+/* Set BASE_DIR for the complete code as constant */
+define('BASE_DIR', dirname(dirname(__FILE__)));
+
+
+/**
+ * AutoloadException to handle exceptions that happen inside
+ * the autoloader module.
+ */
+class AutoloadException extends Exception {
+        public function __construct($message, $code = 0) {
+                parent::__construct($message, $code);
+        }
+}
+
+
+/**
+ * Loads the requested class from the filesystem.
+ * @param string $class_name
+ * @return -
+ */
+function __autoload($class_name) {
+       global $class_mapping;
+
+       /* Load data for class locations */
+
+       if (isset($class_mapping[$class_name])){
+               require_once(BASE_DIR."/".$class_mapping[$class_name]);
+       } else {
+               eval("class $class_name {}");
+               throw new AutoloadException(sprintf(_("Cannot load class '%s'!"), $class_name));
+       }
+}
+
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
diff --git a/include/class_ConfigManager.inc b/include/class_ConfigManager.inc
new file mode 100644 (file)
index 0000000..67061c7
--- /dev/null
@@ -0,0 +1,86 @@
+<?php
+
+/**
+ * ConfigManagerException to handle exceptions that happen inside
+ * the config manager module.
+ */
+class ConfigManagerException extends Exception {
+       public function __construct($message, $code = 0) {
+               parent::__construct($message, $code);
+       }
+}
+
+
+/**
+ * ConfigManager loads and manages GOsa session configurations.
+ *
+ * This class should be integrated via Registry.
+ */
+class ConfigManager {
+
+       /* Config container */
+       protected $config= NULL;
+
+       public function __construct(){}
+
+       /**
+        * Returns a static instance of $class
+        * Creates a new instance of $class if required.
+        * @param string $class
+        * @return obj $$class
+        */
+       public function load($file){
+               if (!is_readable($file)){
+                       throw new ConfigManagerException(sprintf(_("Can't read configuration file '%s'!"), $file));
+               }
+
+               /* Capture errors - just the first line is interesting */
+               ob_start(); 
+               $this->config= parse_ini_file($file, TRUE);
+               $ret= preg_replace( array('/^.*\nWarning: /', '/\n.*$/'),
+                                   array('', ''),
+                                   ob_get_contents());
+               ob_end_clean(); 
+
+               /* Bail out in case of errors */
+               if ($ret != ""){
+                       throw new ConfigManagerException($ret);
+               }
+
+               echo "Test config and load additional configuration data from LDAP\n";
+               #$this->test_config();
+               #$this->load_servers();        -> Section servers/...;
+               #$this->load_plugin_configs(); -> Section pugins/name/value;
+
+               print_r($this->config);
+       }
+
+
+       public function save($file){
+       }
+
+
+       public function set_section($section_name){
+       }
+
+
+       public function &get_section(){
+       }
+
+
+       public function &get_sections(){
+       }
+
+
+       public function &get_value($section){
+       }
+
+
+       public function set_value($section, $value){
+       }
+
+}
+
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
diff --git a/include/class_LdapAttributeFactory.inc b/include/class_LdapAttributeFactory.inc
new file mode 100644 (file)
index 0000000..5db7001
--- /dev/null
@@ -0,0 +1,3 @@
+<?php
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
diff --git a/include/class_LdapManager.inc b/include/class_LdapManager.inc
new file mode 100644 (file)
index 0000000..5db7001
--- /dev/null
@@ -0,0 +1,3 @@
+<?php
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
diff --git a/include/class_LdapObject.inc b/include/class_LdapObject.inc
new file mode 100644 (file)
index 0000000..5db7001
--- /dev/null
@@ -0,0 +1,3 @@
+<?php
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
diff --git a/include/class_ObjectList.inc b/include/class_ObjectList.inc
new file mode 100644 (file)
index 0000000..51d59ec
--- /dev/null
@@ -0,0 +1,145 @@
+<?php
+
+/*! \brief   Exception implementation for ObjectList
+    \author  Cajus Pollmeier <pollmeier@gonicus.de>
+    \version 1.00
+    \date    2007/11/02
+
+    This class handles the exceptions occuring in ObjectList.
+ */
+class ObjectListException extends Exception {
+       public function __construct($message, $code = 0) {
+               parent::__construct($message, $code);
+       }
+}
+
+/*! \brief   Implementation for keeping a list of objects
+    \author  Cajus Pollmeier <pollmeier@gonicus.de>
+    \version 1.00
+    \date    2007/11/02
+
+    The class ObjectList handles a list of objects found in the database
+    based on an optional filter modules. This objects can be iterated
+    directly.
+
+    \sa ObjectListIterator
+ */
+class ObjectList implements IteratorAggregate {
+
+  /*!
+    \brief Container for objects
+
+    This variable stores the list of objects.
+   */
+       private $objects;
+
+  /*!
+    \brief List headline
+
+    String that keeps the desired headline. Returned by ObjectList::getHeadline.
+
+    \sa ObjectList::getHeadline
+   */
+  private $headline;
+
+  /*!
+    \brief List footer
+
+    String that keeps the desired footer. Returned by ObjectList::getFooter.
+
+    \sa ObjectList::getFooter
+   */
+  private $footer;
+
+  /*!
+    \brief Config
+
+    Config array that keeps the classes we do lists for, filter information, etc.
+   */
+  private $config;
+
+
+  /*! \brief ObjectList constructor
+
+    The ObjectList is initialized by a list of classes we're interested
+    in. Rest is done by instances of Filter registered in the Registry.
+
+    \param config Config section that is used to configure this ObjectList
+    \sa Registry
+    \sa Filter
+   */
+       public function __construct(&$config){
+
+    /* Save current config */
+    $this->config= &$config;
+
+    /* Load and instanciate classes, extract filter, icons, view hooks, etc. */
+    $this->load();
+
+  }
+
+
+       /*! \brief Function to initialy load object list
+
+         Internally loads the relevant list of objects depending on eventually
+         defined filter modules. Handles sorting, too.
+        */
+       private function load(){
+    # Crap filling
+    $this->objects= array( array("i", "Testobjekt mit was auch immer", "UPS"),
+                           array("i", "Noch ein Testobjekt", "UPS"),
+                           array("d", "Ein drittes Testobjekt", "UL"));
+    $this->headline= "|{16px}|{90%}Name|{64px}Actions|";
+
+    $this->footer= "Statistical footer";
+       }
+
+
+       /*! \brief Function to reload object list in case of external changes
+
+         Triggers a reload the relevant list of objects depending on eventually
+         defined filter modules. Handles sorting, too.
+        */
+  public function reload(){
+  }
+
+
+       /*! \brief Function to return the iterator object for this class.
+
+      This function is used internally by PHP to produce an iterator.
+
+      \return Iterator object
+
+      \sa ObjectListIterator
+        */
+  public function getIterator() {
+    return new ObjectListIterator($this->objects);
+  }
+
+
+       /*! \brief Function to get the desired headline
+
+      Return the property of headline to the public world.
+
+      \return headline for current list
+        */
+  public function getHeadline() {
+    return $this->headline;
+  }
+
+
+       /*! \brief Function to get the desired footer
+
+      Return the property of footer to the public world.
+
+      \return headline for current list
+        */
+  public function getFooter() {
+    return $this->footer;
+  }
+
+}
+
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
diff --git a/include/class_ObjectListIterator.inc b/include/class_ObjectListIterator.inc
new file mode 100644 (file)
index 0000000..c1eaddd
--- /dev/null
@@ -0,0 +1,78 @@
+<?php
+
+/*! \brief   Implementation for iterating through ObjectList objects
+    \author  Cajus Pollmeier <pollmeier@gonicus.de>
+    \version 1.00
+    \date    2007/11/02
+
+    The class ObjectList handles a list of objects found in the database
+    based on an optional filter modules. This objects can be iterated
+    directly by using this iterator class.
+
+    \sa ObjectList
+ */
+class ObjectListIterator implements Iterator {
+
+  /*!
+    \brief Reference container for objects
+
+    This variable stores the list of objects.
+   */
+       private $objects;
+
+  /*!
+    \brief Iterator position
+
+    Keeps the current position inside our ObjectList
+   */
+  private $position;
+
+  /*! \brief ObjectListIterator constructor
+
+    The ObjectListIterator is initialized by a list of objects from the
+    ObjectList object.
+
+    \param objects List of objects to be iterated
+   */
+       public function __construct(&$objects){
+    $this->objects= &$objects;
+  }
+
+
+  /*! \brief Rewind to the begining of the ObjectList */
+  public function rewind(){
+    $this->position= 0;
+  }
+
+
+  /*! \brief Check if the next object is valid */
+  public function valid() {
+    return isset($this->objects[$this->position]);
+  }
+
+
+  /*! \brief Return the current key
+      \return integer Current position
+   */
+  public function key() {
+    return $this->position;
+  }
+  
+
+  /*! \brief Return the current value
+      \return object Current value
+   */
+  public function current() {
+    return $this->objects[$this->position];
+  }
+
+
+  /*! \brief Go to the next index */
+  public function next() {
+    $this->position++;
+  }
+
+}
+
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
diff --git a/include/class_ObjectListViewport.inc b/include/class_ObjectListViewport.inc
new file mode 100644 (file)
index 0000000..e7ed791
--- /dev/null
@@ -0,0 +1,120 @@
+<?php
+
+/*! \brief   Exception implementation for ObjectListViewport
+    \author  Cajus Pollmeier <pollmeier@gonicus.de>
+    \version 1.00
+    \date    2007/11/02
+
+    This class handles the exceptions occuring in ObjectListViewport.
+ */
+class ObjectListViewportException extends Exception {
+       public function __construct($message, $code = 0) {
+               parent::__construct($message, $code);
+       }
+}
+
+/*! \brief   Implementation for ObjectListViewport
+    \author  Cajus Pollmeier <pollmeier@gonicus.de>
+    \version 1.00
+    \date    2007/11/02
+
+    This class handles painting of ObjectList objects.
+
+    \sa ObjectList
+ */
+class ObjectListViewport {
+
+  /*!
+    \brief Container for objects
+
+    This variable stores the ObjectList object to be displayed.
+   */
+       private $objects;
+
+
+  /*! \brief ObjectListViewport constructor
+
+    The ObjectListViewport class renders/handles the ObjectList defined by $config.
+
+    \param config Config section that is used to configure this ObjectListViewport
+   */
+       public function __construct($config){
+
+    /* Load and instanciate classes, extract filter, icons, view hooks, etc. */
+    $this->objects= new ObjectList($config);
+  }
+
+       /*! \brief Handles _POST / _GET events
+
+           Processes the list of registered plugins to do their eventHandler and adapt
+      internal objectlist according to this.
+        */
+  public function eventHandler(){
+    /* Reloads the list if things have changed interally */
+    $this->objects->reload();
+  }
+
+
+       /*! \brief Renders headline into a string
+
+           Gets the headline description from the ObjectList object and renders it.
+
+      \return HTML rendered headline
+        */
+  private function renderHeadline(){
+    return $this->objects->getHeadline()."\n";
+  }
+
+
+       /*! \brief Renders footer into a string
+
+           Gets the footer description from the ObjectList object and renders it.
+
+      \return HTML rendered footer
+        */
+  private function renderFooter(){
+    return $this->objects->getFooter()."\n";
+  }
+
+
+       /*! \brief Renders entries from the ObjectList iterator into a string
+
+           Gets the entry descriptions from the ObjectList object and renders them.
+
+      \return HTML rendered list entries
+        */
+  private function renderEntry($entry){
+    $buffer= "|";
+    foreach ($entry as $column){
+      $buffer.= "$column|";
+    }
+    $buffer.= "\n";
+
+    return $buffer;
+  }
+
+
+       /*! \brief Renders complete ObjectList into a string
+
+      \return HTML rendered list
+        */
+  public function render() {
+    /* Generate fixed headline */
+    $buffer= $this->renderHeadline();
+
+    /* Generate scrollable contents */
+    foreach ($this->objects as $value){
+      $buffer.= $this->renderEntry($value);
+    }
+
+    /* Generate footer */
+    $buffer.= $this->renderFooter();
+
+    return ($buffer);
+  }
+
+}
+
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
diff --git a/include/class_Registry.inc b/include/class_Registry.inc
new file mode 100644 (file)
index 0000000..3d611f6
--- /dev/null
@@ -0,0 +1,30 @@
+<?php
+
+/**
+ * GOsa Registry of static class instances that are accessible
+ * from all locations.
+ *
+ * Creates a new instance of the requested class if required.
+ */
+class Registry {
+
+       static private $registry = array();
+
+       private function __construct(){}
+
+       /**
+        * Returns a static instance of $class
+        * Creates a new instance of $class if required.
+        * @param string $class
+        * @return obj $$class
+        */
+       static function getInstance($class){
+               if (!isset(Registry::$registry[$class])){
+                       Registry::$registry[$class]= new $class;
+               }
+               return Registry::$registry[$class];
+       }
+}
+
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
diff --git a/test b/test
new file mode 100755 (executable)
index 0000000..3b4469d
--- /dev/null
+++ b/test
@@ -0,0 +1,28 @@
+#!/usr/bin/php
+<?php
+
+/* This is good for testing... */
+error_reporting (E_ALL | E_STRICT);
+
+/* Initiate autoloader... */
+require_once("include/autoload.inc");
+
+try {
+
+       /* Get new test instance of the Configuration */
+       #$cr= Registry::getInstance("ConfigManager");
+       #$cr->load("gosa.conf");
+
+       /* Get a new test instance of ObjectListViewports */
+       $vp= new ObjectListViewport(array("dummy", "dummy"));
+       echo $vp->render();
+
+} catch (Exception $e) {
+       echo "\n-GOsa Exception-----------------------------------------------------------\n\n".
+            $e->__toString().
+            "\n\n--------------------------------------------------------------------------\n\n";
+}
+
+exit (0);
+
+?>
diff --git a/update-gosa b/update-gosa
new file mode 100755 (executable)
index 0000000..fe2816e
--- /dev/null
@@ -0,0 +1,81 @@
+#!/usr/bin/php5
+<?php
+
+/* Function to include all class_ files starting at a given directory base */
+function get_classes($folder= ".")
+{
+  static $base_dir= "";
+  static $result= array();
+
+  if ($base_dir == ""){
+    $base_dir= getcwd();
+  }
+
+  $currdir=getcwd();
+  if ($folder){
+    chdir("$folder");
+  }
+
+  $dh = opendir(".");
+  while(false !== ($file = readdir($dh))){
+
+    if (preg_match("/.*\.svn.*/", $file) ||
+        preg_match("/.*smarty.*/i",$file) ||
+        preg_match("/.*\.tpl.*/",$file) ||
+        ($file==".") ||($file =="..")){
+      continue;
+    }
+
+    /* Recurse through all "common" directories */
+    if (is_dir($file)){
+      get_classes($file);
+      continue;
+    }
+
+    /* Only take care about .inc and .php files... */
+    if (!(preg_match('/\.php$/', $file) || preg_match('/\.inc$/', $file))){
+      continue;
+    }
+
+    /* Include existing class_ files */
+    $contents= file($file);
+    foreach($contents as $line){
+      $line= chop($line);
+      if (preg_match('/^\s*class\s*\w.*$/', $line)){
+        $class= preg_replace('/^\s*class\s*(\w+).*$/', '\1', $line);
+        $result[$class]= preg_replace("%$base_dir/%", "", "$currdir/$folder/$file");
+      }
+    }
+  }
+
+  closedir($dh);
+  chdir($currdir);
+
+  return ($result);
+}
+
+$class_mapping= get_classes();
+$filename= "include/autoload-data.inc";
+
+/* Sanity checks */
+if (is_writable($filename)) {
+
+    if (!$handle= fopen($filename, 'w')) {
+         echo "Cannot open file \"$filename\" - aborted\n";
+         exit (1);
+    }
+
+} else {
+    echo "File \"$filename\" is not writable - aborted\n";
+    exit (2);
+}
+
+fwrite ($handle, "<?php\n\$class_mapping= array(\n");
+foreach ($class_mapping as $key => $value){
+  fwrite ($handle, "                \"$key\" => \"$value\",\n");
+}
+fwrite ($handle, ");\n?>");
+
+fclose($handle);
+
+?>