24
24
require_once (dirname (__FILE__ ) . '/CleantalkSFW.php ' );
25
25
26
26
// Common CleanTalk options
27
- define ('CT_AGENT_VERSION ' , 'smf-213 ' );
27
+ define ('CT_AGENT_VERSION ' , 'smf-214 ' );
28
28
define ('CT_SERVER_URL ' , 'http://moderate.cleantalk.org ' );
29
29
define ('CT_DEBUG ' , false );
30
30
@@ -36,7 +36,7 @@ function cleantalk_sfw_check()
36
36
{
37
37
global $ modSettings , $ user_info ;
38
38
39
- if (!empty ($ modSettings ['cleantalk_sfw ' ]) && !$ user_info ['is_admin ' ]){
39
+ if (!empty ($ modSettings ['cleantalk_sfw ' ]) && !empty ( $ modSettings [ ' cleantalk_api_key_is_ok ' ]) && ! $ user_info ['is_admin ' ]){
40
40
41
41
$ sfw = new CleantalkSFW ();
42
42
$ key = $ modSettings ['cleantalk_api_key ' ];
@@ -49,6 +49,7 @@ function cleantalk_sfw_check()
49
49
if (isset ($ _COOKIE ['ct_sfw_pass_key ' ]) && $ _COOKIE ['ct_sfw_pass_key ' ] == md5 ($ curr_ip .$ key )){
50
50
51
51
$ is_sfw_check =false ;
52
+
52
53
if (!empty ($ _COOKIE ['ct_sfw_passed ' ])){
53
54
$ sfw ->sfw_update_logs ($ curr_ip , 'passed ' );
54
55
setcookie ('ct_sfw_passed ' , '0 ' , 1 , "/ " );
@@ -412,10 +413,10 @@ function cleantalk_print_js_input()
412
413
$ value = cleantalk_get_checkjs_code ();
413
414
414
415
return '<script type="text/javascript">
415
- var d = new Date(),
416
+ var ct_date = new Date(),
416
417
ctTimeMs = new Date().getTime(),
417
418
ctMouseEventTimerFlag = true, //Reading interval flag
418
- ctMouseData = "[" ,
419
+ ctMouseData = [] ,
419
420
ctMouseDataCounter = 0;
420
421
421
422
function ctSetCookie(c_name, value) {
@@ -429,7 +430,7 @@ function ctSetCookie(c_name, value) {
429
430
430
431
setTimeout(function(){
431
432
ctSetCookie("ct_checkjs", " ' .$ value .'");
432
- ctSetCookie("ct_timezone", d .getTimezoneOffset()/60*(-1));
433
+ ctSetCookie("ct_timezone", ct_date .getTimezoneOffset()/60*(-1));
433
434
},1000);
434
435
435
436
//Writing first key press timestamp
@@ -441,20 +442,24 @@ function ctSetCookie(c_name, value) {
441
442
442
443
//Reading interval
443
444
var ctMouseReadInterval = setInterval(function(){
444
- ctMouseEventTimerFlag = true;
445
- }, 150);
445
+ ctMouseEventTimerFlag = true;
446
+ }, 150);
446
447
447
448
//Writting interval
448
449
var ctMouseWriteDataInterval = setInterval(function(){
449
- var ctMouseDataToSend = ctMouseData.slice(0,-1).concat("]");
450
- ctSetCookie("ct_pointer_data", ctMouseDataToSend);
451
- }, 1200);
450
+ ctSetCookie("ct_pointer_data", JSON.stringify(ctMouseData));
451
+ }, 1200);
452
452
453
- //Logging mouse position each 300 ms
453
+ //Logging mouse position each 150 ms
454
454
var ctFunctionMouseMove = function output(event){
455
455
if(ctMouseEventTimerFlag == true){
456
- var mouseDate = new Date();
457
- ctMouseData += "[" + Math.round(event.pageY) + "," + Math.round(event.pageX) + "," + Math.round(mouseDate.getTime() - ctTimeMs) + "],";
456
+
457
+ ctMouseData.push([
458
+ Math.round(event.pageY),
459
+ Math.round(event.pageX),
460
+ Math.round(new Date().getTime() - ctTimeMs)
461
+ ]);
462
+
458
463
ctMouseDataCounter++;
459
464
ctMouseEventTimerFlag = false;
460
465
if(ctMouseDataCounter >= 100){
@@ -465,10 +470,11 @@ function ctSetCookie(c_name, value) {
465
470
466
471
//Stop mouse observing function
467
472
function ctMouseStopData(){
468
- if(typeof window.addEventListener == "function")
473
+ if(typeof window.addEventListener == "function"){
469
474
window.removeEventListener("mousemove", ctFunctionMouseMove);
470
- else
475
+ } else{
471
476
window.detachEvent("onmousemove", ctFunctionMouseMove);
477
+ }
472
478
clearInterval(ctMouseReadInterval);
473
479
clearInterval(ctMouseWriteDataInterval);
474
480
}
@@ -584,7 +590,7 @@ function cleantalk_load()
584
590
$ ct_request ->auth_key = cleantalk_get_api_key ();
585
591
$ ct_request ->feedback = '0: ' .CT_AGENT_VERSION ;
586
592
$ ct_result = $ ct ->sendFeedback ($ ct_request );
587
- // unset($ct, $ct_request);
593
+ unset($ ct , $ ct_request );
588
594
589
595
// Check if key is valid
590
596
if ($ _POST ['cleantalk_api_key ' ] != $ modSettings ['cleantalk_api_key ' ]){
@@ -604,9 +610,35 @@ function cleantalk_load()
604
610
false
605
611
);
606
612
613
+ }else {
614
+ updateSettings (
615
+ array (
616
+ 'cleantalk_api_key_is_ok ' => 0 ,
617
+ 'cleantalk_show_notice ' => 0 ,
618
+ 'cleantalk_renew ' => 0 ,
619
+ 'cleantalk_trial ' => 0 ,
620
+ 'cleantalk_user_token ' => '' ,
621
+ 'cleantalk_spam_count ' => 0 ,
622
+ 'cleantalk_moderate_ip ' => 0 ,
623
+ 'cleantalk_show_review ' => 0 ,
624
+ 'cleantalk_ip_license ' => 0 ,
625
+ )
626
+ );
607
627
}
608
- else
609
- updateSettings (array ('cleantalk_api_key_is_ok ' => '0 ' , false ));
628
+ }else {
629
+ updateSettings (
630
+ array (
631
+ 'cleantalk_api_key_is_ok ' => 0 ,
632
+ 'cleantalk_show_notice ' => 0 ,
633
+ 'cleantalk_renew ' => 0 ,
634
+ 'cleantalk_trial ' => 0 ,
635
+ 'cleantalk_user_token ' => '' ,
636
+ 'cleantalk_spam_count ' => 0 ,
637
+ 'cleantalk_moderate_ip ' => 0 ,
638
+ 'cleantalk_show_review ' => 0 ,
639
+ 'cleantalk_ip_license ' => 0 ,
640
+ )
641
+ );
610
642
}
611
643
}
612
644
@@ -618,7 +650,7 @@ function cleantalk_load()
618
650
619
651
// Deleting selected users
620
652
if (isset ($ _POST ['ct_del_user ' ]))
621
- {
653
+ {
622
654
checkSession ('request ' );
623
655
624
656
if (!isset ($ db_connection ) || $ db_connection === false )
@@ -657,7 +689,7 @@ function cleantalk_load()
657
689
}
658
690
659
691
/* Cron for update SFW */
660
- if (!empty ($ modSettings ['cleantalk_api_key_is_ok ' ]) && !empty ($ modSettings ['cleantalk_sfw ' ]) && isset ($ modSettings ['cleantalk_sfw_last_update ' ]) && $ modSettings ['cleantalk_sfw_last_update ' ] < time () || !empty ( $ doing_cron )){
692
+ if (!empty ($ modSettings ['cleantalk_sfw ' ]) && ( !empty ($ doing_cron ) || (! empty ( $ modSettings ['cleantalk_api_key_is_ok ' ]) && (( isset ($ modSettings ['cleantalk_sfw_last_update ' ]) && $ modSettings ['cleantalk_sfw_last_update ' ] < time ()) || !isset ( $ modSettings [ ' cleantalk_sfw_last_update ' ]) ) ) )){
661
693
662
694
$ sfw = new CleantalkSFW ;
663
695
$ sfw ->sfw_update ($ modSettings ['cleantalk_api_key ' ]);
@@ -667,7 +699,7 @@ function cleantalk_load()
667
699
}
668
700
669
701
/* Cron for send SFW logs */
670
- if (!empty ($ modSettings ['cleantalk_api_key_is_ok ' ]) && !empty ($ modSettings ['cleantalk_sfw ' ]) && isset ($ modSettings ['cleantalk_sfw_last_logs_sent ' ]) && $ modSettings ['cleantalk_sfw_last_logs_sent ' ] < time () || !empty ( $ doing_cron )){
702
+ if (!empty ($ modSettings ['cleantalk_sfw ' ]) && ( !empty ($ doing_cron ) || (! empty ( $ modSettings ['cleantalk_api_key_is_ok ' ]) && (( isset ($ modSettings ['cleantalk_sfw_last_logs_sent ' ]) && $ modSettings ['cleantalk_sfw_last_logs_sent ' ] < time ()) || !isset ( $ modSettings [ ' cleantalk_sfw_last_logs_sent ' ]) ) ) )){
671
703
672
704
$ sfw = new CleantalkSFW ;
673
705
$ sfw ->send_logs ($ modSettings ['cleantalk_api_key ' ]);
@@ -797,7 +829,7 @@ function template_cleantalk_above()
797
829
// }
798
830
799
831
// Bad key banner
800
- if (empty ($ modSettings ['cleantalk_api_key_is_ok ' ]) && (empty ($ _GET ['area ' ]) || (isset ($ _GET ['area ' ])&& $ _GET ['area ' ] != 'modsettings ' ))){
832
+ if (empty ($ modSettings ['cleantalk_api_key_is_ok ' ]) && (empty ($ _GET ['area ' ]) || (isset ($ _GET ['area ' ]) && $ _GET ['area ' ] != 'modsettings ' ))){
801
833
802
834
echo "<div style='margin-bottom: 1.2em; padding: 5px;'> "
803
835
."<h1> "
@@ -836,7 +868,7 @@ function cleantalk_buffer($buffer)
836
868
if (SMF == 'SSI ' )
837
869
return $ buffer ;
838
870
839
- if ($ user_info ['is_admin ' ] && isset ($ _GET ['action ' ], $ _GET ['area ' ]) && $ _GET ['action ' ] == 'admin ' && $ _GET ['area ' ] == 'modsettings ' ){// && false){
871
+ if ($ user_info ['is_admin ' ] && isset ($ _GET ['action ' ], $ _GET ['area ' ]) && $ _GET ['action ' ] == 'admin ' && $ _GET ['area ' ] == 'modsettings ' ){
840
872
841
873
if (strpos ($ forum_version , 'SMF 2.0 ' )===false ){
842
874
@@ -863,91 +895,76 @@ function cleantalk_buffer($buffer)
863
895
864
896
db_extend ('packages ' );
865
897
866
- $ cols = $ smcFunc ['db_list_columns ' ] ('{db_prefix}members ' , 0 );
898
+ // Unmark all users
899
+ $ sql = 'UPDATE {db_prefix}members SET ct_marked = 0 ' ;
900
+ $ result = $ smcFunc ['db_query ' ]('' , $ sql , Array ());
901
+ $ smcFunc ['db_free_result ' ]($ result );
867
902
868
- if (in_array ('ct_marked ' , $ cols )){
903
+ // Cicle params
904
+ $ offset = 0 ;
905
+ $ per_request = 500 ;
869
906
870
- $ sql = 'UPDATE {db_prefix}members set ct_marked=0 ' ;
871
- $ result = $ smcFunc ['db_query ' ]('' , $ sql , Array ());
872
- $ sql = 'SELECT * FROM {db_prefix}members where passwd<>"" ' ;
907
+ // Getting users to check
908
+ // Making at least one DB query
909
+ do {
910
+
911
+ $ sql = "SELECT id_member, member_name, date_registered, last_login, email_address, member_ip FROM {db_prefix}members where passwd <> '' LIMIT $ offset, $ per_request " ;
873
912
$ result = $ smcFunc ['db_query ' ]('' , $ sql , Array ());
874
- $ users =Array ();
875
- $ users [0 ]=Array ();
876
- $ data =Array ();
877
- $ data [0 ]=Array ();
878
- $ cnt =0 ;
913
+
914
+ // Break if result is empty.
915
+ if ($ smcFunc ['db_num_rows ' ] ($ result ) == 0 )
916
+ break ;
917
+
918
+ // Setting data
919
+ $ data = array ();
879
920
while ($ row = $ smcFunc ['db_fetch_assoc ' ] ($ result )){
880
-
881
- $ users [$ cnt ][] = array (
882
- 'name ' => $ row ['member_name ' ],
883
- 'id ' => $ row ['id_member ' ],
884
- 'email ' => $ row ['email_address ' ],
885
- 'ip ' => $ row ['member_ip ' ],
886
- 'joined ' => $ row ['date_registered ' ],
887
- 'visit ' => $ row ['last_login ' ],
888
- );
889
-
890
- $ data [$ cnt ][]=$ row ['email_address ' ];
891
- $ data [$ cnt ][]=$ row ['member_ip ' ];
892
-
893
- if (sizeof ($ users [$ cnt ])>450 ){
894
- $ cnt ++;
895
- $ users [$ cnt ]=Array ();
896
- $ data [$ cnt ]=Array ();
897
- }
921
+ $ data [] = $ row ['email_address ' ];
922
+ $ data [] = $ row ['member_ip ' ];
898
923
}
899
-
900
- $ error ="" ;
901
-
902
- for ($ i =0 ;$ i <sizeof ($ users );$ i ++){
903
- $ send =implode (', ' ,$ data [$ i ]);
904
- $ req ="data= $ send " ;
905
- $ opts = array (
906
- 'http ' =>array (
907
- 'method ' =>"POST " ,
908
- 'content ' =>$ req ,
909
- )
910
- );
911
-
912
- $ context = stream_context_create ($ opts );
913
- $ result = @file_get_contents ("https://api.cleantalk.org/?method_name=spam_check_cms&auth_key= " .cleantalk_get_api_key (), 0 , $ context );
914
- $ result =json_decode ($ result );
915
- if (isset ($ result ->error_message )){
916
- $ error =$ result ->error_message ;
917
- }else {
924
+
925
+ // Request
926
+ $ api_result = CleantalkHelper::spamCheckCms (cleantalk_get_api_key (), $ data );
927
+
928
+ // Error handling
929
+ if (!empty ($ api_result ['error ' ])){
930
+ break ;
931
+ }else {
918
932
919
- if (isset ($ result ->data )){
920
-
921
- foreach ($ result ->data as $ key =>$ value ){
922
-
923
- if ($ key === filter_var ($ key , FILTER_VALIDATE_IP )){
924
-
925
- if ($ value ->appears ==1 ){
926
-
927
- $ sql = 'UPDATE {db_prefix}members set ct_marked=1 where member_ip=" ' .$ key .'" ' ;
928
- $ result = $ smcFunc ['db_query ' ]('' , $ sql , Array ('db_error_skip ' => true ));
929
- }
930
-
931
- }else {
932
-
933
- if ($ value ->appears ==1 ){
934
- $ sql = 'UPDATE {db_prefix}members set ct_marked=1 where email_address=" ' .$ key .'" ' ;
935
- $ result = $ smcFunc ['db_query ' ]('' , $ sql , Array ('db_error_skip ' => true ));
936
- }
937
- }
933
+ foreach ($ api_result as $ key => $ value ){
934
+
935
+ // Mark spam users
936
+ if ($ key === filter_var ($ key , FILTER_VALIDATE_IP )){
937
+ if ($ value ['appears ' ] == 1 ){
938
+ $ sql = 'UPDATE {db_prefix}members set ct_marked=1 where member_ip=" ' .$ key .'" ' ;
939
+ $ sub_result = $ smcFunc ['db_query ' ]('' , $ sql , Array ('db_error_skip ' => true ));
940
+ $ smcFunc ['db_free_result ' ]($ sub_result );
941
+ }
942
+ }else {
943
+ if ($ value ['appears ' ] == 1 ){
944
+ $ sql = 'UPDATE {db_prefix}members set ct_marked=1 where email_address=" ' .$ key .'" ' ;
945
+ $ sub_result = $ smcFunc ['db_query ' ]('' , $ sql , Array ('db_error_skip ' => true ));
946
+ $ smcFunc ['db_free_result ' ]($ sub_result );
938
947
}
939
948
}
940
949
}
950
+ unset($ key , $ value );
941
951
}
952
+
953
+ $ offset += $ per_request ;
954
+
955
+ } while ( true );
956
+
957
+ // Free result when it's all done
958
+ $ smcFunc ['db_free_result ' ]($ result );
942
959
943
- if ( $ error != '' )
944
- $ html .= ' <center> '
945
- . ' <div style="border:2px solid red;color:red;font-size:16px;width:300px;padding:5px;" > '
946
- .'<b> ' . $ error . ' </b > '
947
- .'</div > '
948
- .'<br > '
949
- .'</center> ' ;
950
-
960
+ // Error output
961
+ if (! empty ( $ api_result [ ' error ' ])){
962
+ $ html .= ' <center > '
963
+ .'<div style="border:2px solid red;color:red;font-size:16px;width:300px;padding:5px;" > '
964
+ .'<b> ' . $ error . ' </b > '
965
+ .'</div > '
966
+ .'<br> '
967
+ . ' </center> ' ;
951
968
}
952
969
953
970
$ sql = "SELECT * FROM {db_prefix}members WHERE ct_marked=1 " ;
@@ -972,7 +989,7 @@ function cleantalk_buffer($buffer)
972
989
$ sql = "SELECT * FROM {db_prefix}members WHERE ct_marked=1 LIMIT $ offset, $ on_page " ;
973
990
$ result = $ smcFunc ['db_query ' ]('' , $ sql , Array ());
974
991
975
- if ($ pages && $ pages != 1 ){
992
+ if ($ pages > 1 ){
976
993
$ html .= "<div style='margin: 10px;'> "
977
994
."<b> " .$ txt ['cleantalk_check_users_pages ' ].":</b> "
978
995
."<ul style='display: inline-block; margin: 0; padding: 0;'> " ;
@@ -1020,7 +1037,7 @@ function cleantalk_buffer($buffer)
1020
1037
1021
1038
$ html .="</tbody></table></center> " ;
1022
1039
1023
- if ($ pages && $ pages != 1 ){
1040
+ if ($ pages > 1 ){
1024
1041
$ html .= "<div style='margin: 10px;'> "
1025
1042
."<b> " .$ txt ['cleantalk_check_users_pages ' ].":</b> "
1026
1043
."<ul style='display: inline-block; margin: 0; padding: 0;'> " ;
0 commit comments