Plugin Directory

Changeset 2376893


Ignore:
Timestamp:
09/08/2020 04:56:54 AM (5 years ago)
Author:
devoutpro
Message:

release 1.14
Manual upload of data to the backend system for analysis is done

Location:
nomore404-404-redirection-and-firewall
Files:
2397 added
1 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • nomore404-404-redirection-and-firewall/trunk/includes/nomore404-activation.php

    r2368272 r2376893  
    3838   
    3939    $obj_settings = new NoMore404_Settings();
    40     NoMore404_Model_Static_Class::good_error_log('settings:', $obj_settings);
     40    //NoMore404_Model_Static_Class::good_error_log('settings:', $obj_settings);
    4141   
    4242    $table_name1 = $prefix . "nomore404_uri";
     
    7070                                ADD whitelist TINYINT(1) NOT NULL DEFAULT '0'";
    7171            $result = $wpdb->query($update_query1);
    72             NoMore404_Model_Static_Class::good_error_log('Table 1 update 1 result:', $result);
     72            //NoMore404_Model_Static_Class::good_error_log('Table 1 update 1 result:', $result);
    7373
    7474        }
     
    7777                                ADD comment VARCHAR(50) NULL";
    7878            $result = $wpdb->query($update_query1);
    79             NoMore404_Model_Static_Class::good_error_log('Table 1 update 2 result:', $result);
     79            //NoMore404_Model_Static_Class::good_error_log('Table 1 update 2 result:', $result);
    8080        }
    8181        if($obj_settings->options['dbversion'] < '1.13'){ // alter table here if before v 1.13
     
    8383                                ADD uploaded TINYINT(1) NOT NULL DEFAULT '0'";
    8484            $result = $wpdb->query($update_query1);
    85             NoMore404_Model_Static_Class::good_error_log('Table 1 update 3 result:', $result);
     85            //NoMore404_Model_Static_Class::good_error_log('Table 1 update 3 result:', $result);
    8686        }
    8787       
    8888        $table1updated = True;
    89         NoMore404_Model_Static_Class::var_error_log('Table 1 updated:', $table1updated);
     89        //NoMore404_Model_Static_Class::var_error_log('Table 1 updated:', $table1updated);
    9090    }
    9191
     
    175175        $obj_settings->SetLatestVersions();
    176176    }
    177     NoMore404_Model_Static_Class::good_error_log('settings:', $obj_settings);
     177    //NoMore404_Model_Static_Class::good_error_log('settings:', $obj_settings);
    178178}   
    179179
  • nomore404-404-redirection-and-firewall/trunk/includes/nomore404-list-table-class.php

    r2368272 r2376893  
    866866        $data = NoMore404_Model_Static_Class::getCallers($orderby, $order, $search, $uriid, $current_page, $per_page);
    867867       
     868        //NoMore404_Model_Static_Class::good_error_log('Callers in list class:', $data);
     869       
    868870        $total_items = NoMore404_Model_Static_Class::countCallers($search, $uriid);
    869871       
  • nomore404-404-redirection-and-firewall/trunk/includes/nomore404-model.php

    r2368272 r2376893  
    4848       
    4949        $query = 'SELECT * FROM ' . self::$uri_caller_table_name;
    50         $query .= ' WHERE uploaded <> 1 AND ';
    51         $query .=       '(';
    52         $query .=           'caller_id IN ';
    53         $query .=               '(SELECT uc.caller_id FROM ' . self::$caller_table_name . ' uc ';
    54         $query .=                   'WHERE uc.uploaded <> 1 AND (uc.whitelist = 1 OR uc.malicious = 1 OR uc.suspicious = 1)';
    55         $query .=               ') OR ';
    56         $query .=           'uri_id IN ';
    57         $query .=               '(SELECT uu.uri_id FROM ' . self::$uri_table_name . ' uu ';
    58         $query .=                   'WHERE uu.uploaded <> 1 AND (uu.whitelist = 1 OR uu.malicious = 1 OR uu.suspicious = 1) ';
    59         $query .=               ') ';
    60         $query .=        ') ';       
     50        $query .= ' WHERE uploaded <> 1';       
    6151        $query .= ' ORDER BY uri_id';
    6252
     
    6454       
    6555        if($markuploaded){
    66             $query = 'UPDATE ' . self::$uri_caller_table_name . ' SET uploaded = 1';
    67             $query .= ' WHERE uploaded <> 1 AND ';
    68             $query .=       '(';
    69             $query .=           'caller_id IN ';
    70             $query .=               '(SELECT uc.caller_id FROM ' . self::$caller_table_name . ' uc ';
    71             $query .=                   'WHERE uc.uploaded <> 1 AND (uc.whitelist = 1 OR uc.malicious = 1 OR uc.suspicious = 1)';
    72             $query .=               ') OR ';
    73             $query .=           'uri_id IN ';
    74             $query .=               '(SELECT uu.uri_id FROM ' . self::$uri_table_name . ' uu ';
    75             $query .=                   'WHERE uu.uploaded <> 1 AND (uu.whitelist = 1 OR uu.malicious = 1 OR uu.suspicious = 1) ';
    76             $query .=               ') ';
    77             $query .=        ') ';       
     56            $query = 'UPDATE ' . self::$uri_caller_table_name . ' SET uploaded = 1, date_uploaded = UTC_TIMESTAMP()';
     57            $query .= ' WHERE uploaded <> 1';       
    7858            $query .= ' ORDER BY uri_id';           
    7959            $wpdb->query($query);
     
    9575       
    9676        if($markuploaded){
    97             $query = 'UPDATE ' . self::$uri_table_name . ' SET uploaded = 1';
     77            $query = 'UPDATE ' . self::$uri_table_name . ' SET uploaded = 1, date_uploaded = UTC_TIMESTAMP()';
    9878            $query .= ' WHERE uploaded <> 1 AND (whitelist = 1 OR malicious = 1 OR suspicious = 1)';
    9979            $wpdb->query($query);
     
    11696       
    11797        if($markuploaded){
    118             $query = 'UPDATE ' . self::$caller_table_name . ' SET uploaded = 1';
     98            $query = 'UPDATE ' . self::$caller_table_name . ' SET uploaded = 1, date_uploaded = UTC_TIMESTAMP()';
    11999            $query .= ' WHERE uploaded <> 1 AND (whitelist = 1 OR malicious = 1 OR suspicious = 1)';
    120100            $wpdb->query($query);
     
    175155             $output = $wpdb->insert_id;
    176156         } catch (Exception $ex) {
    177             self::good_error_log('Caught URICaller insert error:',$ex->getMessage());
     157            //self::good_error_log('Caught URICaller insert error:',$ex->getMessage());
    178158            return False; // if insert did not work - return false
    179159         }
     
    188168                            array('uri_id' => $uri_id, 'caller_id' => $caller_id));
    189169         } catch (Exception $ex) {
    190             self::good_error_log('Caught URICaller update error:',$ex->getMessage());
     170            //self::good_error_log('Caught URICaller update error:',$ex->getMessage());
    191171            return False; // if insert did not work - return false
    192172         }
     
    219199             $output = $wpdb->insert_id;
    220200         } catch (Exception $ex) {
    221             self::good_error_log('Caught Caller insert error:',$ex->getMessage());
     201            //self::good_error_log('Caught Caller insert error:',$ex->getMessage());
    222202            return False; // if insert did not work - return false
    223203         }
     
    232212            $output = $wpdb->update(self::$caller_table_name, $caller_data, array('caller_id' => $caller_id));
    233213         } catch (Exception $ex) {
    234             self::good_error_log('Caught Caller update error:',$ex->getMessage());
     214            //self::good_error_log('Caught Caller update error:',$ex->getMessage());
    235215            return False; // if update did not work - return false
    236216         }
     
    256236            );
    257237         } catch (Exception $ex) {
    258             self::good_error_log('Caught Caller delete error:',$ex->getMessage());
     238            //self::good_error_log('Caught Caller delete error:',$ex->getMessage());
    259239            return False; // if update did not work - return false
    260240         }
     
    266246        global $wpdb;
    267247       
    268         self::good_error_log('Counting callers by URIid:', $filteruriid);
     248        //self::good_error_log('Counting callers by URIid:', $filteruriid);
    269249       
    270250        if('' == $filteruriid ){ // if not filtered  then normal sort and search applies       
     
    299279           
    300280        }
    301         self::good_error_log('Running query:', $cleanedsql);
     281        //self::good_error_log('Running query:', $cleanedsql);
    302282        $num = (int) $wpdb->get_var($cleanedsql);
    303         self::good_error_log('Number of records:', $num);
     283        //self::good_error_log('Number of records:', $num);
    304284        return $num;
    305285    }
     
    329309            }   
    330310        }else{
    331             $query = 'SELECT * FROM ' . self::$caller_table_name . ' c ';
     311            // prepare list of fields
     312            $listOfFieldsToGet = 'c.caller_id, c.caller_ip, c.comment, c.hostname, c.date_created, c.date_last_used,
     313                                    c.counter, c.suspicious, c.malicious, c.whitelist, c.uploaded';
     314                   
     315            // form query
     316            $query = 'SELECT ' . $listOfFieldsToGet . ' FROM ' . self::$caller_table_name . ' c ';
    332317            $query .= 'INNER JOIN ' . self::$uri_caller_table_name . ' uc ';
    333318            $query .= 'ON c.caller_id = uc.caller_id and uc.uri_id = %d';
     
    349334        }
    350335        $output = $wpdb->get_results($cleanedsql, ARRAY_A);
     336        //NoMore404_Model_Static_Class::good_error_log('SQL  in model class:', $cleanedsql);
     337        //NoMore404_Model_Static_Class::good_error_log('Callers in model class:', $output);
    351338        return $output;
    352339    }
     
    370357            );
    371358         } catch (Exception $ex) {
    372             self::good_error_log('Caught URI delete error:',$ex->getMessage());
     359            //self::good_error_log('Caught URI delete error:',$ex->getMessage());
    373360            return False; // if update did not work - return false
    374361         }
     
    481468        return $uri_data;
    482469    }
     470   
    483471    public static  function InsertURI($uri_data) {
    484472         global $wpdb;
     
    488476             $output = $wpdb->insert_id;
    489477         } catch (Exception $ex) {
    490             self::good_error_log('Caught insert error:',$ex->getMessage());
     478            //self::good_error_log('Caught insert error:',$ex->getMessage());
    491479            return False; // if insert did not work - return false
    492480         }
     
    501489            $output = $wpdb->update(self::$uri_table_name, $uri_data, array('uri_id' => $uri_id));
    502490         } catch (Exception $ex) {
    503             self::good_error_log('Caught update error:',$ex->getMessage());
     491            //self::good_error_log('Caught update error:',$ex->getMessage());
    504492            return $output; // if insert did not work - return false
    505493         }
  • nomore404-404-redirection-and-firewall/trunk/includes/nomore404-upload-download.php

    r2368272 r2376893  
    2727    // if not uploaded then all changes to uploaded flag will be rolled back
    2828    public static function UploadAllNewData($dofullupload = false) {
     29        global $wpdb;
     30       
    2931        // Start Transaction
    3032        $wpdb->query( "START TRANSACTION" );   
     
    3335        $strJSON = Self::CreateJSON4Upload(FALSE); // what was not uploaded yet
    3436       
     37        //NoMore404_Model_Static_Class::good_error_log('Uploading info:', $strJSON);
     38       
    3539        if(FALSE !== $strJSON){ // there is something to upload
    3640            $uploaded = self::UploadStringAsFile2S3($strJSON);
    3741       
    38             if($uploaded) $wpdb->query( "ROLLBACK" );
     42            if($uploaded) $wpdb->query( "COMMIT" );
    3943            else $wpdb->query( "ROLLBACK" );
    4044        }else{
     
    7882                'ACL' => 'bucket-owner-full-control',
    7983            ]);
    80             NoMore404_Model_Static_Class::good_error_log('S3UploadResult:', $result);
     84            //NoMore404_Model_Static_Class::good_error_log('S3UploadResult:', $result);
     85            //NoMore404_Model_Static_Class::good_error_log('File uploaded:', $file2upload);
    8186           
    8287            // returns true if uploaded
     
    113118        $strJSONText .= '"wp_version": "' . get_bloginfo('version') . '",' . PHP_EOL; // wordpress verson
    114119        $strJSONText .= '"version": "' . NOMORE404VERSION . '",' . PHP_EOL; // plug in versions
    115         $strJSONText .= '"dbversion": "' . NOMORE404DBVERSION . '",' . PHP_EOL; //
    116         $strJSONText .= '"Callers": '; // start of caller records
     120        $strJSONText .= '"dbversion": "' . NOMORE404DBVERSION . '"'; //
     121       
    117122   
    118123        // lets get callers data
    119         // first get data what was not uploaded yet
     124        // first get data what was not uploaded yet and mark them uploaded as well in transaction
    120125        $callers2upload = NoMore404_Model_Static_Class::getCallersForUpload(TRUE);
    121126        //NoMore404_Model_Static_Class::good_error_log('Callers:', $callers2upload);
    122         if(NULL !== $callers2upload){ // there is something to take in
     127        //NoMore404_Model_Static_Class::var_error_log('Callers to upload:',$callers2upload);
     128        if((NULL !== $callers2upload) && (is_array($callers2upload) && sizeof($callers2upload) > 0)){
     129        // there is something to take in, it is array with at least one element
    123130            //NoMore404_Model_Static_Class::good_error_log('Callers:', $callers2upload);
    124131            //NoMore404_Model_Static_Class::good_error_log('CallersJSON:', json_encode($callers2upload, JSON_FORCE_OBJECT));
    125             $strJSONText .= json_encode($callers2upload, JSON_PRETTY_PRINT) . ',' . PHP_EOL;
     132            $strJSONText .= ',' . PHP_EOL . '",Callers": '; // start of caller records
     133            $strJSONText .= json_encode($callers2upload, JSON_PRETTY_PRINT);
    126134            $thereIsSomethingToUpload = TRUE;
    127135            //NoMore404_Model_Static_Class::good_error_log('JSON error:',json_last_error_msg());
     
    129137       
    130138       
    131         $strJSONText .= '"URIs": '; // start of URIs records
     139
    132140        $URIs2upload = NoMore404_Model_Static_Class::getURIsForUpload(TRUE); // get data what was not uploaded yet
    133         if(NULL !== $URIs2upload){ // there is something to take in
    134             $strJSONText .= json_encode($URIs2upload, JSON_PRETTY_PRINT) . ',' . PHP_EOL;
     141        if(NULL !== $URIs2upload && (is_array($URIs2upload) && sizeof($URIs2upload) > 0)){
     142            $strJSONText .=  ',' . PHP_EOL . '"URIs": '; // start of URIs records
     143            // there is something to take in, it is array with at least one element
     144            $strJSONText .= json_encode($URIs2upload, JSON_PRETTY_PRINT);
    135145            $thereIsSomethingToUpload = TRUE;
    136146        }
    137147
    138         $strJSONText .= '"URICaller": '; // start of URIs records
     148       
    139149        $URICaller2upload = NoMore404_Model_Static_Class::getURICallerForUpload(TRUE); // get data what was not uploaded yet
    140150        //NoMore404_Model_Static_Class::good_error_log('$URICaller2upload:', $URICaller2upload);
    141         if(NULL !== $URICaller2upload){ // there is something to take in
     151        if(NULL !== $URICaller2upload && (is_array($URICaller2upload) && sizeof($URICaller2upload) > 0)){
     152            $strJSONText .= ',' . PHP_EOL . '"URICaller": '; // start of URIs records
     153            // there is something to take in, it is array with at least one element
    142154            $strJSONText .= json_encode($URICaller2upload, JSON_PRETTY_PRINT) . PHP_EOL;
    143155            $thereIsSomethingToUpload = TRUE;
  • nomore404-404-redirection-and-firewall/trunk/includes/nomore404-view.php

    r2368272 r2376893  
    216216        $output .= '</tr>' . PHP_EOL;
    217217       
     218        $output .= '<td>Date Uploaded</td>' . PHP_EOL;
     219        $output .= '<td>' . esc_attr($uri_data['date_uploaded']) . '</td>' . PHP_EOL;
     220        $output .= '</tr>' . PHP_EOL;
     221        $output .= '<tr>' . PHP_EOL;
     222
     223        $output .= '<td>Date Downloaded</td>' . PHP_EOL;
     224        $output .= '<td>' . esc_attr($uri_data['date_downloaded']) . '</td>' . PHP_EOL;
     225        $output .= '</tr>' . PHP_EOL;
     226        $output .= '<tr>' . PHP_EOL;     
     227       
     228        $output .= '<tr>' . PHP_EOL;
     229        $output .= '<td>Uploaded</td>' . PHP_EOL;
     230        $output .= '<td><input type="checkbox" name="uploaded" value="Enabled" '
     231                . checked($uri_data['uploaded'], true, false) . '>' . PHP_EOL;
     232        $output .= '</td>' . PHP_EOL;
     233        $output .= '</tr>' . PHP_EOL;
     234       
    218235        $output .= '</table>' . PHP_EOL;
    219236        echo $output;
     
    255272        $output .= '</tr>' . PHP_EOL;
    256273        $output .= '<tr>' . PHP_EOL;
     274       
    257275        $output .= '<td>Date Last Used</td>' . PHP_EOL;
    258276        $output .= '<td>' . esc_attr($caller_data['date_last_used']) . '</td>' . PHP_EOL;
    259277        $output .= '</tr>' . PHP_EOL;
    260278        $output .= '<tr>' . PHP_EOL;
     279       
    261280        $output .= '<td>Counter</td>' . PHP_EOL;
    262281        $output .= '<td>' . esc_attr($caller_data['counter']) . '</td>' . PHP_EOL;
    263282        $output .= '</tr>' . PHP_EOL;       
    264283        $output .= '<tr>' . PHP_EOL;
     284       
    265285        $output .= '<td>Suspicious</td>' . PHP_EOL;
    266286        $output .= '<td><input type="checkbox" name="suspicious" value="Enabled" '
     
    282302        $output .= '</td>' . PHP_EOL;
    283303        $output .= '</tr>' . PHP_EOL;
     304       
     305        $output .= '<td>Date Uploaded</td>' . PHP_EOL;
     306        $output .= '<td>' . esc_attr($caller_data['date_uploaded']) . '</td>' . PHP_EOL;
     307        $output .= '</tr>' . PHP_EOL;
     308        $output .= '<tr>' . PHP_EOL;
     309
     310        $output .= '<td>Date Downloaded</td>' . PHP_EOL;
     311        $output .= '<td>' . esc_attr($caller_data['date_downloaded']) . '</td>' . PHP_EOL;
     312        $output .= '</tr>' . PHP_EOL;
     313        $output .= '<tr>' . PHP_EOL;     
     314       
     315        $output .= '<tr>' . PHP_EOL;
     316        $output .= '<td>Uploaded</td>' . PHP_EOL;
     317        $output .= '<td><input type="checkbox" name="uploaded" value="Enabled" '
     318                . checked($caller_data['uploaded'], true, false) . '>' . PHP_EOL;
     319        $output .= '</td>' . PHP_EOL;
     320        $output .= '</tr>' . PHP_EOL;       
    284321       
    285322        $output .= '</table>' . PHP_EOL;
  • nomore404-404-redirection-and-firewall/trunk/nomore404.php

    r2368272 r2376893  
    44 * Plugin URI:          https://devoutpro.com/nomore404
    55 * Description:         NoMore404 is a free WordPress plugin for redirection of 404 pages (301 type of redirection) and simple firewall to block malicious hosts and URLs.
    6  * Version:             1.13
     6 * Version:             1.14
    77 * Requires at least:   4.0
    88 * Requires PHP:        5.3
     
    3232defined('ABSPATH') or exit;
    3333
    34 define("NOMORE404VERSION", "1.13");
    35 define("NOMORE404DBVERSION", "1.13");
     34define("NOMORE404VERSION", "1.14");
     35define("NOMORE404DBVERSION", "1.14");
    3636
    3737// plugin activation and uninstallation
     
    343343                        if (isset($_SESSION['uri_data']))
    344344                            $uri_data = array_merge($uri_data,$_SESSION['uri_data']);
    345                         //NoMore404_Model_Static_Class::var_error_log('URI data after merge: ', $uri_data);
    346345                    }elseif ('edit' === $_GET['mode']) { // edit existing uri
    347346                        $uri_id = (int) $_GET['id'];
     
    430429   
    431430    if (isset($_POST['btnUpload'])) { // button upload clicked
    432         //NoMore404_Model_Static_Class::good_error_log('Uploading...', $_POST);
    433431        $uploaded = NoMore404_UD_Static_Class::UploadAllNewData();
    434432        if($uploaded)
     
    504502    $caller_data['malicious'] = ( isset($_POST['malicious']) ? True : False );
    505503    $caller_data['whitelist'] = ( isset($_POST['whitelist']) ? True : False );
     504    $caller_data['uploaded'] = ( isset($_POST['uploaded']) ? True : False );
    506505   
    507506    if($caller_data['malicious']) $caller_data['suspicious'] = True; // malicious is stronger
     
    584583    $uri_data['malicious'] = ( isset($_POST['malicious']) ? True : False );
    585584    $uri_data['whitelist'] = ( isset($_POST['whitelist']) ? True : False );
     585    $uri_data['uploaded'] = ( isset($_POST['uploaded']) ? True : False );
    586586   
    587587    $_SESSION['uri_data'] = $uri_data; // save uri data in session
     
    799799        ?>
    800800        <div class="notice notice-error is-dismissible">
    801             <p><?php _e('Upload did not work, contact support.'); ?></p>
     801            <p><?php _e('Upload did not work, possibly nothing to upload.'); ?></p>
    802802        </div>   
    803803        <?php
  • nomore404-404-redirection-and-firewall/trunk/readme.txt

    r2368272 r2376893  
    66Tested up to: 5.5
    77Requires PHP: 5.3
    8 Stable tag: 1.13
     8Stable tag: 1.14   
    99License: GPLv2
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3030
    3131== Changelog ==
     321.14 Manual upload of data to the backend system for analysis is done
    32331.13 Fixed activation and db upgrade errors.
    3334     Uploading whitelists, suspects and  blacklists to the backend
Note: See TracChangeset for help on using the changeset viewer.