phpBMS

root/trunk/phpbms/modules/base/adminsettings_ajax.php

Revision 727, 3.0 KB (checked in by brieb, 2 years ago)
  • Added more rights look ups to certain pages
  • Fixed several path disclosure errors
Line 
1<?php
2
3class checkUpdate {
4
5    /**
6     * function checkUpdate
7     * @param object $db database object
8     */
9
10    function checkUpdate($db) {
11        $this->db = $db;
12    }//end method
13
14    /**
15     * function needUpdateCheck
16     * @param $manual Whether the check was instigated manually or automatically.
17     * @return boolean Whether or not to perform an update.
18     */
19
20    function needUpdateCheck($manual) {
21
22        if(!$manual){
23
24            $querystatement = "
25                SELECT
26                    IF((NOW() >= date_add(`value`, INTERVAL 1 DAY)) OR `value` = '' OR `value` IS NULL,1,0) AS `doautocheck`
27                FROM
28                    `settings`
29                WHERE
30                    `name` = 'last_update_check'
31            ";
32
33            $queryresult = $this->db->query($querystatement);
34
35            $dateCheck = $this->db->fetchArray($queryresult);
36
37            if((int)$dateCheck["doautocheck"] == 0)
38                return false;
39            else
40                return true;
41
42        }else
43            return true;
44
45    }//end function
46
47
48    /**
49     * function checkForUpdate
50     *
51     * @return string A json formated response string.
52     */
53
54    function checkForUpdate() {
55
56        $querystatement = "
57            SELECT
58                `version`,
59                NOW() AS `date`
60            FROM
61                `modules`
62            WHERE
63                `uuid`='mod:29873ee8-c12a-e3f6-9010-4cd24174ffd7'
64        ";
65
66        $queryresult = $this->db->query($querystatement);
67
68        $moduleRecord = $this->db->fetchArray($queryresult);
69
70        $url = "http://kreotek.com/foo.php?v=".htmlspecialchars($moduleRecord["version"]);
71
72        $res = fopen($url,"r");
73        if($res !== false){
74            $response = stream_get_contents($res);
75            fclose($res);
76        }//end if
77
78        $response = json_decode($response);
79        $response->date = $moduleRecord["date"];
80        $response->checked = true;
81
82        $querystatement = "
83            UPDATE
84                `settings`
85            SET
86                `value` = '".mysql_real_escape_string($moduleRecord["date"])."'
87            WHERE
88                `name` = 'last_update_check'
89        ";
90
91        $this->db->query($querystatement);
92
93        $response = json_encode($response);
94        return $response;
95
96    }//end function
97
98}//end class
99
100
101/**
102 * Processing ==================================================================
103 */
104if(!isset($noOutput)){
105
106    require_once("../../include/session.php");
107
108    $db->errorFormat = "json";
109
110    if(!isset($_GET["m"]))
111        $error = new appError(200, "invalid passed paramaters", "", true, true, "json");
112
113    if(!$_SESSION["userinfo"]["admin"])
114        $error = new appError(970, "no rights to function", "", true, true, "json");
115
116    $checkUpdate = new checkUpdate($db);
117    $response = array();
118
119    if($checkUpdate->needUpdateCheck($_GET["m"]))
120        $response = $checkUpdate->checkForUpdate();
121    else{
122        $response["checked"] = false;
123        $response = json_encode($response);
124    }//end if
125
126    echo $response;
127
128}//endif
129?>
Note: See TracBrowser for help on using the browser.
phpBMS vulnerability assesment provided by Orvant Inc. Copyright © 2010 Kreotek, LLC. All Rights reserved.