From cbda30058c0f61ae2afbd9085afcf841f32751a5 Mon Sep 17 00:00:00 2001 From: tbrehm <t.brehm@ispconfig.org> Date: Tue, 27 Jan 2009 11:50:52 -0500 Subject: [PATCH] Fixed: FS#431 - jailkit users cannot login --- interface/lib/classes/tform.inc.php | 189 +++++++++++++++++++++++++--------------------- 1 files changed, 102 insertions(+), 87 deletions(-) diff --git a/interface/lib/classes/tform.inc.php b/interface/lib/classes/tform.inc.php index 64fa438..4bf2269 100644 --- a/interface/lib/classes/tform.inc.php +++ b/interface/lib/classes/tform.inc.php @@ -1,7 +1,7 @@ <?php /* -Copyright (c) 2005, Till Brehm, projektfarm Gmbh +Copyright (c) 2007, Till Brehm, projektfarm Gmbh All rights reserved. Redistribution and use in source and binary forms, with or without modification, @@ -31,43 +31,37 @@ /** * Formularbehandlung * -* Funktionen zur Umwandlung von Formulardaten -* sowie zum vorbereiten von HTML und SQL -* Ausgaben +* Functions to validate, display and save form values * -* Tabellendefinition +* Database table field definitions * -* Datentypen: -* - INTEGER (Wandelt Ausdr�cke in Int um) +* Datatypes: +* - INTEGER (Converts data to int automatically) * - DOUBLE -* - CURRENCY (Formatiert Zahlen nach W�hrungsnotation) -* - VARCHAR (kein weiterer Format Check) -* - DATE (Datumsformat, Timestamp Umwandlung) +* - CURRENCY (Formats digits in currency notation) +* - VARCHAR (No format check) +* - DATE (Date format, converts from and to linux timestamps automatically) * * Formtype: -* - TEXT (normales Textfeld) -* - PASSWORD (Feldinhalt wird nicht angezeigt) -* - SELECT (Gibt Werte als option Feld aus) -* - MULTIPLE (Select-Feld mit nehreren Werten) +* - TEXT (Normal text field) +* - PASSWORD (password field, the content will not be displayed again to the user) +* - SELECT (Option fiield) +* - MULTIPLE (Allows selection of multiple values) * * VALUE: -* - Wert oder Array +* - Value or array * * SEPARATOR -* - Trennzeichen f�r multiple Felder +* - separator char used for fileds with multiple values * -* Hinweis: -* Das ID-Feld ist nicht bei den Table Values einzuf�gen. +* Hint: The auto increment (ID) filed of the table has not be be definied eoarately. * -* @package form -* @author Till Brehm -* @version 1.1 */ class tform { /** - * Definition der Tabelle (array) + * Table definition (array) * @var tableDef */ var $tableDef; @@ -79,26 +73,25 @@ var $action; /** - * Tabellenname (String) + * Table name (String) * @var table_name */ var $table_name; /** - * Debug Variable + * Enable debigging * @var debug */ var $debug = 0; /** - * name des primary Field der Tabelle (string) + * name of the primary field of the datbase table (string) * @var table_index */ var $table_index; /** - * enth�lt die Fehlermeldung bei �berpr�fung - * der Variablen mit Regex + * contains the error message * @var errorMessage */ var $errorMessage = ''; @@ -111,9 +104,9 @@ var $diffrec = array(); /** - * Laden der Tabellendefinition + * Loading of the table definition * - * @param file: Pfad zur Tabellendefinition + * @param file: path to the form definition file * @return true */ /* @@ -137,14 +130,15 @@ $this->module = $module; $wb = array(); + include_once(ISPC_ROOT_PATH.'/lib/lang/'.$_SESSION['s']['language'].'.lng'); if($module == '') { - if(is_file("lib/lang/".$_SESSION["s"]["language"]."_".$this->formDef["name"].".lng")) { - include_once("lib/lang/".$_SESSION["s"]["language"]."_".$this->formDef["name"].".lng"); - } + $lng_file = "lib/lang/".$_SESSION["s"]["language"]."_".$this->formDef["name"].".lng"; + if(!file_exists($lng_file)) $lng_file = "lib/lang/en_".$this->formDef["name"].".lng"; + include($lng_file); } else { - if(is_file("../$module/lib/lang/".$_SESSION["s"]["language"]."_".$this->formDef["name"].".lng")) { - include_once("../$module/lib/lang/".$_SESSION["s"]["language"]."_".$this->formDef["name"].".lng"); - } + $lng_file = "../$module/lib/lang/".$_SESSION["s"]["language"]."_".$this->formDef["name"].".lng"; + if(!file_exists($lng_file)) $lng_file = "../$module/lib/lang/en_".$this->formDef["name"].".lng"; + include($lng_file); } $this->wordbook = $wb; @@ -153,15 +147,14 @@ /** - * Konvertiert die Daten des �bergebenen assoziativen - * Arrays in "menschenlesbare" Form. - * Datentyp Konvertierung, z.B. f�r Ausgabe in Listen. + * Converts the data in the array to human readable format + * Datatype conversion e.g. to show the data in lists * * @param record * @return record */ function decode($record,$tab) { - if(!is_array($this->formDef['tabs'][$tab])) $app->error("Tab ist leer oder existiert nicht (TAB: $tab)."); + if(!is_array($this->formDef['tabs'][$tab])) $app->error("Tab does not exist or the tab is empty (TAB: $tab)."); $new_record = ''; if(is_array($record)) { foreach($this->formDef['tabs'][$tab]['fields'] as $key => $field) { @@ -252,7 +245,7 @@ $app->uses($datasource_class); $values = $app->$datasource_class->$datasource_function($field, $record); } else { - $this->errorMessage .= "Custom datasource class or function is empty<br>\r\n"; + $this->errorMessage .= "Custom datasource class or function is empty<br />\r\n"; } } @@ -262,7 +255,7 @@ /** - * Record f�r Ausgabe in Formularen vorbereiten. + * Prepare the data record to show the data in a form. * * @param record = Datensatz als Array * @param action = NEW oder EDIT @@ -274,8 +267,8 @@ $this->action = $action; - if(!is_array($this->formDef)) $app->error("Keine Formdefinition vorhanden."); - if(!is_array($this->formDef['tabs'][$tab])) $app->error("Tab ist leer oder existiert nicht (TAB: $tab)."); + if(!is_array($this->formDef)) $app->error("No form definition found."); + if(!is_array($this->formDef['tabs'][$tab])) $app->error("The tab is empty or does not exist (TAB: $tab)."); $new_record = array(); if($action == 'EDIT') { @@ -303,10 +296,10 @@ case 'MULTIPLE': if(is_array($field['value'])) { - // aufsplitten ergebnisse + // Split $vals = explode($field['separator'],$val); - // HTML schreiben + // write HTML $out = ''; foreach($field['value'] as $k => $v) { @@ -473,8 +466,8 @@ } /** - * Record in "maschinen lesbares" Format �berf�hren - * und Werte gegen regul�re Ausdr�cke pr�fen. + * Rewrite the record data to be stored in the database + * and check values with regular expressions. * * @param record = Datensatz als Array * @return record @@ -482,7 +475,7 @@ function encode($record,$tab) { global $app; - if(!is_array($this->formDef['tabs'][$tab])) $app->error("Tab ist leer oder existiert nicht (TAB: $tab)."); + if(!is_array($this->formDef['tabs'][$tab])) $app->error("Tab is empty or does not exist (TAB: $tab)."); //$this->errorMessage = ''; if(is_array($record)) { @@ -532,7 +525,7 @@ $field['regex'] .= 's'; if(!preg_match($field['regex'], $record[$key])) { $errmsg = $field['errmsg']; - $this->errorMessage .= $this->wordbook[$errmsg]."<br>\r\n"; + $this->errorMessage .= $this->wordbook[$errmsg]."<br />\r\n"; } } @@ -566,9 +559,9 @@ if(!preg_match($validator['regex'], $field_value)) { $errmsg = $validator['errmsg']; if(isset($this->wordbook[$errmsg])) { - $this->errorMessage .= $this->wordbook[$errmsg]."<br>\r\n"; + $this->errorMessage .= $this->wordbook[$errmsg]."<br />\r\n"; } else { - $this->errorMessage .= $errmsg."<br>\r\n"; + $this->errorMessage .= $errmsg."<br />\r\n"; } } break; @@ -578,9 +571,9 @@ if($num_rec["number"] > 0) { $errmsg = $validator['errmsg']; if(isset($this->wordbook[$errmsg])) { - $this->errorMessage .= $this->wordbook[$errmsg]."<br>\r\n"; + $this->errorMessage .= $this->wordbook[$errmsg]."<br />\r\n"; } else { - $this->errorMessage .= $errmsg."<br>\r\n"; + $this->errorMessage .= $errmsg."<br />\r\n"; } } } else { @@ -588,9 +581,9 @@ if($num_rec["number"] > 0) { $errmsg = $validator['errmsg']; if(isset($this->wordbook[$errmsg])) { - $this->errorMessage .= $this->wordbook[$errmsg]."<br>\r\n"; + $this->errorMessage .= $this->wordbook[$errmsg]."<br />\r\n"; } else { - $this->errorMessage .= $errmsg."<br>\r\n"; + $this->errorMessage .= $errmsg."<br />\r\n"; } } } @@ -599,9 +592,9 @@ if(empty($field_value)) { $errmsg = $validator['errmsg']; if(isset($this->wordbook[$errmsg])) { - $this->errorMessage .= $this->wordbook[$errmsg]."<br>\r\n"; + $this->errorMessage .= $this->wordbook[$errmsg]."<br />\r\n"; } else { - $this->errorMessage .= $errmsg."<br>\r\n"; + $this->errorMessage .= $errmsg."<br />\r\n"; } } break; @@ -609,9 +602,9 @@ if(!preg_match("/^\w+[\w.-]*\w+@\w+[\w.-]*\w+\.[a-z]{2,10}$/i", $field_value)) { $errmsg = $validator['errmsg']; if(isset($this->wordbook[$errmsg])) { - $this->errorMessage .= $this->wordbook[$errmsg]."<br>\r\n"; + $this->errorMessage .= $this->wordbook[$errmsg]."<br />\r\n"; } else { - $this->errorMessage .= $errmsg."<br>\r\n"; + $this->errorMessage .= $errmsg."<br />\r\n"; } } break; @@ -620,9 +613,9 @@ if($tmpval === 0 and !empty($field_value)) { $errmsg = $validator['errmsg']; if(isset($this->wordbook[$errmsg])) { - $this->errorMessage .= $this->wordbook[$errmsg]."<br>\r\n"; + $this->errorMessage .= $this->wordbook[$errmsg]."<br />\r\n"; } else { - $this->errorMessage .= $errmsg."<br>\r\n"; + $this->errorMessage .= $errmsg."<br />\r\n"; } } break; @@ -630,11 +623,29 @@ if(!is_numeric($field_value) || $field_value <= 0){ $errmsg = $validator['errmsg']; if(isset($this->wordbook[$errmsg])) { - $this->errorMessage .= $this->wordbook[$errmsg]."<br>\r\n"; + $this->errorMessage .= $this->wordbook[$errmsg]."<br />\r\n"; } else { - $this->errorMessage .= $errmsg."<br>\r\n"; + $this->errorMessage .= $errmsg."<br />\r\n"; } } + break; + case 'ISIPV4': + $vip=1; + if(preg_match("/^[0-9]{1,3}(\.)[0-9]{1,3}(\.)[0-9]{1,3}(\.)[0-9]{1,3}$/", $field_value)){ + $groups=explode(".",$field_value); + foreach($groups as $group){ + if($group<0 OR $group>255) + $vip=0; + } + }else{$vip=0;} + if($vip==0) { + $errmsg = $validator['errmsg']; + if(isset($this->wordbook[$errmsg])) { + $this->errorMessage .= $this->wordbook[$errmsg]."<br />\r\n"; + } else { + $this->errorMessage .= $errmsg."<br />\r\n"; + } + } break; case 'CUSTOM': // Calls a custom class to validate this record @@ -644,7 +655,7 @@ $app->uses($validator_class); $this->errorMessage .= $app->$validator_class->$validator_function($field_name, $field_value, $validator); } else { - $this->errorMessage .= "Custom validator class or function is empty<br>\r\n"; + $this->errorMessage .= "Custom validator class or function is empty<br />\r\n"; } break; default: @@ -659,7 +670,7 @@ } /** - * SQL Statement f�r Record erzeugen. + * Create the SQL staement. * * @param record = Datensatz als Array * @param action = INSERT oder UPDATE @@ -676,9 +687,9 @@ // checking permissions if($this->formDef['auth'] == 'yes' && $_SESSION["s"]["user"]["typ"] != 'admin') { if($action == "INSERT") { - if(!$this->checkPerm($primary_id,'i')) $this->errorMessage .= "Insert denied.<br>\r\n"; + if(!$this->checkPerm($primary_id,'i')) $this->errorMessage .= "Insert denied.<br />\r\n"; } else { - if(!$this->checkPerm($primary_id,'u')) $this->errorMessage .= "Update denied.<br>\r\n"; + if(!$this->checkPerm($primary_id,'u')) $this->errorMessage .= "Update denied.<br />\r\n"; } } @@ -774,7 +785,7 @@ } - // F�ge Backticks nur bei unvollst�ndigen Tabellennamen ein + // Add backticks for incomplete table names if(stristr($this->formDef['db_table'],'.')) { $escape = ''; } else { @@ -784,7 +795,7 @@ if($action == "INSERT") { if($this->formDef['auth'] == 'yes') { - // Setze User und Gruppe + // Set user and group $sql_insert_key .= "`sys_userid`, "; $sql_insert_val .= ($this->formDef["auth_preset"]["userid"] > 0)?"'".$this->formDef["auth_preset"]["userid"]."', ":"'".$_SESSION["s"]["user"]["userid"]."', "; $sql_insert_key .= "`sys_groupid`, "; @@ -843,17 +854,16 @@ $active_tab = $this->getNextTab(); - // definiere Tabs + // go trough the tabs foreach( $this->formDef["tabs"] as $key => $tab) { $tab['name'] = $key; if($tab['name'] == $active_tab) { - // Wenn Modul gesetzt, dann setzte template pfad relativ zu modul. + // If module is set, then set the template path relative to the module.. if($this->module != '') $tab["template"] = "../".$this->module."/".$tab["template"]; - // �berpr�fe, ob das Template existiert, wenn nicht - // dann generiere das Template + // Generate the template if it does not exist yet. // Translate the title of the tab $tab['title'] = $this->lng($tab['title']); @@ -870,7 +880,7 @@ $tab["active"] = 0; } - // Die Datenfelder werden f�r die Tabs nicht ben�tigt + // Unset unused variables. unset($tab["fields"]); unset($tab["plugins"]); @@ -905,15 +915,15 @@ function datalogSave($action,$primary_id, $record_old, $record_new) { global $app,$conf; - // F�ge Backticks nur bei unvollst�ndigen Tabellennamen ein + // Add backticks for incomplete table names. if(stristr($this->formDef['db_table'],'.')) { $escape = ''; } else { $escape = '`'; } - $diffrec = array(); - + $this->diffrec = array(); + /* if(is_array($record_new) && count($record_new) > 0) { foreach($record_new as $key => $val) { if(@$record_old[$key] != $val) { @@ -932,7 +942,7 @@ } } $this->diffrec = $diffrec; - + */ // Full diff records for ISPConfig, they have a different format then the simple diffrec $diffrec_full = array(); @@ -944,6 +954,8 @@ // Record has changed $diffrec_full['old'][$key] = $val; $diffrec_full['new'][$key] = $record_new[$key]; + $this->diffrec[$key] = array( 'new' => $record_new[$key], + 'old' => $val); } else { $diffrec_full['old'][$key] = $val; $diffrec_full['new'][$key] = $val; @@ -955,6 +967,8 @@ // Record has changed $diffrec_full['new'][$key] = $val; $diffrec_full['old'][$key] = $record_old[$key]; + $this->diffrec[$key] = array( 'old' => @$record_old[$key], + 'new' => $val); } else { $diffrec_full['new'][$key] = $val; $diffrec_full['old'][$key] = $val; @@ -962,12 +976,13 @@ } } + //$this->diffrec = $diffrec; // Insert the server_id, if the record has a server_id $server_id = (isset($record_old["server_id"]) && $record_old["server_id"] > 0)?$record_old["server_id"]:0; if(isset($record_new["server_id"])) $server_id = $record_new["server_id"]; if(count($this->diffrec) > 0) { - $diffstr = $app->db->quote(serialize($diffrec_full)); + $diffstr = addslashes(serialize($diffrec_full)); $username = $app->db->quote($_SESSION["s"]["user"]["username"]); $dbidx = $this->formDef['db_table_idx'].":".$primary_id; // $action = ($action == 'INSERT')?'i':'u'; @@ -999,14 +1014,14 @@ } /* - Diese funktion �berpr�ft, ob ein User die Berechtigung $perm f�r den Datensatz mit der ID $record_id - hat. It record_id = 0, dann wird gegen die user Defaults des Formulares getestet. + This function checks if a user has the parmissions $perm for the data record with the ID $record_id + If record_id = 0, the the permissions are tested against the defaults of the form file. */ function checkPerm($record_id,$perm) { global $app; if($record_id > 0) { - // F�ge Backticks nur bei unvollst�ndigen Tabellennamen ein + // Add backticks for incomplete table names. if(stristr($this->formDef['db_table'],'.')) { $escape = ''; } else { @@ -1035,18 +1050,18 @@ } function getNextTab() { - // Welcher Tab wird angezeigt + // Which tab is shown if($this->errorMessage == '') { - // wenn kein Fehler vorliegt + // If there is no error if(isset($_REQUEST["next_tab"]) && $_REQUEST["next_tab"] != '') { - // wenn n�chster Tab bekannt + // If the next tab is known $active_tab = $_REQUEST["next_tab"]; } else { - // ansonsten ersten tab nehmen + // else use the default tab $active_tab = $this->formDef['tab_default']; } } else { - // bei Fehlern den gleichen Tab nochmal anzeigen + // Show the same tab again in case of an error $active_tab = $_SESSION["s"]["form"]["tab"]; } -- Gitblit v1.9.1