From ec09b18c9c44f85ceb6d9e7588a03a221cd1193f Mon Sep 17 00:00:00 2001 From: tbrehm <t.brehm@ispconfig.org> Date: Fri, 12 Dec 2008 05:47:05 -0500 Subject: [PATCH] Disallow server changes for existing records in mail_domain_edit.php --- interface/lib/classes/tform.inc.php | 160 +++++++++++++++++++++++++--------------------------- 1 files changed, 77 insertions(+), 83 deletions(-) diff --git a/interface/lib/classes/tform.inc.php b/interface/lib/classes/tform.inc.php index 64fa438..888c0b6 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,17 @@ $this->module = $module; $wb = array(); + $lng_file = ISPC_WEB_PATH.'/lang/lib/lang/'.$_SESSION['s']['language'].'_tform.lng'; + if(!file_exists($lng_file)) $lng_file = ISPC_WEB_PATH.'/lang/lib/lang/en'.'_tform.lng'; + include($lng_file); 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 +149,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 +247,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 +257,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 +269,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 +298,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 +468,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 +477,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 +527,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 +561,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 +573,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 +583,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 +594,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 +604,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 +615,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,9 +625,9 @@ 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; @@ -644,7 +639,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 +654,7 @@ } /** - * SQL Statement f�r Record erzeugen. + * Create the SQL staement. * * @param record = Datensatz als Array * @param action = INSERT oder UPDATE @@ -676,9 +671,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 +769,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 +779,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 +838,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 +864,7 @@ $tab["active"] = 0; } - // Die Datenfelder werden f�r die Tabs nicht ben�tigt + // Unset unused variables. unset($tab["fields"]); unset($tab["plugins"]); @@ -905,7 +899,7 @@ 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 { @@ -999,14 +993,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 +1029,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