phpBMS

Changeset 691

Show
Ignore:
Timestamp:
12/30/09 14:17:21 (2 years ago)
Author:
nate
Message:
  • Added additional data check for api get requests.
  • The files's class getRecord no longer loads in the entire binary file into memory when the function is called. The function also returns a field named 'apifileurl' that gives the to get a file via an api login.
  • Added a file that serves a files record's file field using api login credentials posted to it.
Location:
trunk/phpbms/modules
Files:
1 added
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/phpbms/modules/api/include/apiclass.php

    r689 r691  
    598598                            $processor->timeFormat =  $this->options->timeFormat; 
    599599                        }//end if 
    600  
    601                         if(!$this->options->useUuid){ 
     600                         
     601                        $errorMessage = ""; 
     602                        if($this->options->useUuid){ 
     603                            if(!isset($request["data"]["uuid"])) 
     604                                $errorMessage = "The `uuid` field must be set."; 
     605                        }else{ 
     606                            if(!isset($request["data"]["id"])) 
     607                                $errorMessage = "The `id` field must be set."; 
     608                        }//end if 
     609                         
     610                        if($errorMessage) 
     611                            $this->sendError("Update failed from request number ".$i, $errorMessage); 
     612                        elseif(!$this->options->useUuid){ 
    602613                            $therecord = $processor->getRecord((int) $request["data"]["id"], $this->options->useUuid); 
    603614                            $thereturn = $therecord["id"]; 
     
    608619                            $thevalue = $request["data"]["uuid"]; 
    609620                        } 
    610  
    611621 
    612622                        if($thereturn == $thevalue) 
  • trunk/phpbms/modules/base/files_addedit.php

    r587 r691  
    6666 
    6767        function getAttachments($db,$uuid){ 
    68                 $querystatement=" 
     68                $querystatement = " 
    6969                        SELECT 
    7070                                `tabledefs`.`displayname`, 
  • trunk/phpbms/modules/base/include/files.php

    r690 r691  
    5353                        return $file; 
    5454                } 
    55  
    56  
     55                 
     56                 
     57                /** 
     58          * function getDefaults 
     59          * 
     60          * Retrieves default values for a single record 
     61          * 
     62          * Uses the field names to guess a default value.  If it cannot find 
     63          * one of the standard names it sets the default value based on the type 
     64          * 
     65          * @retrun array associative array with record defaults 
     66          */ 
     67        function getDefaults(){ 
     68                         
     69                        $therecord = parent::getDefaults(); 
     70                         
     71                        $therecord["apifileurl"] = ""; 
     72                         
     73                        return $therecord; 
     74                         
     75                }//end function --getDefaults 
     76 
     77 
     78                /** 
     79         * function getRecord 
     80         * 
     81         * Retrieves a single record from the database 
     82         * 
     83         * @param integer|string $id the record id or uuid 
     84         * @param bool $useUuid specifies whther the $id is a uuid (true) or not.  Default is false 
     85         * 
     86         * @return array the record as an associative array 
     87         */ 
     88        function getRecord($id, $useUuid = false){ 
     89                         
     90                        if($useUuid){ 
     91                         
     92                                $id = mysql_real_escape_string($id); 
     93                                $whereclause = "`uuid` = '".$id."'"; 
     94                         
     95                        } else { 
     96                         
     97                                $id = (int) $id; 
     98                                $whereclause = "`id` = ".$id; 
     99                         
     100                        }//endif 
     101                         
     102                        $querystatement = " 
     103                                SELECT 
     104                                        `id`, 
     105                                        `uuid`, 
     106                                        `name`, 
     107                                        `description`, 
     108                                        `type`, 
     109                                        `createdby`, 
     110                                        `creationdate`, 
     111                                        `modifiedby`, 
     112                                        `modifieddate`, 
     113                                        `roleid`, 
     114                                        '' AS `file`, 
     115                                        `custom1`, 
     116                                        `custom2`, 
     117                                        `custom3`, 
     118                                        `custom4`, 
     119                                        `custom5`, 
     120                                        `custom6`, 
     121                                        `custom7`, 
     122                                        `custom8` 
     123                                FROM 
     124                                        `files` 
     125                                WHERE 
     126                                        ".$whereclause; 
     127                                         
     128                        $queryresult = $this->db->query($querystatement); 
     129                                         
     130                        if($this->db->numRows($queryresult)){ 
     131                $therecord = $this->db->fetchArray($queryresult); 
     132                                 
     133                                if(!empty($_SERVER["HTTPS"])) 
     134                                        $protocol = "https://"; 
     135                                else 
     136                                        $protocol = "http://"; 
     137                                         
     138                                 
     139                                if( ($_SERVER["SERVER_PORT"] == "443" && !empty($_SERVER["HTTPS"])) || ($_SERVER["SERVER_PORT"] == "80" && empty($_SERVER["HTTPS"])) ) 
     140                                        $port = ""; 
     141                                else 
     142                                        $port = ":".$_SERVER["SEVER_PORT"]; 
     143                                 
     144                                $therecord["apifileurl"] = $protocol.$_SERVER["SERVER_NAME"].$port.APP_PATH."modules/api/api_servefile.php?i=".(int)$therecord["id"]; 
     145                        }else 
     146                $therecord = $this-> getDefaults(); 
     147                         
     148                        return $therecord; 
     149                         
     150                }//end function --getRecord-- 
     151                 
     152                 
    57153                function verifyVariables($variables){ 
    58154 
phpBMS vulnerability assesment provided by Orvant Inc. Copyright © 2010 Kreotek, LLC. All Rights reserved.