From 5dc3d55f94b14474f436b7c96c0b92794e771f7e Mon Sep 17 00:00:00 2001
From: tbrehm <t.brehm@ispconfig.org>
Date: Wed, 20 Jan 2010 10:53:08 -0500
Subject: [PATCH] Changed the characters that are available to be used in the password salt to avoid decoding problems with certain 64Bit Linux systems.

---
 interface/lib/classes/tform.inc.php |  300 +++++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 268 insertions(+), 32 deletions(-)

diff --git a/interface/lib/classes/tform.inc.php b/interface/lib/classes/tform.inc.php
index 6810419..2d258f6 100644
--- a/interface/lib/classes/tform.inc.php
+++ b/interface/lib/classes/tform.inc.php
@@ -160,11 +160,11 @@
                         foreach($this->formDef['tabs'][$tab]['fields'] as $key => $field) {
                                 switch ($field['datatype']) {
                                 case 'VARCHAR':
-                                        $new_record[$key] = stripslashes($record[$key]);
+                                        $new_record[$key] = $record[$key];
                                 break;
 
                                 case 'TEXT':
-                                        $new_record[$key] = stripslashes($record[$key]);
+                                        $new_record[$key] = $record[$key];
                                 break;
 
                                 case 'DATE':
@@ -186,7 +186,7 @@
                                 break;
 
                                 default:
-                                        $new_record[$key] = stripslashes($record[$key]);
+                                        $new_record[$key] = $record[$key];
                                 }
                         }
 
@@ -275,6 +275,33 @@
 					$allowed = explode(',',$client['lm']);
 				}
 			}
+			
+			//* values are limited to a field in the reseller settings
+			if($limit_parts[0] == 'reseller') {
+				if($_SESSION["s"]["user"]["typ"] == 'admin') {
+					return $values;
+				} else {
+					//* Get the limits of the client that is currently logged in
+					$client_group_id = $_SESSION["s"]["user"]["default_group"];
+					$client = $app->db->queryOneRecord("SELECT parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
+					//echo "SELECT parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id";
+					//* If the client belongs to a reseller, we will check against the reseller Limit too
+					if($client['parent_client_id'] != 0) {
+				
+						//* first we need to know the groups of this reseller
+						$tmp = $app->db->queryOneRecord("SELECT userid, groups FROM sys_user WHERE client_id = ".$client['parent_client_id']);
+						$reseller_groups = $tmp["groups"];
+						$reseller_userid = $tmp["userid"];
+				
+						// Get the limits of the reseller of the logged in client
+						$client_group_id = $_SESSION["s"]["user"]["default_group"];
+						$reseller = $app->db->queryOneRecord("SELECT ".$limit_parts[1]." as lm FROM client WHERE client_id = ".$client['parent_client_id']);
+						$allowed = explode(',',$reseller['lm']);
+					} else {
+						return $values;
+					}
+				} // end if admin
+			} // end if reseller
 			
 			//* values are limited to a field in the system settings
 			if($limit_parts[0] == 'system') {
@@ -381,7 +408,8 @@
                                                                 foreach($vals as $tvl) {
                                                                         if(trim($tvl) == trim($k)) $checked = ' CHECKED';
                                                                 }
-                                                                $out .= "<label for=\"".$key."[]\" class=\"inlineLabel\"><input name=\"".$key."[]\" id=\"".$key."[]\" value=\"$k\" type=\"checkbox\" $checked /> $v</label>\r\n";
+                                                                // $out .= "<label for=\"".$key."[]\" class=\"inlineLabel\"><input name=\"".$key."[]\" id=\"".$key."[]\" value=\"$k\" type=\"checkbox\" $checked /> $v</label>\r\n";
+																$out .= "<input name=\"".$key."[]\" id=\"".$key."[]\" value=\"$k\" type=\"checkbox\" $checked /> $v &nbsp;\r\n";
                                                         }
                                                 }
                                                 $new_record[$key] = $out;
@@ -394,10 +422,25 @@
                                                         $out = '';
                                                         foreach($field['value'] as $k => $v) {
                                                                 $checked = ($k == $val)?' CHECKED':'';
-                                                                $out .= "<label for=\"".$key."[]\" class=\"inlineLabel\"><input name=\"".$key."[]\" id=\"".$key."[]\" value=\"$k\" type=\"radio\" $checked/> $v</label>\r\n";
+                                                                //$out .= "<label for=\"".$key."[]\" class=\"inlineLabel\"><input name=\"".$key."[]\" id=\"".$key."[]\" value=\"$k\" type=\"radio\" $checked/> $v</label>\r\n";
+																$out .= "<input name=\"".$key."[]\" id=\"".$key."[]\" value=\"$k\" type=\"radio\" $checked/> $v\r\n";
                                                         }
                                                 }
                                                 $new_record[$key] = $out;
