1 | <?php |
||
2 | /** |
||
3 | * /classes/DomainMOD/Goal.php |
||
4 | * |
||
5 | * This file is part of DomainMOD, an open source domain and internet asset manager. |
||
6 | * Copyright (c) 2010-2018 Greg Chetcuti <[email protected]> |
||
7 | * |
||
8 | * Project: http://domainmod.org Author: http://chetcuti.com |
||
9 | * |
||
10 | * DomainMOD is free software: you can redistribute it and/or modify it under the terms of the GNU General Public |
||
11 | * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later |
||
12 | * version. |
||
13 | * |
||
14 | * DomainMOD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
||
15 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
||
16 | * |
||
17 | * You should have received a copy of the GNU General Public License along with DomainMOD. If not, see |
||
18 | * http://www.gnu.org/licenses/. |
||
19 | * |
||
20 | */ |
||
21 | //@formatter:off |
||
22 | namespace DomainMOD; |
||
23 | |||
24 | class Goal |
||
25 | { |
||
26 | public $deeb; |
||
27 | public $time; |
||
28 | |||
29 | public function __construct() |
||
30 | { |
||
31 | $this->deeb = Database::getInstance(); |
||
32 | $this->time = new Time(); |
||
33 | } |
||
34 | |||
35 | public function installation() |
||
36 | { |
||
37 | $pdo = $this->deeb->cnxx; |
||
38 | |||
39 | $act_software_version = SOFTWARE_VERSION; |
||
40 | $act_ip_address = $this->getIp(); |
||
41 | $act_agent = $_SERVER['HTTP_USER_AGENT']; |
||
42 | $act_language = $_SERVER['HTTP_ACCEPT_LANGUAGE']; |
||
43 | |||
44 | $stmt = $pdo->prepare(" |
||
45 | INSERT INTO goal_activity |
||
46 | (type, old_version, new_version, ip, agent, `language`, insert_time) |
||
47 | VALUES |
||
48 | ('i', 'n/a', :act_software_version, :act_ip_address, :act_agent, :act_language, :insert_time)"); |
||
49 | $stmt->bindValue('act_software_version', $act_software_version, \PDO::PARAM_STR); |
||
50 | $stmt->bindValue('act_ip_address', $act_ip_address, \PDO::PARAM_STR); |
||
51 | $stmt->bindValue('act_agent', $act_agent, \PDO::PARAM_LOB); |
||
52 | $stmt->bindValue('act_language', $act_language, \PDO::PARAM_STR); |
||
53 | $bind_timestamp = $this->time->stamp(); |
||
54 | $stmt->bindValue('insert_time', $bind_timestamp, \PDO::PARAM_STR); |
||
55 | $stmt->execute(); |
||
56 | } |
||
57 | |||
58 | public function upgrade($act_old_version) |
||
59 | { |
||
60 | $pdo = $this->deeb->cnxx; |
||
61 | |||
62 | $act_new_version = SOFTWARE_VERSION; |
||
63 | $act_ip_address = $this->getIp(); |
||
64 | $act_agent = $_SERVER['HTTP_USER_AGENT']; |
||
65 | $act_language = $_SERVER['HTTP_ACCEPT_LANGUAGE']; |
||
66 | |||
67 | $stmt = $pdo->prepare(" |
||
68 | INSERT INTO goal_activity |
||
69 | (type, old_version, new_version, ip, agent, `language`, insert_time) |
||
70 | VALUES |
||
71 | ('u', :act_old_version, :act_new_version, :act_ip_address, :act_agent, :act_language, :insert_time)"); |
||
72 | $stmt->bindValue('act_old_version', $act_old_version, \PDO::PARAM_STR); |
||
73 | $stmt->bindValue('act_new_version', $act_new_version, \PDO::PARAM_STR); |
||
74 | $stmt->bindValue('act_ip_address', $act_ip_address, \PDO::PARAM_STR); |
||
75 | $stmt->bindValue('act_agent', $act_agent, \PDO::PARAM_LOB); |
||
76 | $stmt->bindValue('act_language', $act_language, \PDO::PARAM_STR); |
||
77 | $bind_timestamp = $this->time->stamp(); |
||
78 | $stmt->bindValue('insert_time', $bind_timestamp, \PDO::PARAM_STR); |
||
79 | $stmt->execute(); |
||
80 | } |
||
81 | |||
82 | public function remote() |
||
83 | { |
||
84 | $pdo = $this->deeb->cnxx; |
||
85 | |||
86 | $result = $pdo->query(" |
||
87 | SELECT id, type, old_version, new_version, ip, agent, `language`, insert_time |
||
88 | FROM goal_activity |
||
89 | WHERE new_activity = '1' |
||
90 | ORDER BY id ASC")->fetchAll(); |
||
91 | |||
92 | if ($result) { |
||
0 ignored issues
–
show
|
|||
93 | |||
94 | $stmt = $pdo->prepare(" |
||
95 | UPDATE goal_activity |
||
96 | SET new_activity = '0', |
||
97 | update_time = :timestamp |
||
98 | WHERE id = :id"); |
||
99 | $bind_timestamp = $this->time->stamp(); |
||
100 | $stmt->bindValue('timestamp', $bind_timestamp, \PDO::PARAM_STR); |
||
101 | $stmt->bindParam('id', $bind_id, \PDO::PARAM_INT); |
||
102 | |||
103 | foreach ($result as $row) { |
||
104 | |||
105 | $bind_id = $row->id; |
||
106 | $stmt->execute(); |
||
107 | |||
108 | $base_url = $this->getBaseUrl($row->type, $row->old_version, $row->new_version); |
||
109 | $goal_url = $base_url . '&ip=' . urlencode($row->ip) . '&a=' . urlencode($row->agent) . '&l=' . |
||
110 | urlencode($row->language) . '&ti=' . urlencode($row->insert_time) . '&tu=' . |
||
111 | urlencode($this->time->stamp()); |
||
112 | $this->triggerGoal($goal_url); |
||
113 | |||
114 | } |
||
115 | |||
116 | } |
||
117 | } |
||
118 | |||
119 | public function getBaseUrl($goal, $old_version, $new_version) |
||
120 | { |
||
121 | if ($goal == 'i') { // install |
||
122 | return 'https://domainmod.org/installed/index.php?v=' . urlencode($new_version); |
||
123 | } else { // upgrade |
||
124 | return 'https://domainmod.org/upgraded/index.php?ov=' . urlencode($old_version) . '&nv=' . |
||
125 | urlencode($new_version); |
||
126 | } |
||
127 | } |
||
128 | |||
129 | public function getIp() |
||
130 | { |
||
131 | if ($_SERVER['SERVER_ADDR'] == '127.0.0.1' || $_SERVER['SERVER_ADDR'] == '::1') { |
||
132 | return $_SERVER['REMOTE_ADDR']; |
||
133 | } else { |
||
134 | return $_SERVER['SERVER_ADDR']; |
||
135 | } |
||
136 | } |
||
137 | |||
138 | public function triggerGoal($goal_url) |
||
139 | { |
||
140 | $system = new System(); |
||
141 | $system->getFileContents('Log Goal', 'error', $goal_url); |
||
142 | } |
||
143 | |||
144 | } //@formatter:on |
||
145 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.