Skip to content

Commit

Permalink
Domain verification is now possible. Close #3
Browse files Browse the repository at this point in the history
  • Loading branch information
mikasjp committed Mar 23, 2018
1 parent 0258770 commit 1db4073
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
10 changes: 7 additions & 3 deletions admin/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@
<label for="WP_ABUSESHIELD_ADMIN_APIKEY">AbuseIPDB API key:</label><br>
<input type="text" name="WP_ABUSESHIELD_ADMIN_APIKEY" id="WP_ABUSESHIELD_ADMIN_APIKEY" size="40" value="<?php echo $admin->plugin->config->config["APIKey"]; ?>">
</div>
<div class="wp-abuseshield-config-row">
<label for="WP_ABUSESHIELD_ADMIN_DVC">AbuseIPDB domain verification code:</label><br>
<input type="text" name="WP_ABUSESHIELD_ADMIN_DVC" id="WP_ABUSESHIELD_ADMIN_DVC" size="40" value="<?php echo $admin->plugin->config->config["DVC"]; ?>">
</div>
<div class="wp-abuseshield-config-row">
<input type="submit" name="WP_ABUSESHIELD_ADMIN_SUBMIT" class="button button-primary" value="Save">
</div>
<input name="WP_ABUSESHIELD_ADMIN_NONCE" type="hidden" value="<?php echo $WP_ABUSESHIELD_ADMIN_NONCE; ?>" />
<input name="WP_ABUSESHIELD_ADMIN_NONCE" type="hidden" value="<?php echo $WP_ABUSESHIELD_ADMIN_NONCE; ?>">
</form>
</div>
</td></tr>
Expand All @@ -41,7 +45,7 @@
<div class="wp-abuseshield-config-row">
<input type="submit" name="WP_ABUSESHIELD_ADMIN_RESET_SECRET" class="button button-primary" value="Reset Secret Token">
</div>
<input name="WP_ABUSESHIELD_ADMIN_NONCE" type="hidden" value="<?php echo $WP_ABUSESHIELD_ADMIN_NONCE; ?>" />
<input name="WP_ABUSESHIELD_ADMIN_NONCE" type="hidden" value="<?php echo $WP_ABUSESHIELD_ADMIN_NONCE; ?>">
</form>
</div>
</td></tr>
Expand All @@ -55,7 +59,7 @@
<div class="wp-abuseshield-config-row">
<input type="submit" name="WP_ABUSESHIELD_ADMIN_CLEAR_CACHE" class="button button-primary" value="Clear Cache">
</div>
<input name="WP_ABUSESHIELD_ADMIN_NONCE" type="hidden" value="<?php echo $WP_ABUSESHIELD_ADMIN_NONCE; ?>" />
<input name="WP_ABUSESHIELD_ADMIN_NONCE" type="hidden" value="<?php echo $WP_ABUSESHIELD_ADMIN_NONCE; ?>">
</form>
</div>
</td></tr>
Expand Down
1 change: 1 addition & 0 deletions admin/class-wp-abuseshield-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ protected function ParseRequests()
if(isset($_POST["WP_ABUSESHIELD_ADMIN_SUBMIT"]) && $this->VerifyCSRFNonce())
{
$this->plugin->config->config["APIKey"] = htmlspecialchars($_POST["WP_ABUSESHIELD_ADMIN_APIKEY"]);
$this->plugin->config->config["DVC"] = htmlspecialchars($_POST["WP_ABUSESHIELD_ADMIN_DVC"]);
$this->plugin->config->SaveConfig();
$this->ShowMessage("The configuration has been saved successfully");
}
Expand Down
3 changes: 2 additions & 1 deletion include/class-wp-abuseshield-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public function __construct()
{
$this->config = [];
$this->config["APIKey"] = "";
$this->config["DVC"] = "";
$this->config["Secret"] = $this->GenerateSecret();
$this->config["CacheExpiration"] = 24;
$this->SaveConfig();
Expand All @@ -35,7 +36,7 @@ public function SaveConfig()

public function GenerateSecret()
{
return sha1(time()."#".rand(0, 1000000));
return sha1(time()."#".rand(0, 1000000000));
}

}
13 changes: 11 additions & 2 deletions wp-abuseshield.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

require_once plugin_dir_path( __FILE__ ) . "include/class-wp-abuseshield.php";

$WPAbuseShield = new Wp_Abuseshield();

function activate_wp_abuseshield()
{
global $wpdb;
Expand All @@ -34,7 +36,7 @@ function deactivate_wp_abuseshield()

function run_wp_abuseshield()
{
$WPAbuseShield = new Wp_Abuseshield();
global $WPAbuseShield;
$WPAbuseShield->Run();
}

Expand All @@ -44,6 +46,12 @@ function EnqueueAdminStyle()
wp_enqueue_style("wp_abuseshield_admin_css");
}

function wp_abuseshield_add_verification_tag()
{
if(!empty($WPAbuseShield->config->config["DVC"]))
echo '<meta name="abuseipdb-verification" content="'.$WPAbuseShield->config->config["DVC"].'">';
}

function wp_abuseshield_admin_panel()
{
DEFINE("WP_ABUSESHIELD_ADMIN", true);
Expand All @@ -63,4 +71,5 @@ function wp_abuseshield_setup_menu()
register_deactivation_hook( __FILE__, "deactivate_wp_abuseshield");

add_action('admin_menu', 'wp_abuseshield_setup_menu');
add_action('admin_enqueue_scripts', 'EnqueueAdminStyle');
add_action('admin_enqueue_scripts', 'EnqueueAdminStyle');
add_action("wp_head", "wp_abuseshield_add_verification_tag");

0 comments on commit 1db4073

Please sign in to comment.