-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdropstock.php
More file actions
182 lines (149 loc) · 4.29 KB
/
Copy pathdropstock.php
File metadata and controls
182 lines (149 loc) · 4.29 KB
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
<?php
/**
* @file
* The PHP page that serves all page requests on a Drupal installation.
*
* The routines here dispatch control to the appropriate handler, which then
* prints the appropriate page.
*
* All Drupal code is released under the GNU General Public License.
* See COPYRIGHT.txt and LICENSE.txt.
*/
header('Content-Type: text/plain; charset=utf-8');
/**
* Root directory of Drupal installation.
*/
$status = 'ok';
try
{
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
// menu_execute_active_handler();
}
catch(Exception $e)
{
$status = 'ko';
}
//identificar el origen de la crida
if(!isset($_REQUEST['dropsite'])){
die('you need to povide a "dropsite"');
}
$site = $_REQUEST['dropsite'];
$exploded_site = explode('|',$site);
$site = $exploded_site[0];
if(!isset($_REQUEST['token'])){
$_REQUEST['token'] = $exploded_site[1];
}
//agafar els tokens de dropstock
$dropstock_token = curl_get($site.'/token',array(),array());
if($dropstock_token){
variable_set('dropstock_token', $dropstock_token);
}
$cypher_token = curl_get($site.'/encrypt-token',array(), array());
if($cypher_token){
variable_set('dropstock_cypher_token', $cypher_token);
}
//comprovar el token
if(!isset($_REQUEST['token'])){
die('No token provided');
}
$provided_token = $_REQUEST['token'];
if(!$dropstock_token){
die("I can't connect to $site/token");
}
if($dropstock_token != $provided_token){
die('tokens mismatch');
}
//els tokens son iguals, continuem.
$info = array(
'name' => '',
'software' => 'Drupal '.VERSION,
'status' => $status,
'modules' => module_list(),
'languages' => language_list(),
'modules_enabled' => system_list('module_enabled'),
);
$var = $info;
if (isset($var)) {
$json = json_encode($var);
$msg_encrypted = encrypt_decrypt('encrypt',$json, $cypher_token);
print $msg_encrypted;
}
print '';
die();
/* FUNCTIONS */
/**
* simple method to encrypt or decrypt a plain text string
* initialization vector(IV) has to be the same when encrypting and decrypting
* PHP 5.4.9
*
* this is a beginners template for simple encryption decryption
* before using this in production environments, please read about encryption
*
* @param string $action: can be 'encrypt' or 'decrypt'
* @param string $string: string to encrypt or decrypt
*
* @return string
*/
function encrypt_decrypt($action, $string, $secret) {
$output = false;
$encrypt_method = "AES-256-CBC";
$secret_key = $secret;
$secret_iv = '1234'; //salt
// hash
$key = substr(hash('sha256', $secret_key), 0, 32);
// iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning
$iv = substr(hash('sha256', $secret_iv), 0, 16);
if( $action == 'encrypt' ) {
$output = encrypt($string, $key);
}
else if( $action == 'decrypt' ){
$output = decrypt($string, $key);
}
return $output;
}
function encrypt($value,$key){
$text = $value;
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, $iv);
return $crypttext;
}
function decrypt($value,$key){
$crypttext = $value;
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$decrypttext = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $crypttext, MCRYPT_MODE_ECB, $iv);
return trim($decrypttext);
}
/**
* Send a GET requst using cURL
* @param string $url to request
* @param array $get values to send
* @param array $options for cURL
* @return string
*/
function curl_get($url, array $get = NULL, array $options = array())
{
if(!function_exists('curl_init')){
$result = file_get_contents($url. (strpos($url, '?') === FALSE ? '?' : ''). http_build_query($get));
}
else{
$defaults = array(
CURLOPT_URL => $url. (strpos($url, '?') === FALSE ? '?' : ''). http_build_query($get),
CURLOPT_HEADER => 0,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_TIMEOUT => 4
);
$ch = curl_init();
curl_setopt_array($ch, ($options + $defaults));
$result = curl_exec($ch) ;
if( !$result )
{
trigger_error(curl_error($ch));
}
curl_close($ch);
}
return $result;
}