-
Notifications
You must be signed in to change notification settings - Fork 40
/
ajax.php
executable file
·1680 lines (1230 loc) · 78.1 KB
/
ajax.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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
session_start();
require '/var/www/classes/Session.class.php';
$session = new Session();
$result = Array();
$result['status'] = 'ERROR';
$result['redirect'] = '';
$result['msg'] = 'STOP SPYING ON ME!';
$loggedOut = FALSE;
if(isset($_POST['func'])){
switch($_POST['func']){
case 'check-user':
case 'check-mail':
$loggedOut = TRUE;
break;
}
}
if($session->issetLogin() || $loggedOut){
$result['status'] = 'OK';
if(!$loggedOut){
// 2019: Sorry, no idea what I had in mind below
//TESTE!!!! RETIRAR \/ (COMENTÁRIO OU A LINHA)
//require 'template/gameHeader.php'; //TODO: is it really needed? (perhaps for set_time, but..)
}
if(isset($_POST['func'])){
$func = $_POST['func'];
switch($func){
case 'gettext':
if(!isset($_POST['id'])){
$result['status'] = 'ERROR';
break;
}
$id = $_POST['id'];
//leave this empty space (' ' instead of ''), otherwise gettext will freak out.
$title = ' ';
$text = ' ';
$btn = ' ';
$img = ' ';
$extra = ' ';
switch($id){
case 'tutorial_prepare':
$title = 'Prepare your tools.';
$text = sprintf(_('Before hacking the victim, you need to run your cracker. Go to the %ssoftware page%s.'), '<a class=\"notify-link\" href=\"software\">', '</a>');
break;
case 'tutorial_install_cracker':
$title = 'Install your cracker';
$text = sprintf(_('%sInstall%s the highlighted software, so you can hack the victim.'), '<a class=\"notify-link\" href=\"software?action=install&id='.$_POST['info'].'\">', '</a>');
break;
case 'tutorial_goto_vic_80':
$title = 'Navigate to the victim';
$text = sprintf(_('Good job on installing your cracker. Now, go to the %sinternet page%s and navigate to the victim IP.'), '<a href=\"internet\" class=\"notify-link\">', '</a>');
break;
case 'tutorial_goto_vic_83':
$title = 'Navigate to the victim';
$text = sprintf(_('Go to the %sinternet page%s and navigate to the victim IP address.'), '<a href=\"internet\" class=\"notify-link\">', '</a>');
break;
case 'tutorial_goto_vic':
$title = 'Navigate to the victim';
$text = sprintf(_('Now that you are here, enter the victim IP address: %s%s%s'), '<a class=\"notify-link\" href=\"internet?ip='.$_POST['info'].'\">', $_POST['info'], '</a>');
break;
case 'tutorial_hacktab':
$title = 'Good!';
$text = sprintf(_('Now click on the %shack tab%s to display the hacking options.'), '<a class=\"notify-link\" href=\"internet?action=hack\">', '</a>');
break;
case 'tutorial_hack':
$title = 'Hack him!';
$text = sprintf(_('Click on %sBruteforce Attack%s to use your cracker.'), '<a class=\"notify-link\" href=\"internet?action=hack&method=bf\">', '</a>');
break;
case 'tutorial_login1':
$title = 'Abracadabra!';
$text = 'Congratulations, you just hacked your first IP. Now do the login, don\'t forget to quickly delete your logs.';
case 'tutorial_login2':
$title = 'Nice!';
$text = 'You have his password. Again, don\'t forget to quickly hide your logs.';
break;
case 'tutorial_deletelog':
$title = 'Delete your logs!';
$text = 'Hide your IP. Quick!';
break;
case 'tutorial_80':
$title = 'What?';
$text = sprintf(_('Someone must have deleted the file Users.dat. Check the %slog page%s!'), '<a class=\"notify-link\" href=\"internet?view=logs\">', '</a>');
break;
case 'tutorial_81':
$title = 'Someone deleted it!';
$text = sprintf(_('Look! That guy deleted our file. Fine, I have an idea. Check your %smission page%s again, I\'ve updated it.'), '<a class=\"notify-link\" href=\"missions\">', '</a>');
break;
case 'tutorial_logout':
$title = 'Logout from this one.';
$text = 'We are done here. Click on Logout.';
break;
case 'tutorial_upload1':
$title = 'Upload him a gift.';
$text = 'Give that man a gift. Upload the virus using the menu on the right.';
break;
case 'tutorial_upload2':
$title = 'Almost there.';
$text = sprintf(_('Now %sinstall%s the virus.'), '<a class=\"notify-link\" href=\"internet?view=software&cmd=install&id='.$_POST['info'].'\">', '</a>');
break;
case 'tutorial_end':
$title = 'Hurray!';
$text = sprintf(_('Nice job, son. I am proud of you. I hope this SOB learned his lesson. Go to the %smission page%s to retrieve your reward.'), '<a href=\"missions\" class=\"notify-link\">', '</a>');
break;
case 'tutorial_collect':
$title = 'Collect your money.';
$text = 'Congratulations on completing the mission. Now, collect your hard-earned money clicking on \'Complete mission\'.';
break;
case 'abort':
$title = 'Abort Mission';
$text = sprintf(_('Are you sure you want to abort this misson?<br/><br/>You will lose %s of your reputation and pay a penalty of %s.'), '<span class=\"red\">10%</span>', '<span class=\"red\">$500 + '._('reward').'</span>');
$btn = '<input type=\"submit\" class=\"btn btn-danger\" value=\"'._('Abort').'\">';
break;
case 'accept_m':
$title = 'Accept Mission';
$text = 'Are you sure you want to accept this mission?';
$btn = '<input type=\"submit\" class=\"btn btn-success\" value=\"'._('Accept').'\">';
break;
case 'm_completed_notify':
$title = 'Mission completed';
$text = sprintf(_('Congratulations, you completed the mission. Go to the %smission page%s to retrieve your reward.'), '<a class=\"notify-link\" href=\"missions\">', '</a>');
break;
case 'm_completed_inform':
$title = 'Complete mission';
$text = sprintf(_('You completed the mission. Inform the account you want to add your %s. %s'), '<font color=\"red\"><strong>$'.$_POST['info'].'</strong></font>', '<br/><br/><div id=\"loading\"><img src=\"images/ajax-money.gif\">'._('Loading...').'</div><input type=\"hidden\" id=\"accSelect\" value=\"\"><span id=\"desc-money\"></span>');
$btn = '<input id=\"modal-submit\" type=\"submit\" class=\"btn btn-success\" value=\"'._('Complete Mission').'\" DISABLED>';
break;
case 'certdiv':
$completed = _('You have already completed this certification.');
$completed_label = _('Completed ');
$completed_all = sprintf(_('%sCongratulations!%s You have completed all certifications.%s'), '<div class=\"alert alert-success\"><strong>', '</strong>', '</div> ');
$take = _('Take certification');
$learning_label = _('Learning');
$certify_free = _('Get certified (free)');
$ceritify_paid = _('Get certified for $');
$locked = sprintf(_('%sThis certification is locked.'), '<span title=\"'._('This means you need to take another certification before doing this one.').'\">', '</span>');
$c1 = 'Basic Tutorial';
$d1 = 'Game basics.';
$c2 = 'Hacking 101';
$d2 = 'Learn the basics of hacking.';
$c3 = 'Intermediate Hacking';
$d3 = 'Improve your hacking techniques.';
$c4 = 'Advanced Hacking';
$d4 = 'Meet the wonders of DDoS world.';
$c5 = 'DDoS Security';
$d5 = 'Learn to protect yourself from DDoS.';
$extra = ',"c":"'.$completed.'","c_label":"'.$completed_label.'","c_all":"'.$completed_all.'","take":"'.$take.'","learning":"'.$learning_label.'","cert_free":"'.$certify_free.'","cert_paid":"'.$ceritify_paid.'","locked":"'.$locked.'"';
$extra .= ',"c1":"'._($c1).'","c2":"'._($c2).'","c3":"'._($c3).'","c4":"'._($c4).'","c5":"'._($c5).'"';
$extra .= ',"d1":"'._($d1).'","d2":"'._($d2).'","d3":"'._($d3).'","d4":"'._($d4).'","d5":"'._($d5).'"';
break;
case 'certbuy':
$key = $_POST['info'];
if(!ctype_digit($key) || $key <= 0 || $key > 5){
$result['status'] = 'ERROR';
break;
}
switch($key){
case 1:
$name = 'Basic Tutorial';
$p = 0;
break;
case 2:
$name = 'Hacking 101';
$p = 0;
break;
case 3:
$name = 'Intermediate Hacking';
$p = 50;
break;
case 4:
$name = 'Advanced Hacking';
$p = 200;
break;
case 5:
$name = 'DDoS Security';
$p = 500;
break;
}
if($p > 0){
$disabled = 'DISABLED';
} else {
$disabled = '';
}
require '/var/www/classes/Finances.class.php';
$finances = new Finances();
$totalMoney = $finances->totalMoney();
$title = _('Buy certification');
$text = sprintf(_('Are you sure you want to buy the certification %s for %s?'), '<strong>'._($name).'</strong>', '<span class=\"red\">$'.$p.'</span>');
$text .= '<br/><div id=\"loading\"><img src=\"images/ajax-money.gif\">'._('Loading...').'</div><input type=\"hidden\" id=\"accSelect\" value=\"\"><span id=\"desc-money\"></span>';
$btn = '<input id=\"modal-submit\" type=\"submit\" class=\"btn btn-primary\" value=\"'._('Buy').'\" '.$disabled.'>';
$extra = ',"n":"'.$name.'","p":"'.$p.'"';
if($totalMoney < $p && $p > 0){
$text = 'You do not have enough money to buy this certification.';
$btn = '<input type=\"submit\" data-dismiss=\"modal\" class=\"btn btn-info\" value=\"Okay\">';
}
break;
case 'loadsoft':
$loading = '<div id=\"loading\"><img src=\"images/ajax-software.gif\"> '._('Loading...').'</div>';
$ph = _('Choose a software...');
$extra = ',"loading":"'.$loading.'","placeholder":"'.$ph.'"';
break;
case 'adb':
$title = sprintf(_('Hey, looks like you are using AdBlock. <br/>We hate ads too, and we totally support your right to not be tracked! However, ads keep this game free.<br/> Please, consider disabling AdBlock for this site or purchasing a %spremium account</a> to get rid of them.<br/>'), '<a href=\"premium\">');
break;
}
if($title == '' && $text == '' && $extra == ''){
$result['status'] = 'ERROR';
break;
}
$result['msg'] = '[{"title":"'._($title).'","text":"'._($text).'","btn":"'._($btn).'"'.$extra.'}]';
break;
case 'credits':
// 2019: Feel free to add your name(s) below, as well as remove
// 2019: any if they are no longer used (e.g. if you completely
// 2019 removed one of the JS libraries). Otherwise, please keep
// 2019: the corresponding credits.
$title = _('Credits');
$text = '';
$text .= '<p><span class=\"credit-category\">'._('Developer').'</span><br/><span class=\"credit-sole\"><a href=\"http://fb.com/RenatoMassaro\">Renato Massaro</a></span></p>';
$text .= '<p><span class=\"credit-category\">'._('Game Designer').'</span><br/><span class=\"credit-sole\"><a href=\"http://fb.com/RenatoMassaro\">Renato Massaro</a></span></p>';
$text .= '<p><span class=\"credit-category\">'._('System Administrator').'</span><br/><span class=\"credit-sole\"><a href=\"http://fb.com/RenatoMassaro\">Renato Massaro</a></span></p>';
$text .= '<p><span class=\"credit-category\">'._('Design').'</span><br/>';
$text .= '<span class=\"credit-text\">Framework</span><span class=\"credit-right\"><a href=\"http://getbootstrap.com/\">Twitter Bootstrap</a></span><br/>';
$text .= '<span class=\"credit-text\">Template</span><span class=\"credit-right\"><a href=\"http://bootstrap-hunter.com/\">diablo9983</a></span><br/>';
$text .= '<span class=\"credit-text\">Icon Pack</span><span class=\"credit-right\"><a href=\"http://www.famfamfam.com/lab/icons/\">Fam Fam Fam</a></span><br/>';
$text .= '<span class=\"credit-text\"> </span><span class=\"credit-right\"><a href=\"http://www.fatcow.com/free-icons\">Fat Cow</a></span><br/>';
$text .= '<span class=\"credit-text\">Landing page</span><span class=\"credit-right\"><a href=\"fb.com/RenatoMassaro\">Renato Massaro</a></span><br/>';
$text .= '<span class=\"credit-text\">Blinking cursor</span><span class=\"credit-right\">Victor Scattone</span><br/></p>';
$text .= '<p><span class=\"credit-category\">'._('Javascript Libraries').'</span><br/>';
$text .= '<span class=\"credit-sole\"><a href=\"http://jquery.com/\">jQuery</a></span><br/>';
$text .= '<span class=\"credit-sole\"><a href=\"http://ivaynberg.github.io/select2/\">Select2</a></span><br/>';
$text .= '<span class=\"credit-sole\"><a href=\"http://rendro.github.io/easy-pie-chart/\">Easy pie chart</a></span><br/>';
$text .= '<span class=\"credit-sole\"><a href=\"http://drewwilson.com/\">TipTip</a></span><br/>';
$text .= '<span class=\"credit-sole\"><a href=\"https://github.com/plentz/jquery-maskmoney\">jQuery-maskmoney</a></span><br/>';
$text .= '<span class=\"credit-sole\"><a href=\"https://github.com/peachananr/onepage-scroll\">One page scroll</a></span><br/>';
$text .= '<span class=\"credit-sole\"><a href=\"https://github.com/mattboldt/typed.js/\">typed.js</a></span><br/>';
$text .= '<span class=\"credit-sole\"><a href=\"http://www.sceditor.com/\">SCEditor</a></span><br/></p>';
$text .= '<p><span class=\"credit-category\">'._('Special thanks').'</span><br/>';
$text .= '<span class=\"credit-sole\">Eduardo Estevão</span><br/>';
$text .= '<span class=\"credit-sole\">Gabriel Oliveira</span><br/>';
$text .= '<span class=\"credit-sole\">Victor Scattone</span><br/>';
$text .= '<span class=\"credit-sole\"><a href=\"http://stackoverflow.com/\">Stack Overflow ♥</a></span><br/></p>';
$text .= '<br/><span class=\"small\">'._('You should be here?').' <a class=\"black\" href=\"mailto:'._('[email protected]').'\">'._('Contact us').'</a>!</span>';
$text .= '';
$btn = '<a data-dismiss=\"modal\" class=\"btn\" href=\"#\">'._('Ok').'</a>';
$result['msg'] = '[{"title":"'.$title.'","text":"'.$text.'","btn":"'.$btn.'"}]';
break;
case 'getBRLvalue':
require '/var/www/classes/Premium.class.php';
$premium = new Premium();
$result['msg'] = $premium->exchange_rate('USD', 'BRL', 1, 2);
break;
case 'deleteDdos':
$title = 'Delete DDoS reports';
$text = 'Are you sure you want to delete all DDoS reports? This action can\'t be undone.';
$btn = '<input id=\"modal-submit\" type=\"submit\" class=\"btn btn-primary\" value=\"Yes\"><a data-dismiss=\"modal\" class=\"btn\" href=\"#\">'._('Cancel').'</a>';
$result['msg'] = '[{"title":"'.$title.'","text":"'.$text.'","btn":"'.$btn.'"}]';
break;
case 'bankChangePass':
$title = 'Change account password';
$text = 'Are you sure you want to change your account password? It is <strong>free</strong>.';
$btn = '<input id=\"modal-submit\" type=\"submit\" class=\"btn btn-primary\" value=\"Change\"><a data-dismiss=\"modal\" class=\"btn\" href=\"#\">'._('Cancel').'</a>';
$result['msg'] = '[{"title":"'.$title.'","text":"'.$text.'","btn":"'.$btn.'"}]';
break;
case 'bankCloseAcc':
if(!$session->issetBankSession()){
$result['status'] = 'ERROR';
break;
}
require '/var/www/classes/Finances.class.php';
$finances = new Finances();
$accInfo = $finances->getBankAccountInfo($_SESSION['id'], $_SESSION['BANK_ID']);
if($accInfo['VALID_ACC'] == '0'){
$result['status'] = 'ERROR';
break;
} elseif($accInfo['USER'] != $_SESSION['id']){
$result['status'] = 'ERROR';
break;
}
if($accInfo['CASH'] > 0){
$text = 'You can not close an account with money.';
$btn = '<input data-dismiss=\"modal\" type=\"submit\" class=\"btn btn-info\" value=\"Okay\">';
} else {
$text = 'Are you sure you want to close your account? It can\'t be undone.';
$btn = '<input id=\"modal-submit\" type=\"submit\" class=\"btn btn-danger\" value=\"Close\"><a data-dismiss=\"modal\" class=\"btn\" href=\"#\">'._('Cancel').'</a>';
}
$title = 'Close account';
$result['msg'] = '[{"title":"'.$title.'","text":"'.$text.'","btn":"'.$btn.'"}]';
break;
case 'buyLicense':
$result['status'] = 'ERROR';
if(!isset($_POST['id'])){
break;
}
$softID = $_POST['id'];
if(!ctype_digit($softID)){
break;
}
require '/var/www/classes/Player.class.php';
require '/var/www/classes/PC.class.php';
require '/var/www/classes/Finances.class.php';
$software = new SoftwareVPC();
$finances = new Finances();
$external = FALSE;
if(!$software->issetSoftware($softID, $_SESSION['id'], 'VPC')){
if(!$software->issetExternalSoftware($softID)){
break;
}
$external = TRUE;
}
if($external){
$softInfo = $software->getExternalSoftware($softID);
} else {
$softInfo = $software->getSoftware($softID);
}
if(!$software->isResearchable($softInfo->softtype)){
break;
}
$result['status'] = 'OK';
$researchPrice = $software->license_studyPrice($softInfo->softtype, $softInfo->softversion, $softInfo->licensedto);
if($researchPrice > $finances->totalMoney()){
$textMoney = '<br/><span class=\"red pull-left\" style=\"margin-left: 9%;\">'._('You do not have enough money to buy this license.').'</span>';
$canBuy = FALSE;
$btn = '<input id=\"modal-submit\" type=\"submit\" class=\"btn btn-primary\" value=\"'._('Buy').'\" DISABLED><a data-dismiss=\"modal\" class=\"btn\" href=\"#\">'._('Cancel').'</a>';
} else {
$textMoney = '<br/><div id=\"loading\" class=\"pull-left\" style=\"margin-left: 9%;\"><img src=\"images/ajax-money.gif\">'._('Loading...').'</div><input type=\"hidden\" id=\"accSelect\" value=\"\"><span id=\"desc-money\" class=\"pull-left\" style=\"margin-left: 9%;\"></span>';
$canBuy = TRUE;
$btn = '<input id=\"modal-submit\" type=\"submit\" class=\"btn btn-primary\" value=\"'._('Buy').'\"><a data-dismiss=\"modal\" class=\"btn\" href=\"#\">'._('Cancel').'</a>';
}
$licenseText = '<span class=\"pull-left\">'._('Buy license of the software ').'<strong>'.$softInfo->softname.$software->getExtension($softInfo->softtype).'</strong>';
$licenseText .= _(' for ').'<span class=\"green\">$'.number_format($researchPrice).'</span>?</span>';
$title = _('Buy license');
$text = '<span class=\"pull-left\" style=\"margin-left: 9%;\">'. $licenseText .'</span>';
$text .= $textMoney;
$result['msg'] = '[{"title":"'.$title.'","text":"'.$text.'","btn":"'.$btn.'","canBuy":"'.$canBuy.'"}]';
break;
// 2019: I don't remember if the reportBug feature works. If it does,
// 2019: I'm pretty sure there's no interface to see them, other than
// 2019: inspecting the database directly.
case 'reportBug':
$result['status'] = 'OK';
if(isset($_POST['follow']) && isset($_POST['rlt'])){
$follow = $_POST['follow'];
$rlt = $_POST['rlt'];
if($follow != 1){
$follow = 0;
}
if(strlen(trim($rlt)) == 0){
$result['status'] = 'ERROR';
break;
}
$sessionDB = '';
foreach($_SESSION as $key => $value){
if ($value instanceof DateTime) {
$value = $value->format('Y-m-d H:i:s');
}
$sessionDB .= '<strong>'.$key.'</strong> - '.$value.'<br/>';
}
$server = '';
foreach($_SERVER as $key => $value){
$server .= '<strong>'.$key.'</strong> - '.$value.'<br/>';
}
$pdo = PDO_DB::factory();
$session->newQuery();
$sql = 'INSERT INTO bugreports (bugText, reportedBy, sessionContent, serverContent, follow)
VALUES (:text, :reporter, :session, :server, :follow)';
$stmt = $pdo->prepare($sql);
$stmt->execute(array(':text' => $rlt, ':reporter' => $_SESSION['id'], ':session' => $sessionDB, ':server' => $server, ':follow' => $follow));
} else {
$title = '<center>'._('Report a bug').'</center>';
$text = '<center><div class=\"control-group\"><div class=\"controls\"><textarea id=\"bug-content\" class=\"bugtext\" name=\"bugcontent\" rows=\"5\" placeholder=\"'._('Please explain in details what happened. In which page were you? Which action were you doing? Is it possible to reproduce the bug? Thanks!').'\" style=\"width: 80%;\"></textarea><br/><span class=\"small pull-left link\" style=\"margin-left: 9%;\"><label name=\"contact\">'._('Contact me with bug information').': <input id=\"bug-follow\" style=\"margin-left: 5px;\" type=\"checkbox\" name=\"contact\" value=\"1\" CHECKED></label></span></div></div></center>';
$btn = '<input id=\"bug-submit\" type=\"submit\" class=\"btn btn-info\" value=\"'._('Report').'\">';
$result['msg'] = '[{"title":"'.$title.'","text":"'.$text.'","btn":"'.$btn.'"}]';
}
break;
case 'getBadge':
$result['status'] = 'ERROR';
if(!array_key_exists('HTTP_REFERER', $_SERVER)){
break;
}
if(strpos($_SERVER['HTTP_REFERER'], 'clan')){
$clan = TRUE;
} else {
$clan = FALSE;
}
if(!isset($_POST['badgeID']) || !isset($_POST['userID'])){
break;
}
$badgeID = $_POST['badgeID'];
$userID = $_POST['userID'];
if(strlen($badgeID) == 0 || !ctype_digit($badgeID) || $badgeID < 1){
break;
}
if(strlen($userID) == 0 || !ctype_digit($userID) || $userID < 1){
break;
}
$pdo = PDO_DB::factory();
if(!$clan){
$session->newQuery();
$sql = 'SELECT login FROM users WHERE id = :userID LIMIT 1';
$stmt = $pdo->prepare($sql);
$stmt->execute(array(':userID' => $userID));
$user = $stmt->fetch(PDO::FETCH_OBJ)->login;
$session->newQuery();
$sql = 'SELECT round, dateAdd, COUNT(badgeID) AS total
FROM users_badge
WHERE badgeID = :badgeID AND userID = :userID
GROUP BY badgeID';
$stmt = $pdo->prepare($sql);
$stmt->execute(array(':badgeID' => $badgeID, ':userID' => $userID));
$badgeInfo = $stmt->fetch(PDO::FETCH_OBJ);
$title = 'Badges of user '.$user;
} else {
$session->newQuery();
$sql = 'SELECT name FROM clan WHERE clanID = :clanID LIMIT 1';
$stmt = $pdo->prepare($sql);
$stmt->execute(array(':clanID' => $userID));
$user = $stmt->fetch(PDO::FETCH_OBJ)->name;
$session->newQuery();
$sql = 'SELECT round, dateAdd, COUNT(badgeID) AS total
FROM clan_badge
WHERE badgeID = :badgeID AND clanID = :clanID
GROUP BY badgeID';
$stmt = $pdo->prepare($sql);
$stmt->execute(array(':badgeID' => $badgeID, ':clanID' => $userID));
$badgeInfo = $stmt->fetch(PDO::FETCH_OBJ);
$title = 'Badges of clan '.$user;
}
if(!empty($badgeInfo)){
$result['status'] = 'OK';
$badgeJSON = json_decode(file_get_contents('json/badges.json'));
$badgeName = $badgeJSON->$badgeID->name;
$badgeDesc = $badgeJSON->$badgeID->desc;
if($badgeDesc != ''){
$badgeDesc = ' - '.$badgeDesc;
}
$totalAwarded = $awardedStr = '';
if($badgeJSON->$badgeID->collectible){
if($badgeInfo->total == 1){
$totalAwarded = 'Awarded 1 time.';
$awardedStr = substr($badgeInfo->dateadd, 0, -9).' - Round #'.$badgeInfo->round;
} else {
$totalAwarded = 'Awarded '.$badgeInfo->total.' times.';
$awardedStr = '';
if($clan){
$session->newQuery();
$sql = "SELECT round, dateAdd
FROM clan_badge
WHERE badgeID = '".$badgeID."' AND clanID = '".$userID."'";
$data = $pdo->query($sql);
} else {
$session->newQuery();
$sql = "SELECT round, dateAdd
FROM users_badge
WHERE badgeID = '".$badgeID."' AND userID = '".$userID."'";
$data = $pdo->query($sql);
}
while($dateInfo = $data->fetch(PDO::FETCH_OBJ)){
$awardedStr .= substr($dateInfo->dateadd, 0, -9).' - Round #'.$dateInfo->round;
$awardedStr .= '<br/>';
}
$awardedStr = substr($awardedStr, 0, -5);
}
$totalAwarded .= '<br/>';
$awardedStr .= '<br/><br/>';
}
if($clan){
$session->newQuery();
$sql = "SELECT COUNT(*)
FROM clan_badge
WHERE badgeID = '".$badgeID."'
GROUP BY clanID
HAVING clanID <> '".$userID."'";
$totalPlayers = sizeof($pdo->query($sql)->fetchAll());
if($totalPlayers == 0){
$playersStr = 'Only <a href=\"clan?id='.$userID.'\">'.$user.'</a> have this badge.';
} elseif($totalPlayers == 1) {
$playersStr = '<a href=\"clan?id='.$userID.'\">'.$user.'</a> and <strong>1</strong> other clan have this badge.';
} else {
$playersStr = '<a href=\"clan?id='.$userID.'\">'.$user.'</a> and <strong>'.$totalPlayers .'</strong> others clans have this badge.';
}
} else {
$session->newQuery();
$sql = "SELECT COUNT(*)
FROM users_badge
WHERE badgeID = '".$badgeID."'
GROUP BY userID
HAVING userID <> '".$userID."'";
$totalPlayers = sizeof($pdo->query($sql)->fetchAll());
if($totalPlayers == 0){
$playersStr = 'Only <a href=\"profile?id='.$userID.'\">'.$user.'</a> have this badge.';
} elseif($totalPlayers == 1) {
$playersStr = '<a href=\"profile?id='.$userID.'\">'.$user.'</a> and <strong>1</strong> other player have this badge.';
} else {
$playersStr = '<a href=\"profile?id='.$userID.'\">'.$user.'</a> and <strong>'.$totalPlayers .'</strong> others players have this badge.';
}
}
$text = '<strong>'.$badgeName.'</strong>'.$badgeDesc.'<br/><br/>'.$totalAwarded.'<span class=\"small nomargin\">'.$awardedStr.'</span>'.$playersStr;
}
if($result['status'] == 'ERROR'){
$text = 'Ops! This badge does not exists. :/';
}
$result['msg'] = '[{"title":"'.$title.'","text":"'.$text.'"}]';
break;
case 'check-user':
case 'check-mail':
require '/var/www/classes/System.class.php';
$pdo = PDO_DB::factory();
$system = new System();
$result = false;
if($func == 'check-user'){
if(!isset($_POST['username'])){
break;
}
$user = $_POST['username'];
if(ctype_digit($user)){
break;
}
if(strlen($user) > 15 || strlen($user) < 1){
break;
}
if(!$system->validate($user, 'username')){
break;
}
$cond = 'login';
$var = $user;
} elseif($func == 'check-mail'){
if(!isset($_POST['email'])){
break;
}
$mail = $_POST['email'];
if(strlen($mail) < 1){
break;
}
if(!$system->validate($mail, 'email')){
break;
}
$cond = 'email';
$var = $mail;
}
$sql = 'SELECT id FROM users WHERE '.$cond.' = ? LIMIT 1';
$sqlReg = $pdo->prepare($sql);
$sqlReg->execute(array($var));
if($sqlReg->rowCount() == 1){
$result = FALSE;
} else {
$result = TRUE;
}
break;
case 'getResearchStats':
$pdo = PDO_DB::factory();
if(!isset($_POST['round'])){
$result['status'] = 'ERROR';
break;
}
$round = $_POST['round'];
if($round == 'all'){
$select = 'SUM(researchCount) AS researchcount, SUM(moneyResearch) AS moneyresearch';
$where = '';
} else {
$select = 'researchCount, moneyResearch';
$where = 'ORDER BY id DESC LIMIT 1';
}
$session->newQuery();
$sql = 'SELECT '.$select.' FROM round_stats '.$where;
$info = $pdo->query($sql)->fetch(PDO::FETCH_OBJ);
$moneySpent = $info->moneyresearch;
$totalResearched = $info->researchcount;
require '/var/www/classes/Ranking.class.php';
$ranking = new Ranking();
$rankInfo = $ranking->getResearchRank($_SESSION['id']);
$myRank = $rankInfo['rank'];
$return = number_format($moneySpent).'#'.number_format($totalResearched).'#'.number_format($myRank);
$result['msg'] = $return;
break;
case 'getFileActionsModal':
if(isset($_POST['type'])){
if($_POST['type'] == 'text'){
$type = 'text';
} else {
$type = 'folder';
}
if(isset($_POST['remote'])){
$remote = TRUE;
if($_POST['remote'] == 0){
$remote = FALSE;
}
} else {
$remote = FALSE;
}
if(!isset($_POST['action'])){
$result['status'] = 'ERROR';
break;
}
$action = $_POST['action'];
if($remote){
$host = long2ip($_SESSION['LOGGED_IN']);
} else {
$host = 'localhost';
}
$pdo = PDO_DB::factory();
$id = $_POST['id'];
if(!ctype_digit($id)){
if($action != 'create'){
$result['status'] = 'ERROR';
break;
}
}
if($type == 'text'){
switch($action){
case 'create':
$title = _('Create text file at ').$host;
$text = '<div class=\"control-group\"><div class=\"input-prepend\"><div class=\"controls\"><input class=\"name\" type=\"text\" name=\"name\" placeholder=\"'._('File name').'\" style=\"width: 67%;\"/><span class=\"add-on\" style=\"width: 10%;\">.txt</span></div></div></div><div class=\"control-group\"><div class=\"controls\"><textarea id=\"wysiwyg\" class=\"text\" name=\"text\" rows=\"5\" placeholder=\"'._('Content').'\" style=\"width: 80%;\"></textarea><br/><span class=\"small pull-left link text-show-editor\" style=\"margin-left: 9%;\">'._('Show editor').'</span></div></div>';
$btn = '<input type=\"submit\" class=\"btn btn-primary\" value=\"'._('Create text file').'\"><a data-dismiss=\"modal\" class=\"btn\" href=\"#\">'._('Cancel').'</a>';
break;
case 'edit':
$session->newQuery();
$sql = "SELECT software_texts.text, software.softName
FROM software_texts
INNER JOIN software ON software.id = software_texts.id
WHERE software_texts.id = '".$id."'
LIMIT 1";
$txtInfo = $pdo->query($sql)->fetchAll();
if(sizeof($txtInfo) == 0){
$result['status'] = 'ERROR';
break;
}
$txtName = str_replace('"', '\"', $txtInfo['0']['softname']);
$txtContent = str_replace('"', '\"', $txtInfo['0']['text']);
$txtContent = str_replace("\r\n", "\n", $txtContent);
$txtContent = str_replace("\r", "\n", $txtContent);
$txtContent = str_replace("\n", "\\n", $txtContent);
$title = _('Edit text file at ').$host;
$text = '<div class=\"control-group\"><div class=\"input-prepend\"><div class=\"controls\"><input class=\"name\" type=\"text\" name=\"name\" value=\"'.$txtName.'\" style=\"width: 67%;\"/><span class=\"add-on\" style=\"width: 10%;\">.txt</span></div></div></div><div class=\"control-group\"><div class=\"controls\"><textarea id=\"wysiwyg\" name=\"text\" rows=\"5\" style=\"width: 80%;\">'.$txtContent.'</textarea><br/><span class=\"small pull-left link text-show-editor\" style=\"margin-left: 9%;\">'._('Show editor').'</span></div></div>';
$btn = '<input type=\"submit\" class=\"btn btn-primary\" value=\"'._('Edit text file').'\"><a data-dismiss=\"modal\" class=\"btn\" href=\"#\">'._('Cancel').'</a>';
break;
default:
$result['status'] = 'ERROR';
break;
}
} else {
switch($action){
case 'create':
$title = _('Create folder at ').$host;
$text = '<div class=\"control-group\"><div class=\"controls\"><input class=\"name\" type=\"text\" name=\"name\" placeholder=\"'._('Folder name').'\" style=\"width: 80%;\"/></div></div>';
$btn = '<input type=\"submit\" class=\"btn btn-primary\" value=\"'._('Create folder').'\"><a data-dismiss=\"modal\" class=\"btn\" href=\"#\">'._('Cancel').'</a>';
break;
case 'edit':
$session->newQuery();
$sql = "SELECT softname FROM software WHERE id = '".$id."' LIMIT 1";
$folderInfo = $pdo->query($sql)->fetchAll();
if(sizeof($folderInfo) == 0){
$result['status'] = 'ERROR';
break;
}
$folderName = str_replace('"', '\"', $folderInfo['0']['softname']);
$title = _('Edit folder at ').$host;
$text = '<div class=\"control-group\"><div class=\"controls\"><input class=\"name\" type=\"text\" name=\"name\" value=\"'.$folderInfo['0']['softname'].'\" placeholder=\"Folder name\" style=\"width: 80%;\"/></div></div>';
$btn = '<input type=\"submit\" class=\"btn btn-primary\" value=\"'._('Edit folder').'\"><a data-dismiss=\"modal\" class=\"btn\" href=\"#\">'._('Cancel').'</a>';
break;
case 'delete':
$session->newQuery();
$sql = "SELECT softname, softversion FROM software WHERE id = '".$id."' LIMIT 1";
$data = $pdo->query($sql)->fetchAll();
if(sizeof($data) == 0){
$result['status'] = 'ERROR';
break;
}
$folderName = $data['0']['softname'];
if($remote){
$link = 'internet?view=software';
} else {
$link = 'software';
}
$title = 'Delete folder '.$folderName;
if($data['0']['softversion'] > 0){
$text = 'Folder <strong>'.$folderName.'</strong> have softwares and they must be deleted before.';
$btn = '<a data-dismiss=\"modal\" class=\"btn\" href=\"#\">'._('Ok').'</a>';
} else {
$text = 'Are you sure you want to delete the folder <strong>'.$folderName.'</strong>?';
$btn = '<input type=\"submit\" class=\"btn btn-primary\" value=\"'._('Delete folder').'\"><a data-dismiss=\"modal\" class=\"btn\" href=\"#\">'._('Cancel').'</a>';
}
break;
default:
$result['status'] = 'ERROR';
break;
}
}
if($result['status'] == 'ERROR'){
break;
}
$result['msg'] = '[{"title":"'.$title.'","text":"'.$text.'","btn":"'.$btn.'"}]';
}
break;
case 'getPwdInfo':
require '/var/www/classes/Process.class.php';
$process = new Process();
$player = new Player();
$btn = '';
$select2 = False;
$title = _('Change password');
if(!$process->issetProcess($_SESSION['id'], 'RESET_PWD', '', 'local', '', '', '')){
$btn = '<input id=\"modal-submit\" type=\"submit\" class=\"btn btn-primary\" value=\"'._('Change').'\" DISABLED><a data-dismiss=\"modal\" class=\"btn\" href=\"#\">'._('Cancel').'</a>';
$pwdInfo = $player->pwd_info();
if($pwdInfo['PRICE'] > 0){
$finances = new Finances();
$text = sprintf(_('You can wait %s<strong>%s</strong></span> for your next free reset or pay <strong>$%s</strong> for our charged password reset service.'), '<span class=\"red\">', $pwdInfo['NEXT_RESET'], number_format($pwdInfo['PRICE']));
$text .= '</br></br>';
if($finances->totalMoney() >= $pwdInfo['PRICE']){
$text .= '<div id=\"loading\"><img src=\"images/ajax-money.gif\">'._('Please wait').'</div><input type=\"hidden\" id=\"accSelect\" value=\"\"><span id=\"desc-money\"></span>';
$select2 = True;
} else {
$btn = '<a data-dismiss=\"modal\" class=\"btn\" href=\"#\">'._('Cancel').'</a>';
$text .= _('You do not have enough money.');
}
} else {
$text = _('You can reset your password now <b>for free!</b>');
$btn = '<input id=\"modal-submit\" type=\"submit\" class=\"btn btn-primary\" value=\"'._('Change').'\"><a data-dismiss=\"modal\" class=\"btn\" href=\"#\">'._('Cancel').'</a>';
}
} else {
$text = sprintf(_('There already is a password change in process. Refeer to the %sTask Manager%s.'), '<a href=\"processes\">', '</a>');
}
$result['msg'] = '[{"title":"'.$title.'","text":"'.$text.'","btn":"'.$btn.'","select2":"'.$select2.'"}]';
break;
case 'getPartModal':
if(!isset($_POST['opts'])){
$result['status'] = 'ERROR';
break;
}
$opts = $_POST['opts'];
if(!isset($opts['part']) || !isset($opts['price'])){
$result['status'] = 'ERROR';
break;
}
if(!ctype_digit($opts['price'])){
$result['status'] = 'ERROR';
exit();
}
require '/var/www/classes/Finances.class.php';
$finances = new Finances();
$totalMoney = $finances->totalMoney();
$title = _('Upgrade ').strtoupper($opts['part']);
$text = sprintf(_('Are you sure you want to buy %s for %s<strong>$%s</strong></span>?'), strtoupper($opts['part']), '<span class=\"red\">', number_format($opts['price']));
$text .= '<br/><br/>';
if($totalMoney >= $opts['price']){
$text .= '<input type=\"hidden\" id=\"accSelect\" value=\"\"><span id=\"desc-money\"></span>';
$btn = '<input id=\"modal-submit\" type=\"submit\" class=\"btn btn-primary\" value=\"'._('Buy').'\"><a data-dismiss=\"modal\" class=\"btn\" href=\"#\">'._('Cancel').'</a>';
} else {