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
|
<?php
/**
*
* Class ki skrbi za prenos domene www.1ka.si na oneclicksurvey.com oz. enklikanketa.si
*
*/
class DomainChange{
private static $instance = false;
private $usr_id;
private $user_switch_status; // Status preklopa uporabnika (0 - ni preklopil, 1 - je zavrnil preklop in ostal na 1ka.si, 2 - je preklopil na oneclick)
public static $domain_original = 'www.1ka.si';
//public static $domain_original = 'localhost';
public static $domain_new = 'www.oneclicksurvey.com';
//public static $domain_new = 'localhost';
public static function getInstance($usr_id){
if (!self::$instance)
self::$instance = new DomainChange($usr_id);
return self::$instance;
}
private function __construct($usr_id){
// Ce nimamo usr_id-ja ga poskusimo pridobiti iz id-ja ankete
if(!isset($usr_id) || $usr_id < 1 || $usr_id == ''){
echo 'Napaka! Manjka ID uporabnika.';
die();
}
$this->usr_id = $usr_id;
// Dobimo status preklopa za userja
$sqlUser = sisplet_query("SELECT switch_status FROM 1ka_domain_change_user WHERE usr_id='".$this->usr_id."'");
// Uporabnik se ni naredil nic
if(mysqli_num_rows($sqlUser) == 0)
$this->user_switch_status = 0;
$rowUser = mysqli_fetch_array($sqlUser);
$this->user_switch_status = $rowUser['switch_status'];
}
// Preverimo ce izvajamo na aplikaciji preklop domene
public static function check1kaDomainChange(){
global $site_domain;
// ZAENKRAT JE CEL MODUL UGASNJEN
return false;
// Ce smo na www.1ka.si, oneclicksurvey.com ali enklikanketa.si
//if(in_array($site_domain, array('www.1ka.si', 'www.oneclicksurvey.com', 'www.enklikanketa.si'))){
//if(in_array($site_domain, array(self::$domain_original, self::$domain_new)))
if($site_domain == self::$domain_original)
return true;
else
return false;
}
// Ali prikazujemo kreiranje, kopiranje ankete
public function domainChangeLimits(){
global $site_domain;
// Skrivamo samo na originalni domeni (www.1ka.si) in se ni naredil preklopa na oneclicksurvey.com
if($site_domain == self::$domain_original && $this->user_switch_status != '2'){
// Preverimo aktiven paket - ce nima placanega paketa, mu vse skrijemo
$userAccess = UserAccess::getInstance($this->usr_id);
$user_package = $userAccess->getPackage();
if ($user_package != '2' && $user_package != "3"){
return true;
}
}
return false;
}
// Ali prikazujemo kreiranje, kopiranje ankete
public function visibleSwitchPopup(){
global $site_domain;
if($site_domain != self::$domain_original)
return false;
if($this->user_switch_status != 0)
return false;
return true;
}
// Izpisemo popup obvestilo, da je funkcionalnost onemogocena in naj kupi paket
private function displaySwitchPopup(){
global $lang;
global $site_url;
echo '<h2>'.$lang['domain_switch_popup_title'].'</h2>';
echo '<div class="popup_close"><a href="#" onclick="popupUserAccess_close();">✕</a></div>';
echo '<p>'.$lang['domain_switch_popup_text'].'</p>';
echo '<div class="button_holder">';
echo ' <button class="medium white-blue" href="#" onClick="popupSwitch_save(\'1\');">'.$lang['domain_switch_popup_no'].'</button>';
echo ' <button class="medium blue" href="#" onClick="popupSwitch_save(\'2\');">'.$lang['domain_switch_popup_yes'].'</button>';
echo '</div>';
}
// Ajax klici
public function ajax(){
global $site_url;
// Prikazemo popup z izbiro preklopa
if($_GET['a'] == 'displaySwitchPopup') {
$this->displaySwitchPopup($what);
}
// Prikazemo popup z izbiro preklopa
elseif($_GET['a'] == 'setSwitchStatus') {
$switch_status = isset($_POST['switch_status']) ? $_POST['switch_status'] : '';
if($switch_status != ''){
/*$sqlUser = sisplet_query("INSERT INTO 1ka_domain_change_user
(usr_id, switch_time, switch_status)
VALUES
('".$this->usr_id."', NOW(), '".$switch_status."')
ON DUPLICATE KEY UPDATE
switch_status='".$switch_status."'
");*/
// Izvede se prenos na oneclicksurvey.com - userja se odjavi na 1ka.si in prijavi na oneclicksurvey.com
if($switch_status == '2'){
$return_data = array(
'action' => 'switch_domain',
'url' => $site_url.'/domain-change.php?action=logout'
);
echo json_encode($return_data);
}
}
}
}
// Pri preklopu domene odjavimo userja iz stare domene
public static function domainChangeLogoutOld($secret_key){
global $cookie_domain;
// Dobmo piskotek za post na domeno oneclicksurvey.com (tam uporabnika prijavimo)
$cookie = array(
'secret' => $_COOKIE['secret'],
'uid' => $_COOKIE['uid'],
'unam' => $_COOKIE['unam']
);
if (isset ($_COOKIE['g2fa']) && !empty($_COOKIE['g2fa']))
$cookie['g2fa'] = $_COOKIE['g2fa'];
$cookie_string = json_encode($cookie);
$cipher = "AES-256-CBC";
$encrypted_cookie_string = openssl_encrypt($cookie_string, $cipher, $secret_key);
// Pobrisemo piskotek in uporabnika odjavimo
setcookie('uid', '', time() - 3600, '/', $cookie_domain);
setcookie('unam', '', time() - 3600, '/', $cookie_domain);
setcookie('secret', '', time() - 3600, '/', $cookie_domain);
setcookie('ME', '', time() - 3600, '/', $cookie_domain);
setcookie('P', '', time() - 3600, '/', $cookie_domain);
setcookie("AN", '', time() - 3600, '/', $cookie_domain);
setcookie("AS", '', time() - 3600, '/', $cookie_domain);
setcookie("AT", '', time() - 3600, '/', $cookie_domain);
setcookie("DP", $p, time() - 3600 * 24 * 365, "/", $cookie_domain);
setcookie("DC", $p, time() - 3600 * 24 * 365, "/", $cookie_domain);
setcookie("DI", $p, time() - 3600 * 24 * 365, "/", $cookie_domain);
setcookie("SO", $p, time() - 3600 * 24 * 365, "/", $cookie_domain);
setcookie("SPO", $p, time() - 3600 * 24 * 365, "/", $cookie_domain);
setcookie("SL", $p, time() - 3600 * 24 * 365, "/", $cookie_domain);
// pobrisi se naddomeno! (www.1ka.si naj pobrise se 1ka.si)
if (substr_count($cookie_domain, ".") > 1) {
$nd = substr($cookie_domain, strpos($cookie_domain, ".") + 1);
setcookie('uid', '', time() - 3600, '/', $nd);
setcookie('unam', '', time() - 3600, '/', $nd);
setcookie('secret', '', time() - 3600, '/', $nd);
setcookie('ME', '', time() - 3600, '/', $nd);
setcookie('P', '', time() - 3600, '/', $nd);
setcookie("AN", '', time() - 3600, '/', $nd);
setcookie("AS", '', time() - 3600, '/', $nd);
setcookie("AT", '', time() - 3600, '/', $nd);
setcookie("DP", $p, time() - 3600 * 24 * 365, "/", $nd);
setcookie("DC", $p, time() - 3600 * 24 * 365, "/", $nd);
setcookie("DI", $p, time() - 3600 * 24 * 365, "/", $nd);
setcookie("SO", $p, time() - 3600 * 24 * 365, "/", $nd);
setcookie("SPO", $p, time() - 3600 * 24 * 365, "/", $nd);
setcookie("SL", $p, time() - 3600 * 24 * 365, "/", $nd);
}
// Preusmerimo na oneclicksurvey s parametri za prijavo
header('Location: http://'.self::$domain_new.'/domain-change.php?action=login&c='.urlencode($encrypted_cookie_string));
}
// Pri preklopu domene prijavimo userja v novo stran
public static function domainChangeLoginNew($secret_key){
global $cookie_domain;
// Check if the request is coming from an allowed domain
$referer = $_SERVER['HTTP_REFERER'];
$domain = parse_url($referer, PHP_URL_HOST);
if ($domain != self::$domain_original) {
header("HTTP/1.0 403 Forbidden");
die("Forbidden");
}
// Get cookies from parameter
if(!isset($_GET['c']) || $_GET['c'] == ''){
die();
}
$encrypted_cookie_string = $_GET['c'];
// Decrypt cookies
$cipher = "AES-256-CBC";
$cookie_string = openssl_decrypt($encrypted_cookie_string, $cipher, $secret_key);
$cookie = json_decode($cookie_string);
$LifeTime = 43200;
// Set cookies on new domain
setcookie("uid", $cookie->uid, time() + $LifeTime, '/', $cookie_domain);
setcookie("unam", $cookie->unam, time() + $LifeTime, '/', $cookie_domain);
setcookie("secret", $cookie->secret, time() + $LifeTime, '/', $cookie_domain);
header('Location: http://'.self::$domain_new);
}
}
|