+                                        break;
+                                        
+                                        case 'DATETIME':
+                                        		if (strtotime($val) !== false) {
+                                        			$dt_value = $val;
+                                        		} elseif ( isset($field['default']) && (strtotime($field['default']) !== false) ) {
+                                        			$dt_value = $field['default'];
+                                        		} else {
+                                        			$dt_value = 0;
+                                        		}
+                                        		
+                                        		$display_seconds = (isset($field['display_seconds']) && $field['display_seconds'] == true) ? true : false;
+		                              
+		                                        $new_record[$key] = $this->_getDateTimeHTML($key, $dt_value, $display_seconds);
                                         break;
 
                                         default:
@@ -471,7 +514,8 @@
                                                         foreach($vals as $tvl) {
                                                                 if(trim($tvl) == trim($k)) $checked = ' CHECKED';
                                                         }
-                                                        $out .= "<label for=\"".$key."[]\" class=\"inlineLabel\"><input name=\"".$key."[]\" id=\"".$key."[]\" value=\"$k\" type=\"checkbox\" $checked /> $v</label>\r\n";
+                                                        // $out .= "<label for=\"".$key."[]\" class=\"inlineLabel\"><input name=\"".$key."[]\" id=\"".$key."[]\" value=\"$k\" type=\"checkbox\" $checked /> $v</label>\r\n";
+														$out .= "<input name=\"".$key."[]\" id=\"".$key."[]\" value=\"$k\" type=\"checkbox\" $checked /> $v &nbsp;\r\n";
                                                 }
                                         }
                                         $new_record[$key] = $out;
@@ -484,10 +528,18 @@
                                                 $out = '';
                                                 foreach($field['value'] as $k => $v) {
                                                         $checked = ($k == $field["default"])?' CHECKED':'';
-                                                        $out .= "<label for=\"".$key."[]\" class=\"inlineLabel\"><input name=\"".$key."[]\" id=\"".$key."[]\" value=\"$k\" type=\"radio\" $checked/> $v</label>\r\n";
+                                                        //$out .= "<label for=\"".$key."[]\" class=\"inlineLabel\"><input name=\"".$key."[]\" id=\"".$key."[]\" value=\"$k\" type=\"radio\" $checked/> $v</label>\r\n";
+														$out .= "<input name=\"".$key."[]\" id=\"".$key."[]\" value=\"$k\" type=\"radio\" $checked/> $v\r\n";
                                                 }
                                         }
                                         $new_record[$key] = $out;
+                                break;
+                                
+                                case 'DATETIME':
+                                        $dt_value = (isset($field['default'])) ? $field['default'] : 0;
+                                        $display_seconds = (isset($field['display_seconds']) && $field['display_seconds'] == true) ? true : false;
+                              
+                                        $new_record[$key] = $this->_getDateTimeHTML($key, $dt_value, $display_seconds);
                                 break;
 
                                 default:
@@ -553,6 +605,18 @@
                                 break;
                                 case 'CURRENCY':
                                         $new_record[$key] = str_replace(",",".",$record[$key]);
+                                break;
+                                
+                                case 'DATETIME':
+                                		if (is_array($record[$key]))
+                                		{
+	                                		$filtered_values = array_map(create_function('$item','return (int)$item;'), $record[$key]);
+                                			extract($filtered_values, EXTR_PREFIX_ALL, '_dt');
+                                			
+                                			if ($_dt_day != 0 && $_dt_month != 0 && $_dt_year != 0) {
+	                                			$new_record[$key] = date( 'Y-m-d H:i:s', mktime($_dt_hour, $_dt_minute, $_dt_second, $_dt_month, $_dt_day, $_dt_year) );
+	                                		}
+                                		}
                                 break;
                                 }
 
