-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgis_reg_process.php
executable file
·409 lines (308 loc) · 12.6 KB
/
gis_reg_process.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
<?php
//update for epxa endpoint
//podio library
include_once '/lib/podio-php-4.3.0/PodioAPI.php';
//get Response library
require_once '/home/webmaster/wp-config-files/GetResponseAPI3.class.php';
require '/home/webmaster/wp-config-files/vendor/google/recaptcha/src/autoload.php';
require '/home/webmaster/wp-config-files/gis_lib/vendor/autoload.php';
//private keys config files
$configs_external = include('/home/webmaster/wp-config-files/wp_login_config.php');
//plugin configs
$configs = include('config.php');
#default is gv for hte campaing in get response
$gr_campaing_id = $configs_external['gr_campaign_ogv_id'];
//captcah verification
////captcah verification
/////captcah verification
/////captcah verification
$recaptcha = new \ReCaptcha\ReCaptcha($configs_external['recaptcha_secret']);
$resp = $recaptcha->verify($_POST['g-recaptcha-response'], get_client_ip());
if (!$resp->isSuccess()) {
$errors = $resp->getErrorCodes();
header("Location: http://aiesec.org.mx/registro_no");
return;
}
//captcah verification
////captcah verification
/////captcah verification
/////captcah verification
/**
* AIESEC GIS Form Submission via cURL
*
* This is a basic form processor to create new users for the Opportunities Portal
* so you can create and manage a registration form on your country website.
*
*
*/
// UNCOMMENT HERE: to view the HTML form requested from the GIS
//print $result;
$curl = curl_init();
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://auth.aiesec.org/users/sign_in',
CURLOPT_USERAGENT => 'Codular Sample cURL Request'
));
// Send the request & save response to $resp
$result = curl_exec($curl);
// Close request to clear up some resources
curl_close($curl);
// extract token from cURL result
preg_match('/<meta content="(.*)" name="csrf-token" \/>/', $result, $matches);
$gis_token = $matches[1];
// UNCOMMENT HERE: to view HTTP status and errors from curl
// curl_errors($ch1);
//close connection
curl_close($ch1);
// map LC name -> GIS ID
// we use javascript to map uni<->LC, so the first step is already taken care of
$lc_json = 'lc_id.json';
$json = file_get_contents($lc_json, false, stream_context_create($arrContextOptions));
$lc_gis_map = json_decode($json,true);
$user_lc = $lc_gis_map[$_POST['localcommittee']];
$program = intval($_POST['interested_in']);
// structure data for GIS
// form structure taken from actual form submission at auth.aiesec.org/user/sign_in
/*
$fields = array(
'authenticity_token' => htmlspecialchars($gis_token),
'user[email]' => htmlspecialchars($_POST['email']),
'user[first_name]' => htmlspecialchars($_POST['first_name']),
'user[last_name]' => htmlspecialchars($_POST['last_name']),
'user[password]' => htmlspecialchars($_POST['password']),
'user[phone]' => htmlspecialchars($_POST['phone']),
'user[country]' => $configs["country_name"], //'POLAND', // EXAMPLE: 'GERMANY'
'user[mc]' => $configs["mc_id"], //'1626', // EXAMPLE: 1596
'user[lc_input]' => $user_lc,
'user[lc]' => $user_lc,
'commit' => 'REGISTER'
);*/
$fields = array( 'user'=>array(
'email' => htmlspecialchars($_POST['email']),
'first_name' => htmlspecialchars($_POST['first_name']),
'last_name' => htmlspecialchars($_POST['last_name']),
'password' => htmlspecialchars($_POST['password']),
'phone' => htmlspecialchars($_POST['phone']),
'lc' => $user_lc,
'country_code' => '+52'
)
);
// UNCOMMENT HERE: to view the array which will be submitted to GIS
// echo "<h2>Text going to GIS</h2>";
// echo '<pre>';
// print_r($fields);
// echo "</pre>";
//url-ify the data for the POST
$fields_string = "";
foreach($fields as $key=>$value) { $fields_string .= $key.'='.urlencode($value).'&'; }
rtrim($fields_string, '&');
$innerHTML = "";
// UNCOMMENT THIS BLOCK: to enable real GIS form submission
$fieldsjs = json_encode($fields);
// POST form with curl
$url = "https://auth.aiesec.org/users.json";
$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL, $url);
curl_setopt($ch2, CURLOPT_POST, count($fieldsjs));
curl_setopt($ch2, CURLOPT_POSTFIELDS, $fieldsjs);
curl_setopt($ch2, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json')
);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, TRUE);
// give cURL the SSL Cert for Salesforce
curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, false); // TODO: FIX SSL - VERIFYPEER must be set to true
//
// "without peer certificate verification, the server could use any certificate,
// including a self-signed one that was guaranteed to have a CN that matched
// the server’s host name."
// http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/
//
// curl_setopt($ch2, CURLOPT_SSL_VERIFYHOST, 2);
// curl_setopt($ch2, CURLOPT_CAINFO, getcwd() . "\CACerts\VeriSignClass3PublicPrimaryCertificationAuthority-G5.crt");
$result = curl_exec($ch2);
$ep_id = json_decode($result,true)['person_id'];
curl_errors($ch2);
// Check if any error occurred
if (curl_errno($ch2)) {
header("Location: http://aiesec.org.mx/registro_no");
return;
}
curl_close($ch2);
libxml_use_internal_errors(true);
$doc = new DOMDocument();
$doc->loadHTML($result);
libxml_clear_errors();
$selector = new DOMXPath($doc);
$result = $selector->query('//div[@id="error_explanation"]');
$children = $result->item(0)->childNodes;
if (is_iterable($children))
{
foreach ($children as $child) {
$tmp_doc = new DOMDocument();
$tmp_doc->appendChild($tmp_doc->importNode($child,true));
$innerHTML .= strip_tags($tmp_doc->saveHTML());
//$innerHTML.add($tmp_doc->saveHTML());
}
}
$innerHTML = preg_replace('~[\r\n]+~', '', $innerHTML);
$innerHTML = str_replace(array('"', "'"), '', $innerHTML);
///////////PODIO Start /////////
///////////PODIO Start /////////
///////////PODIO Start /////////
///////////PODIO Start /////////
///////////PODIO Start /////////
//Podio submit
// This is to test the conection with the podio API and the authentication
Podio::setup('aiesec-mexico', $configs_external['podio_key']);
//getting the podio Id for each lc
$lc_podio = 'lc_podio.json';
$json_podio_lc = file_get_contents($lc_podio, false, stream_context_create($arrContextOptions));
$lc_podio_map = json_decode($json_podio_lc,true);
$user_lc_podio = $lc_podio_map[$_POST['localcommittee']];
//getting the podio Id for each lc
$uni_podio = 'universidades_podio_state.json';
//since we had too many insittues we change the podio field that we submit of it depending on the lc
$intitute_name = "instituto-estado";
//The lcs that are citi/university based : Chihuahua, CDMX, GTO, NL
$os = array(27,22,5,8,15,17,18,26,23,25,29,30,21,6,12,1,16);
if (in_array(intval($user_lc_podio), $os)){
$intitute_name = "instituto";
$uni_podio = 'universidades_podio.json';
}
$json_podio_uni = file_get_contents($uni_podio, false, stream_context_create($arrContextOptions));
$uni_podio_map = json_decode($json_podio_uni,true);
$user_uni_podio = $uni_podio_map[$_POST['university']];
//echo strval($user_uni_podio).' fue el que eligio y el comite era '.$_POST['university'].'<br>';
$podio_id = intval($configs_external['podio_space_ogv_id']);
try {
//OGV
if ($program == 1){
Podio::authenticate_with_app(intval($configs_external['podio_space_ogv_id']),$configs_external['podio_space_ogv_key']);
$podio_id = intval($configs_external['podio_space_ogv_id']);
$gr_campaing_id = $configs_external['gr_campaign_ogv_id'] ;
}
//OGT
else if ($program == 2){
Podio::authenticate_with_app(intval($configs_external['podio_space_ogt_id']),$configs_external['podio_space_ogt_key']);
$podio_id = intval($configs_external['podio_space_ogt_id']);
$gr_campaing_id = $configs_external['gr_campaign_ogt_id'];
}
//OGE
else {
Podio::authenticate_with_app(intval($configs_external['podio_space_oge_id']), $configs_external['podio_space_oge_key']);
$podio_id = intval($configs_external['podio_space_oge_id']);
$gr_campaing_id = $configs_external['gr_campaign_oge_id'];
}
$fields = new PodioItemFieldCollection(array(
new PodioTextItemField(array("external_id" => "titulo", "values" => ($_POST['first_name'] ) )),
new PodioTextItemField(array("external_id" => "apellido", "values" => $_POST['last_name'])),
new PodioTextItemField(array("external_id" => "correo", "values" => $_POST['email'])),
new PodioTextItemField(array("external_id" => "numero-telefonico", "values" => $_POST['phone'])),
new PodioCategoryItemField(array("external_id" => "comite-local", "values" => intval($user_lc_podio))),
new PodioCategoryItemField(array("external_id" => $intitute_name, "values" => intval($user_uni_podio))),
new PodioCategoryItemField(array("external_id" => "fuente", "values" => intval($_POST['source'])))
));
// Create the item object with fields
// Be sure to add an app or podio-php won't know where to create the item
$item = new PodioItem(array(
'app' => new PodioApp($podio_id), // Attach to app with app_id=123
'fields' => $fields
));
// Save the new item
$item->save();
}
catch (PodioError $e) {
// Something went wrong. Examine $e->body['error_description'] for a description of the error.
header("Location: http://aiesec.org.mx/registro_no");
}
////////PODIO END /////////
////////PODIO END /////////
////////PODIO END /////////
////////PODIO END /////////
////////PODIO END /////////
////////PODIO END /////////
function is_iterable($var)
{
return $var !== null
&& (is_array($var)
|| $var instanceof Traversable
|| $var instanceof Iterator
|| $var instanceof IteratorAggregate
);
}
function get_client_ip() {
$ipaddress = '';
if (getenv('HTTP_CLIENT_IP'))
$ipaddress = getenv('HTTP_CLIENT_IP');
else if(getenv('HTTP_X_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_X_FORWARDED_FOR');
else if(getenv('HTTP_X_FORWARDED'))
$ipaddress = getenv('HTTP_X_FORWARDED');
else if(getenv('HTTP_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_FORWARDED_FOR');
else if(getenv('HTTP_FORWARDED'))
$ipaddress = getenv('HTTP_FORWARDED');
else if(getenv('REMOTE_ADDR'))
$ipaddress = getenv('REMOTE_ADDR');
else
$ipaddress = 'UNKNOWN';
return $ipaddress;
}
////////////////GET RESPONSE
///////////////////GET RESPONSE
///////////////////GET RESPONSE
///////////////////GET RESPONSE
///////////////////GET RESPONSE
////////////////GET RESPONSE
$getresponse = new GetResponse($configs_external['gr_id']);
$getresponse->enterprise_domain =$configs_external['gr_api_domain'];
$getresponse->api_url = $configs_external['gp_api_url']; //
$gr_data = array(
'name' => $_POST['first_name'].' '.$_POST['last_name'],
'email' => $_POST['email'],
'dayOfCycle' => 0,
'campaign' => array(
'campaignId' => ($gr_campaing_id)),
'ipAddress' => get_client_ip(),
'customFieldValues' => array(
array('customFieldId' => 'zU3k6', //universidad
'value' => array(
$_POST['university']
)),
array('customFieldId' => 'zU3vv', //expa_id
'value' => array(
strval($ep_id)
)
),
array('customFieldId' => 'zU3kZ', //telefono
'value' => array(
'+52'.$_POST['phone']
)
),
array('customFieldId' => 'zU3kb', //nombre
'value' => array(
$_POST['first_name']
)
),
array('customFieldId' => 'zU3vI', //apellido
'value' => array(
$_POST['last_name']
)
),
array('customFieldId' => 'zU3kg', //comite
'value' => array(
$_POST['localcommittee']
)
)
)
);
$getresponse->addContact($gr_data);
////////////////getresponse ////////////////////////
header("Location: http://aiesec.org.mx/registro/?thank_you=true");
function curl_errors($ch)
{
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curl_errno= curl_errno($ch);
}
?>