Code

Updated macro checks
[gosa.git] / plugins / gofon / macro / class_gofonMacro.inc
old mode 100755 (executable)
new mode 100644 (file)
index e3c67e4..6043a63
@@ -9,13 +9,6 @@
 */
 class macro extends plugin
 {
-  /*! CLI vars */
-  var $cli_summary= "Handling of GOsa's macro object";
-  /*! CLI vars */
-  var $cli_description= "Some longer text\nfor help";
-  /*! CLI vars */
-  var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
-
   /*! Macro attributes,  */
   var $generate_error= "";
   
@@ -49,6 +42,8 @@ class macro extends plugin
 
   var $goFonHomeServers = array(); // Contains all available asterisk database server 
 
+  var $is_new = FALSE;
+
   //! The Konstructor   
   /*!  Konstructor, load class with  attributes of the given dn*/
   function macro ($config, $dn= NULL, $parent= NULL)
@@ -60,6 +55,7 @@ class macro extends plugin
 
     /* Edit or new one ?*/
     if ($this->dn == "new"){
+      $this->is_new = TRUE;
       if(isset($_SESSION['CurrentMainBase'])){
         $this->base = $_SESSION['CurrentMainBase'];
       }else{
@@ -221,6 +217,7 @@ class macro extends plugin
         $r_current  =  @mysql_pconnect($Server['SERVER'],$Server['LOGIN'],$Server['PASSWORD']);
         $db_current =  @mysql_select_db($Server['DB'],$r_current);
         $res = @mysql_query($query,$r_current);
+        @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query, "Database query");
         if(!$res){
           gosa_log(@mysql_error($r_current));
           return(sprintf(_("Removing macro from '%s' failed. Check GOsa log for mysql error."),$Server['SERVER']));
@@ -269,9 +266,10 @@ class macro extends plugin
        * Remove comments introduced by ;
        * Skip empty lines 
        */ 
-      $s_linestr = preg_replace ("/^.*=\> /","",$s_linestr);
-      $s_linestr = preg_replace("/;.*$/","",$s_linestr) ;
       $s_linestr = trim($s_linestr);
+      $s_linestr = preg_replace("/;.*$/","",$s_linestr) ;
+      $s_linestr = preg_replace ("/^.*=\> /","",$s_linestr);
+
       if(empty($s_linestr)){
         continue;
       }
@@ -288,21 +286,23 @@ class macro extends plugin
 #      if(substr_count($s_linestr,",") !=2){
 #        return(sprintf(_("More than two ',' given in line : '%s'. Remember that parameters are seperated by '|'."),$i_linenum));
 #      }
-      /* Multiple () are not supproted currently ... */  
-      if(substr_count($s_linestr,"(") >1 ){
-        return(sprintf(_("More than one '(' is currently not supported. Line : '%s'."),$i_linenum));
-      }
-      if(substr_count($s_linestr,")") >1 ){
-        return(sprintf(_("More than one ')' is currently not supported. Line : '%s'."),$i_linenum));
-      }
+
+#     /* Multiple () are not supproted currently ... */  
+#     if(substr_count($s_linestr,"(") >1 ){
+#       return(sprintf(_("More than one '(' is currently not supported. Line : '%s'."),$i_linenum));
+#     }
+#     if(substr_count($s_linestr,")") >1 ){
+#       return(sprintf(_("More than one ')' is currently not supported. Line : '%s'."),$i_linenum));
+#     }
+
       /* Check if there is an application given */
       if(empty($tmp[1])){
         return(sprintf(_("There is no application given in line : '%s'."),$i_linenum));
-      } 
+      }
       /* Check if there is an extension given */
       if(empty($tmp[0])){
         return(sprintf(_("There is no extension type given in line : '%s'."),$i_linenum));
-      } 
+      }
 
       /* Create extension entry for current line 
        *  and add this line to an array that will be inserted 
@@ -311,8 +311,7 @@ class macro extends plugin
       $exten  = addslashes($tmp[0]);
       $prio   = addslashes($tmp[1]);
       $app    = addslashes(preg_replace("/\(.*\).*$/","",$tmp[2]));
-      $para   = addslashes(preg_replace("/^.*\(/","",$tmp[2]));
-      $para   = preg_replace("/\).*$/","",$para);
+      $para   = addslashes(preg_replace("/^[^(]*\((.*)\)[^)]*$/", "$1", $tmp[2]));
       $sql.= " ('".$context."','".$exten."','".$prio."','".$app."','".$para."'),";
     }
     
@@ -328,6 +327,7 @@ class macro extends plugin
         $db     = @mysql_select_db($cfg['DB'],$r_con);
         $query  = preg_replace("/%TABLENAME%/",$cfg['EXT_TABLE'],$sql);
         $res    = @mysql_query($query,$r_con);
+        @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query, "Database query");
         if(!$res){
           gosa_log(@mysql_error($r_con));
           return(sprintf(_("Insert of new macro failed for server '%s'."),$cfg['SERVER']));
@@ -345,7 +345,7 @@ class macro extends plugin
       plugin::save_object();
 
       /* The cn can't be changed if this entry is not new */
-      if($this->dn!= "new"){
+      if(!$this->is_new){
         $this->cn = $this->orig_cn;
       }
 
@@ -411,12 +411,6 @@ class macro extends plugin
         }
       }
     }
-
-    /* Macro content must be smaller than 100 lines */
-    if(count(split("\n",$this->goFonMacroContent))>100){
-      $message[] = _("Makro length must be lower than 100 lines");
-    }
-
     return $message;
   }
 
@@ -455,7 +449,7 @@ class macro extends plugin
 
     /* Delete references to object groups */
     $ldap->cd ($this->config->current['BASE']);
-    $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
+    $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".@LDAP::prepare4filter($this->dn)."))", array("cn"));
     while ($ldap->fetch()){
       $og= new ogroup($this->config, $ldap->getDN());
       unset($og->member[$this->dn]);