@@ -752,8 +816,10 @@
                                                         $sql_insert_key .= "`$key`, ";
                                                         if($field['encryption'] == 'CRYPT') {
                                                                 $salt="$1$";
-																for ($n=0;$n<11;$n++) {
-																	$salt.=chr(mt_rand(64,126));
+																$base64_alphabet='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
+																for ($n=0;$n<8;$n++) {
+																	//$salt.=chr(mt_rand(64,126));
+																	$salt.=$base64_alphabet[mt_rand(0,63)];
 																}
 																$salt.="$";
 																// $salt = substr(md5(time()),0,2);
@@ -785,8 +851,10 @@
                                                 if($field['formtype'] == 'PASSWORD') {
 														if(isset($field['encryption']) && $field['encryption'] == 'CRYPT') {
                                                                 $salt="$1$";
-																for ($n=0;$n<11;$n++) {
-																	$salt.=chr(mt_rand(64,126));
+																$base64_alphabet='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
+																for ($n=0;$n<8;$n++) {
+																	//$salt.=chr(mt_rand(64,126));
+																	$salt.=$base64_alphabet[mt_rand(0,63)];
 																}
 																$salt.="$";
 																// $salt = substr(md5(time()),0,2);
@@ -953,7 +1021,11 @@
 
         function datalogSave($action,$primary_id, $record_old, $record_new) {
                 global $app,$conf;
-
+				
+				$app->db->datalogSave($this->formDef['db_table'], $action, $this->formDef['db_table_idx'], $primary_id, $record_old, $record_new);
+				return true;
+				
+				/*
                 // Add backticks for incomplete table names.
                 if(stristr($this->formDef['db_table'],'.')) {
                         $escape = '';
@@ -962,26 +1034,6 @@
                 }
 
                 $this->diffrec = array();
-				/*
-                if(is_array($record_new) && count($record_new) > 0) {
-                        foreach($record_new as $key => $val) {
-                                if(@$record_old[$key] != $val) {
-										// Record has changed
-                                        $diffrec[$key] = array('old' => @$record_old[$key],
-                                                               'new' => $val);
-                                }
-                        }
-                } elseif(is_array($record_old)) {
-                        foreach($record_old as $key => $val) {
-                                if($record_new[$key] != $val) {
-										// Record has changed
-                                        $diffrec[$key] = array('new' => $record_new[$key],
-                                                               'old' => $val);
-                                }
-                        }
-                }
-				$this->diffrec = $diffrec;
-				*/
 				
 				// Full diff records for ISPConfig, they have a different format then the simple diffrec
 				$diffrec_full = array();
@@ -1034,6 +1086,7 @@
                 }
 
                 return true;
+				*/
 
         }
 
@@ -1144,7 +1197,190 @@
 			}
 			
 		}
+		
+		function checkClientLimit($limit_name,$sql_where = '') {
+			global $app;
+			
+			$check_passed = true;
+			$limit_name = $app->db->quote($limit_name);
+			if($limit_name == '') $app->error('Limit name missing in function checkClientLimit.');
+			
+			// Get the limits of the client that is currently logged in
+			$client_group_id = $_SESSION["s"]["user"]["default_group"];
+			$client = $app->db->queryOneRecord("SELECT $limit_name as number, parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
+			
+			// Check if the user may add another item
+			if($client["number"] >= 0) {
+				$sql = "SELECT count(".$this->formDef['db_table_idx'].") as number FROM ".$this->formDef['db_table']." WHERE ".$this->getAuthSQL('u');
+				if($sql_where != '') $sql .= ' and '.$sql_where;
+				$tmp = $app->db->queryOneRecord($sql);
+				if($tmp["number"] >= $client["number"]) $check_passed = false;
+			}
+			
+			return $check_passed;
+		}
+		
+		function checkResellerLimit($limit_name,$sql_where = '') {
+			global $app;
+			
+			$check_passed = true;
+			$limit_name = $app->db->quote($limit_name);
+			if($limit_name == '') $app->error('Limit name missing in function checkClientLimit.');
+			
+			// Get the limits of the client that is currently logged in
+			$client_group_id = $_SESSION["s"]["user"]["default_group"];
+			$client = $app->db->queryOneRecord("SELECT parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
+			
+			//* If the client belongs to a reseller, we will check against the reseller Limit too
+			if($client['parent_client_id'] != 0) {
+				
+				//* first we need to know the groups of this reseller
+				$tmp = $app->db->queryOneRecord("SELECT userid, groups FROM sys_user WHERE client_id = ".$client['parent_client_id']);
+				$reseller_groups = $tmp["groups"];
+				$reseller_userid = $tmp["userid"];
+				
+				// Get the limits of the reseller of the logged in client
+				$client_group_id = $_SESSION["s"]["user"]["default_group"];
+				$reseller = $app->db->queryOneRecord("SELECT $limit_name as number FROM client WHERE client_id = ".$client['parent_client_id']);
+			
+				// Check if the user may add another item
+				if($reseller["number"] >= 0) {
+					$sql = "SELECT count(".$this->formDef['db_table_idx'].") as number FROM ".$this->formDef['db_table']." WHERE (sys_groupid IN (".$reseller_groups.") or sys_userid = ".$reseller_userid.")";
+					if($sql_where != '') $sql .= ' and '.$sql_where;
+					$tmp = $app->db->queryOneRecord($sql);
+					if($tmp["number"] >= $reseller["number"]) $check_passed = false;
+				}
+			}
+			
+			return $check_passed;
+		}
+		
+		//* get the difference record of two arrays
+		function getDiffRecord($record_old,$record_new) {
+			
+			if(is_array($record_new) && count($record_new) > 0) {
+			foreach($record_new as $key => $val) {
+				if(@$record_old[$key] != $val) {
+					// Record has changed
+					$diffrec[$key] = array(	'old' => @$record_old[$key],
+											'new' => $val);
+					}
+				}
+			} elseif(is_array($record_old)) {
+				foreach($record_old as $key => $val) {
+					if($record_new[$key] != $val) {
+						// Record has changed
+						$diffrec[$key] = array(	'new' => $record_new[$key],
+												'old' => $val);
+						}
+					}
+				}
+			return $diffrec;
+		
+		}
+		
+		/**
+		 * Generate HTML for DATETIME fields.
+		 * 
+		 * @access private
+		 * @param string $form_element Name of the form element.
+		 * @param string $default_value Selected value for fields.
+		 * @param bool $display_secons Include seconds selection.
+		 * @return string HTML	
+		 */
+		function _getDateTimeHTML($form_element, $default_value, $display_seconds=false)
+		{
+			$_datetime = strtotime($default_value);
+			$_showdate = ($_datetime === false) ? false : true;
 
+			$dselect = array('day','month','year','hour','minute');
+            if ($display_seconds === true) {
+			 	$dselect[] = 'second';
+			}
+			 
+			$out = '';
+			 
+			foreach ($dselect as $dt_element)
+			{
+			 	$dt_options = array();
+			 	$dt_space = 1;
+			 	
+			 	switch ($dt_element) {
+			 		case 'day':
+					 	for ($i = 1; $i <= 31; $i++) {
+				            $dt_options[] = array('name' =>  sprintf('%02d', $i),
+				            					  'value' => sprintf('%d', $i));
+				        }
+				        $selected_value = date('d', $_datetime);
+			 			break;
+			 			
+			 		case 'month':
+				 		for ($i = 1; $i <= 12; $i++) {
+				            $dt_options[] = array('name' => strftime('%b', mktime(0, 0, 0, $i, 1, 2000)),
+				            					  'value' => strftime('%m', mktime(0, 0, 0, $i, 1, 2000)));
+				        }
+				        $selected_value = date('n', $_datetime);
+			 			break;
+			 			
+			 		case 'year':
+					 	$start_year = strftime("%Y");
+						$years = range((int)$start_year, (int)($start_year+3));
+				        
+				        foreach ($years as $year) {
+				        	$dt_options[] = array('name' => $year,
+				            					 'value' => $year);
+				        }
+				        $selected_value = date('Y', $_datetime);
+				        $dt_space = 2;
+			 			break;
+			 			
+			 		case 'hour':
+			 			foreach(range(0, 23) as $hour) {
+			 				$dt_options[] = array('name' =>  sprintf('%02d', $hour),
+            			    					  'value' => sprintf('%d', $hour));
+			 			}
+			 			$selected_value = date('G', $_datetime);
+			 			break;
+			 			
+			 		case 'minute':
+			 			foreach(range(0, 59) as $minute) {
+			 				if (($minute % 5) == 0) {
+			 					$dt_options[] = array('name' =>  sprintf('%02d', $minute),
+													  'value' => sprintf('%d', $minute));
+			 				}
+			 			}
+			 			$selected_value = (int)floor(date('i', $_datetime));
+			 			break;
+			 			
+			 		case 'second':	
+			 			foreach(range(0, 59) as $second) {
+			 				$dt_options[] = array('name' =>  sprintf('%02d', $second),
+							      				  'value' => sprintf('%d', $second));
+			 			}
+			 			$selected_value = (int)floor(date('s', $_datetime));
+			 			break;
+			 	}
+					 	
+				$out .= "<select name=\"".$form_element."[$dt_element]\" id=\"".$form_element."_$dt_element\" class=\"selectInput\" style=\"width: auto; float: none;\">";
+				if (!$_showdate) {
+					$out .= "<option value=\"-\" selected=\"selected\">--</option>" . PHP_EOL;
+				} else {
+					$out .= "<option value=\"-\">--</option>" . PHP_EOL;
+				}
+				 
+				foreach ($dt_options as $dt_opt) {
+					if ( $_showdate && ($selected_value == $dt_opt['value']) ) {
+						$out .= "<option value=\"{$dt_opt['value']}\" selected=\"selected\">{$dt_opt['name']}</option>" . PHP_EOL;
+					} else {
+						$out .= "<option value=\"{$dt_opt['value']}\">{$dt_opt['name']}</option>" . PHP_EOL;
+					}
+				}
+												        
+				$out .= '</select>' . str_repeat('&nbsp;', $dt_space);
+			}
+			
+			return $out;
+		}
 }
 
 ?>
\ No newline at end of file

--
Gitblit v1.9.1