Skip to content

Commit

Permalink
Updated verification and notification process
Browse files Browse the repository at this point in the history
  • Loading branch information
turnermm committed Dec 16, 2016
1 parent 396cdef commit 9910593
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 4 deletions.
59 changes: 58 additions & 1 deletion action.php
Expand Up @@ -39,11 +39,16 @@ function dw_start(&$event, $param)
if(!$this->is_allowed($allowed, $test)) {
msg("$test is not a valid IP");
}
else msg("$test is a valid IP",2);
else {
$ret = $this->saved_data($ip, 1);
msg($ret,2);
}
}
return;
}



if($ACT == 'login' && !$this->is_allowed($allowed, $ip)) {
if($this->getConf('log')) {
$this->log($ip);
Expand All @@ -70,8 +75,60 @@ function is_allowed($allowed, $ip) {
if(!$allowed || preg_match("/" . $allowed . "/", $ip) ) { // if allowed string is empty then all ips are allowed
return true;
}

if ($this->saved_data($ip)) {
msg("This IP has been verified. You should notify the wiki admin.");
$this->abortnotify($ip);
return true;
}
return false;
}
function abortnotify($ip) {
global $USERINFO;
if (empty($USERINFO)) return;

$mail = new Mailer();
$uname = $USERINFO['name'];
$umail = $USERINFO['mail'];
$user = "$uname<$umail>";
$admin = $this->getConf('admin_mail') ;
$body = "IP $ip ";
if(!$admin) {
$to = $user;
$body .= $this->getLang('user_notice');
}
else {
$to = $admin;
$mail->cc($user);
$body .= $this->getLang('admin_notice');
}

$mail->to($to);
$mail->subject($this->getLang('verified'));
$mail->setBody($body);
$mail->send();
}

function saved_data($ip, $test = false) {
$saved_data = false;
$file = metaFN('abortlogin:data','.ser') ;

if(file_exists($file)) {
$user_data = unserialize(file_get_contents($file));
}
else $user_data = array();

if(empty($user_data[$ip]) && $test) {
$user_data[$ip] = 1;
if(io_saveFile($file, serialize($user_data))) return "$ip saved in test db";
return "Unable to save $ip in test db. Please check meta/abortlogin permissions";
}
else if(key_exists($ip,$user_data)) {
return "IP Address is valid";
}
return false;
}


function log($ip) {
$log = metaFN('abortlogin:aborted_ip','.log');
Expand Down
2 changes: 1 addition & 1 deletion conf/default.php
Expand Up @@ -2,6 +2,6 @@
$conf['allowed'] = '';
$conf['test'] = '';
$conf['log'] = 0;

$conf['admin_mail'] = "";


1 change: 1 addition & 0 deletions conf/metadata.php
Expand Up @@ -2,3 +2,4 @@
$meta['allowed'] = array('string');
$meta['test'] = array('string');
$meta['log'] = array('onoff');
$meta['admin_mail'] = array('string');
4 changes: 4 additions & 0 deletions lang/en/lang.php
@@ -0,0 +1,4 @@
<?php
$lang['verified'] = 'IP has been verified for use in this wiki.';
$lang['user_notice'] = 'has been verified. Ask your admin to add it to the allowed list.';
$lang['admin_notice'] = ' should be added to the allowed list and removed from the test list, if it has not already been';
3 changes: 2 additions & 1 deletion lang/en/settings.php
@@ -1,4 +1,5 @@
<?php
$lang['allowed'] = "Comma separated list of allowed ip addresses";
$lang['test'] = "Comma separated list of ip addresses to test; testing limited to admins only";
$lang['log'] ="Keep a log of failed login attempts";
$lang['log'] ="Keep a log of failed login attempts";
$lang['admin_mail'] = "Administrator's email (required for notifications)";
2 changes: 1 addition & 1 deletion plugin.info.txt
@@ -1,7 +1,7 @@
base abortlogin
author Myron Turner
email turnermm02@shaw.ca
date 2015-12-20
date 2016-12-15
name abortlogin
desc prevents attempt to login from non-accepted ips
url https://www.dokuwiki.org/plugin:abortlogin
Expand Down

0 comments on commit 9910593

Please sign in to comment.