phpBMS

Changeset 720 for trunk/phpbms

Show
Ignore:
Timestamp:
01/06/10 17:04:26 (2 years ago)
Author:
brieb
Message:
  • fixed checkunique breaking with uuids and possible SQL injection
  • fixed backslashes in searches
  • fixed mark_as in invoice search commands incorrectly setting value to string 'NULL'
Location:
trunk/phpbms
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/phpbms/checkunique.php

    r702 r720  
    3737 +-------------------------------------------------------------------------+ 
    3838*/ 
    39         require ("include/session.php"); 
    4039 
    41         function isUnique($tablename,$column,$value,$excludeid,$db){ 
    42                  
    43                 $thereturn=false; 
    44                  
    45                 $querystatement="SELECT count(id) AS thecount FROM ".$tablename." WHERE ".$column."=\"".$value."\" AND id!=".$excludeid; 
    46                 $queryresult=$db->query($querystatement); 
    47                 if($queryresult){ 
    48                         $therecord=$db->fetchArray($queryresult); 
    49                         if($therecord["thecount"]==0) 
    50                                 $thereturn=true; 
    51                 } 
    52                  
    53                 return $thereturn; 
    54         } 
    55          
    56          
    57         $isunique=false; 
    58          
    59         if(isset($_GET["tdid"]) && isset($_GET["c"]) && isset($_GET["val"]) && isset($_GET["xid"])) { 
    60                 $_GET["tdid"]=((int) $_GET["tdid"]); 
    61                 $_GET["xid"]=((int) $_GET["xid"]); 
    62                  
    63                 $querystatement="SELECT maintable FROM tabledefs WHERE id=".$_GET["tdid"]; 
    64                 $queryresult=$db->query($querystatement); 
    65                 if($queryresult) 
    66                         if($therecord=$db->fetchArray($queryresult)) 
    67                                 $isunique=isUnique($therecord["maintable"],$_GET["c"],$_GET["val"],$_GET["xid"],$db);            
    68         } 
    69          
    70         header('Content-Type: text/xml'); 
    71         echo '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>'; 
    72 ?> 
    73 <response> 
    74   <isunique><?php echo ((int) $isunique) ?></isunique> 
    75 </response> 
     40 
     41class uniqueChecker{ 
     42 
     43    var $db; 
     44 
     45    function uniqueChecker($db){ 
     46 
     47        $this->db = $db; 
     48        $this->db->errorFormat = "json"; 
     49 
     50    }//end function init 
     51 
     52 
     53    function check($tabledefuuid, $columname, $value, $excludeid = NULL){ 
     54 
     55        $querystatement = " 
     56            SELECT 
     57                `maintable` 
     58            FROM 
     59                `tabledefs` 
     60            WHERE 
     61                `uuid` = '".mysql_real_escape_string($tabledefuuid)."'"; 
     62 
     63        $queryresult = $this->db->query($querystatement); 
     64 
     65        if($this->db->numRows($queryresult) === 0) 
     66            return "error"; 
     67 
     68        $therecord = $this->db->fetchArray($queryresult); 
     69 
     70        $table = $therecord["maintable"]; 
     71 
     72        $columname = mysql_real_escape_string(str_replace("`","", $columname)); 
     73        $value = mysql_real_escape_string($value); 
     74 
     75        $querystatement = " 
     76            SELECT 
     77                count(id) AS thecount 
     78            FROM 
     79                `".$table."` 
     80            WHERE 
     81                `".$columname."` = '".$value."'"; 
     82 
     83        if($excludeid){ 
     84 
     85            $querystatement .= " AND `uuid` != '".mysql_real_escape_string($excludeid)."'"; 
     86 
     87        }//endif 
     88 
     89        $queryresult = $this->db->query($querystatement); 
     90 
     91        $therecord = $this->db->fetchArray($queryresult); 
     92 
     93        return ($therecord["thecount"] == 0); 
     94 
     95    }//end function check 
     96 
     97}//end class 
     98 
     99 
     100/** 
     101 * PROCESSING ================================================================== 
     102 */ 
     103if(!isset($noOutput)){ 
     104 
     105    require_once("include/session.php"); 
     106 
     107    if(!isset($_GET["tduuid"]) || !isset($_GET["cname"]) || !isset($_GET["value"])) 
     108        $error = new appError(200, "passed parameters not set"); 
     109 
     110    if(!isset($_GET["xuuid"])) 
     111        $_GET["xuuid"] = ""; 
     112 
     113    $checker = new uniqueChecker($db); 
     114 
     115    echo json_encode($checker->check($_GET["tduuid"], $_GET["cname"], $_GET["value"], $_GET["xuuid"])); 
     116 
     117}//endif 
  • trunk/phpbms/common/javascript/fields.js

    r703 r720  
    237237} 
    238238 
    239 function checkUnique(tabledefid,column,checkvalue,excludeid){ 
    240  
    241         var theurl=APP_PATH+"checkunique.php?tdid="+parseInt(tabledefid); 
    242         theurl=theurl+"&c="+encodeURIComponent(column); 
    243         theurl=theurl+"&val="+encodeURIComponent(checkvalue); 
    244         theurl=theurl+"&xid="+parseInt(excludeid); 
    245  
     239function checkUnique(tabledefuuid , columnName, value, excludeuuid){ 
     240 
     241        var theurl= APP_PATH + "checkunique.php?tduuid=" + encodeURIComponent(tabledefuuid); 
     242 
     243        theurl=theurl+"&cname="+encodeURIComponent(columnName); 
     244        theurl=theurl+"&value="+encodeURIComponent(value); 
     245        theurl=theurl+"&xuuid="+encodeURIComponent(excludeuuid); 
    246246 
    247247        loadXMLDoc(theurl,null,false); 
    248248 
    249         response = req.responseXML.documentElement; 
    250         thevalue = response.getElementsByTagName('isunique')[0].firstChild.data; 
    251  
    252         if(thevalue==1) return true; else return false; 
    253 } 
     249        var isUnique = false; 
     250 
     251        try { 
     252 
     253            isUnique = eval("(" + req.responseText + ")") 
     254 
     255        } catch(err) { 
     256 
     257            isUnique = false; 
     258 
     259        } 
     260 
     261        return isUnique; 
     262 
     263} 
  • trunk/phpbms/include/search_class.php

    r711 r720  
    671671 
    672672                <label for="startswith">starts with</label><br /> 
    673                 <input id="startswith" name="startswith" type="text"  value="<?php if($this->querytype=="search" and isset($this->savedstartswith)) echo formatVariable($this->savedstartswith) ?>" size="35" maxlength="128" tabindex="1"/> 
     673                <input id="startswith" name="startswith" type="text"  value="<?php if($this->querytype=="search" and isset($this->savedstartswith)) echo formatVariable(stripslashes(stripslashes($this->savedstartswith))) ?>" size="35" maxlength="128" tabindex="1"/> 
    674674 
    675675            </p> 
  • trunk/phpbms/modules/bms/include/invoices.php

    r703 r720  
    816816                                }//end if 
    817817 
    818                                 if(!in_array(((string)$variables["assignedtoid"]),$this->_availableUserUUIDs)) 
     818                                if(!in_array(((string)$variables["assignedtoid"]), $this->_availableUserUUIDs)) 
    819819                                        $this->verifyErrors[] = "The `assignedtoid` field does not give an existing/acceptable user id number."; 
    820820 
     
    15561556 
    15571557                                if($therecord["defaultassignedtoid"]!="") 
    1558                                         $assignedtoid = $therecord["defaultassignedtoid"]; 
     1558                                        $assignedtoid = "'".$therecord["defaultassignedtoid"]."'"; 
    15591559                                else 
    15601560                                        $assignedtoid="NULL"; 
     
    15951595                                        SET 
    15961596                                                invoices.statusdate=NOW(), 
    1597                                                 assignedtoid='".$assignedtoid."', 
     1597                                                assignedtoid=".$assignedtoid.", 
    15981598                                                modifiedby=".$_SESSION["userinfo"]["id"].", "; 
    15991599 
     
    16271627                                $querystatement="INSERT INTO invoicestatushistory (invoiceid,invoicestatusid,statusdate,assignedtoid) values ("; 
    16281628                                $querystatement.="'".$therecord["uuid"]."','".$statusid."',NOW(),"; 
    1629                                 $querystatement.="'".$assignedtoid."'"; 
     1629                                $querystatement.= $assignedtoid; 
    16301630                                $querystatement.=")"; 
    16311631                                $insertresult = $this->db->query($querystatement); 
  • trunk/phpbms/modules/bms/javascript/product.js

    r703 r720  
    8181 
    8282        var partnumber = getObjectFromID("partnumber"); 
    83         var excludeid = getObjectFromID("id"); 
    84  
    85         if(!checkUnique(4, "partnumber", partnumber.value, parseInt(excludeid.value))){ 
     83        var excludeid = getObjectFromID("uuid"); 
     84 
     85        if(!checkUnique('tbld:7a9e87ed-d165-c4a4-d9b9-0a4adc3c5a34', "partnumber", partnumber.value, excludeid.value)){ 
    8686 
    8787            alert("Part number must be unique."); 
  • trunk/phpbms/search.php

    r702 r720  
    4949        //initialize the object 
    5050        $displayTable->initialize($_GET["id"]); 
    51          
    52         if (isset($passedjoinclause)) $_SESSION["passedjoinclause"] = $passedjoinclause;  
    53         if (isset($passedjoinwhere)) $_SESSION["passedjoinwhere"] = $passedjoinwhere;  
     51 
     52        if (isset($passedjoinclause)) $_SESSION["passedjoinclause"] = $passedjoinclause; 
     53        if (isset($passedjoinwhere)) $_SESSION["passedjoinwhere"] = $passedjoinwhere; 
    5454 
    5555 
     
    121121 
    122122                        }//endif 
    123                          
     123 
    124124                        /** 
    125                           *  If the command is a push command, include tables.php  
     125                          *  If the command is a push command, include tables.php 
    126126                          */ 
    127127                        if(strpos($functionname, ":") !== false) 
    128128                                include("include/tables.php"); 
    129                          
     129 
    130130                        //try to include table specific functions 
    131131                        if(file_exists("modules/".$displayTable->thetabledef["name"]."/include/".$displayTable->thetabledef["maintable"].".php")) 
     
    142142 
    143143                        if(!preg_match("/\:/", $functionname)){ 
    144                                  
     144 
    145145                                if(method_exists($searchFunctions,$functionname)) 
    146146                                        $statusmessage = $searchFunctions->$functionname(); 
    147147                                else 
    148148                                        $statusmessage = "Function ".$functionname." not defined"; 
    149                                          
     149 
    150150                        }else{ 
    151                                  
     151 
    152152                                if(moduleExists("mod:b2d42220-443b-fe74-dbdb-ed2c0968c38c", $phpbms->modules)) 
    153153                                        $statusmessage = $searchFunctions->runPush($therecord["name"]); 
    154                                  
     154 
    155155                        }//end if 
    156156                        break; 
phpBMS vulnerability assesment provided by Orvant Inc. Copyright © 2010 Kreotek, LLC. All Rights reserved.