This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * |
||
4 | * @package phpBB Extension - Paypal |
||
5 | * @copyright (c) 2015 tas2580 (https://tas2580.net) |
||
6 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
||
7 | * |
||
8 | */ |
||
9 | namespace tas2580\paypal\controller; |
||
10 | |||
11 | use Symfony\Component\HttpFoundation\Response; |
||
12 | |||
13 | class main |
||
14 | { |
||
15 | /** @var \phpbb\config\config */ |
||
16 | protected $config; |
||
17 | |||
18 | /** @var \phpbb\db\driver\driver */ |
||
19 | protected $db; |
||
20 | |||
21 | /** @var \phpbb\controller\helper */ |
||
22 | protected $helper; |
||
23 | |||
24 | /** @var \phpbb\request\request */ |
||
25 | protected $request; |
||
26 | |||
27 | /** @var \phpbb\template\template */ |
||
28 | protected $template; |
||
29 | |||
30 | /** @var \phpbb\user */ |
||
31 | protected $user; |
||
32 | |||
33 | /** |
||
34 | * Constructor |
||
35 | * |
||
36 | * @param \phpbb\config\config $config |
||
37 | * @param \phpbb\controller\helper $helper |
||
38 | * @param \phpbb\template\template $template |
||
39 | * @param \phpbb\user $user |
||
40 | */ |
||
41 | public function __construct(\phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\controller\helper $helper, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user, $table_amount, $table_config, $table_donations, $table_items) |
||
42 | { |
||
43 | $this->config = $config; |
||
44 | $this->db = $db; |
||
45 | $this->helper = $helper; |
||
46 | $this->request = $request; |
||
47 | $this->template = $template; |
||
48 | $this->user = $user; |
||
49 | $this->table_amount = $table_amount; |
||
50 | $this->table_config = $table_config; |
||
51 | $this->table_donations = $table_donations; |
||
52 | $this->table_items = $table_items; |
||
53 | } |
||
54 | /** |
||
55 | * Controller for route /paypal |
||
56 | * |
||
57 | * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object |
||
58 | */ |
||
59 | public function page() |
||
60 | { |
||
61 | $this->user->add_lang_ext('tas2580/paypal', 'common'); |
||
62 | |||
63 | $amount_list = ''; |
||
64 | $sql = 'SELECT * |
||
65 | FROM ' . $this->table_amount . ' |
||
66 | ORDER BY amount_value'; |
||
67 | $result = $this->db->sql_query($sql); |
||
68 | while ($row = $this->db->sql_fetchrow($result)) |
||
69 | { |
||
70 | $amount_list .= '<option value="' . number_format($row['amount_value'] / 100, 2) . '">' . number_format($row['amount_value'] / 100, 2) . '</option>'; |
||
71 | } |
||
72 | |||
73 | $sql = 'SELECT * |
||
74 | FROM ' . $this->table_items . ' |
||
75 | ORDER BY item_name'; |
||
76 | $result = $this->db->sql_query($sql); |
||
77 | while ($row = $this->db->sql_fetchrow($result)) |
||
78 | { |
||
79 | $this->template->assign_block_vars('items', array( |
||
80 | 'ITEM_NAME' => $row['item_name'], |
||
81 | 'ITEM' => generate_text_for_display($row['item_text'], $row['bbcode_uid'], $row['bbcode_bitfield'], 7), |
||
82 | 'ITEM_ID' => $row['item_id'], |
||
83 | )); |
||
84 | } |
||
85 | $sql = 'SELECT * |
||
86 | FROM ' . $this->table_config; |
||
87 | $result = $this->db->sql_query($sql); |
||
88 | $row = $this->db->sql_fetchrow($result); |
||
89 | |||
90 | $this->template->assign_vars(array( |
||
91 | 'PAYPAL_TITLE' => $row['paypal_title'], |
||
92 | 'PAYPAL_TEXT' => generate_text_for_display($row['paypal_text'], $row['bbcode_uid'], $row['bbcode_bitfield'], 7), |
||
93 | 'PAYPAL_EMAIL' => $row['paypal_email'], |
||
94 | 'AMOUNT_LIST' => $amount_list, |
||
95 | 'PAYPAL_ACTION' => ($row['paypal_sandbox'] == 1) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', |
||
96 | 'S_SANDBOX' => ($row['paypal_sandbox'] == 1) ? true : false, |
||
97 | 'S_CURL' => function_exists('curl_init'), |
||
98 | 'CURRENCY_CODE' => $this->currency_code_select($row['paypal_currency']), |
||
99 | 'CURRENCY' => $row['paypal_currency'], |
||
100 | 'USER_ID' => $this->user->data['user_id'], |
||
101 | 'IPN_URL' => $this->helper->route('tas2580_paypal_ipn', array(), true, '', \Symfony\Component\Routing\Generator\UrlGeneratorInterface::ABSOLUTE_URL), |
||
102 | 'RETURN_URL' => $this->helper->route('tas2580_paypal_controller', array(), true, '', \Symfony\Component\Routing\Generator\UrlGeneratorInterface::ABSOLUTE_URL), |
||
103 | )); |
||
104 | return $this->helper->render('paypal_body.html', $row['paypal_title']); |
||
105 | } |
||
106 | |||
107 | |||
108 | /** |
||
109 | * |
||
110 | * https://github.com/paypal/ipn-code-samples/blob/master/paypal_ipn.php |
||
111 | * |
||
112 | * @return boolean |
||
113 | */ |
||
114 | public function ipn() |
||
115 | { |
||
116 | $raw_post_data = file_get_contents('php://input'); |
||
117 | $raw_post_array = explode('&', $raw_post_data); |
||
118 | $myPost = array(); |
||
119 | foreach ($raw_post_array as $keyval) |
||
120 | { |
||
121 | $keyval = explode ('=', $keyval); |
||
122 | if (count($keyval) == 2) |
||
123 | { |
||
124 | $myPost[$keyval[0]] = urldecode($keyval[1]); |
||
125 | } |
||
126 | } |
||
127 | // read the post from PayPal system and add 'cmd' |
||
128 | $req = 'cmd=_notify-validate'; |
||
129 | if (function_exists('get_magic_quotes_gpc')) |
||
130 | { |
||
131 | $get_magic_quotes_exists = true; |
||
132 | } |
||
133 | foreach ($myPost as $key => $value) |
||
134 | { |
||
135 | if ($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) |
||
136 | { |
||
137 | $value = urlencode(stripslashes($value)); |
||
138 | } |
||
139 | else |
||
140 | { |
||
141 | $value = urlencode($value); |
||
142 | } |
||
143 | $req .= "&$key=$value"; |
||
144 | } |
||
145 | |||
146 | $sql = 'SELECT paypal_sandbox |
||
147 | FROM ' . $this->table_config; |
||
148 | $result = $this->db->sql_query($sql); |
||
149 | $row = $this->db->sql_fetchrow($result); |
||
150 | |||
151 | $paypal_url = ($row['paypal_sandbox'] == 1) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr'; |
||
152 | |||
153 | $ch = curl_init($paypal_url); |
||
154 | if ($ch == false) |
||
155 | { |
||
156 | return false; |
||
157 | } |
||
158 | curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
||
159 | curl_setopt($ch, CURLOPT_POST, 1); |
||
160 | curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); |
||
161 | curl_setopt($ch, CURLOPT_POSTFIELDS, $req); |
||
162 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); |
||
163 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); |
||
164 | curl_setopt($ch, CURLOPT_FORBID_REUSE, 1); |
||
165 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); |
||
166 | curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close')); |
||
167 | $res = curl_exec($ch); |
||
168 | curl_close($ch); |
||
169 | |||
170 | // Inspect IPN validation result and act accordingly |
||
171 | // Split response headers and payload, a better way for strcmp |
||
172 | $tokens = explode("\r\n\r\n", trim($res)); |
||
173 | $res = trim(end($tokens)); |
||
174 | if (strcmp($res, 'VERIFIED') == 0) |
||
175 | { |
||
176 | $sql_data = array( |
||
177 | 'user_id' => (int) $this->request->variable('custom', '0'), |
||
178 | 'item_id' => (int) $this->request->variable('item_number', '0'), |
||
179 | 'item_name' => $this->request->variable('item_number', '', true), |
||
180 | 'donation_time' => time(), |
||
181 | 'donation_amount' => $this->request->variable('mc_gross', '0'), |
||
182 | ); |
||
183 | |||
184 | $sql = 'INSERT INTO ' . $this->table_donations . ' |
||
185 | ' . $this->db->sql_build_array('INSERT', $sql_data); |
||
186 | $this->db->sql_query($sql); |
||
187 | } |
||
188 | |||
189 | $headers = array( |
||
190 | 'Content-Type' => 'application/xml; charset=UTF-8', |
||
191 | ); |
||
192 | return new Response('', '200', $headers); |
||
193 | } |
||
194 | |||
195 | private function currency_code_select($sel) |
||
196 | { |
||
197 | $codes = array( |
||
198 | 'AUD' => $this->user->lang('DONATION_AUD'), |
||
199 | 'CAD' => $this->user->lang('DONATION_CAD'), |
||
200 | 'CHF' => $this->user->lang('DONATION_CHF'), |
||
201 | 'CZK' => $this->user->lang('DONATION_CZK'), |
||
202 | 'DKK' => $this->user->lang('DONATION_DKK'), |
||
203 | 'EUR' => $this->user->lang('DONATION_EUR'), |
||
204 | 'GBP' => $this->user->lang('DONATION_GBP'), |
||
205 | 'HKD' => $this->user->lang('DONATION_HKD'), |
||
206 | 'HUF' => $this->user->lang('DONATION_HUF'), |
||
207 | 'ILS' => $this->user->lang('DONATION_ILS'), |
||
208 | 'JPY' => $this->user->lang('DONATION_JPY'), |
||
209 | 'MXN' => $this->user->lang('DONATION_MXN'), |
||
210 | 'NOK' => $this->user->lang('DONATION_NOK'), |
||
211 | 'NZD' => $this->user->lang('DONATION_NZD'), |
||
212 | 'PLN' => $this->user->lang('DONATION_PLN'), |
||
213 | 'SEK' => $this->user->lang('DONATION_SEK'), |
||
214 | 'SGD' => $this->user->lang('DONATION_SGD'), |
||
215 | 'USD' => $this->user->lang('DONATION_USD'), |
||
216 | ); |
||
217 | |||
218 | $retrun = ''; |
||
219 | View Code Duplication | foreach ($codes as $value => $title) |
|
0 ignored issues
–
show
|
|||
220 | { |
||
221 | $selected = ($value == $sel) ? ' selected="selected"' : ''; |
||
222 | $retrun .= '<option value="' . $value . '"' . $selected . '>' . $title . '</option>'; |
||
223 | } |
||
224 | return $retrun; |
||
225 | } |
||
226 | } |
||
227 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.