From 951cf72ef747d4ff2b4a8d8859d4a2d0556fbf58 Mon Sep 17 00:00:00 2001 From: johnsnook Date: Sat, 30 Jun 2018 20:18:09 -0400 Subject: [PATCH] Fixed blowoff bug, migration bug and added screenshots. --- Module.php | 19 ++++++++++--------- README.md | 18 +++++++++++++++++- controllers/VisitorController.php | 6 ++---- ...222_create_table_visitor_service_error.php | 16 +++++++--------- views/visitor/blowoff.php | 19 ++++++++++++++----- 5 files changed, 50 insertions(+), 28 deletions(-) diff --git a/Module.php b/Module.php index e71a293..dff0db9 100644 --- a/Module.php +++ b/Module.php @@ -32,7 +32,7 @@ * @property array $ignorables Array of controller actions and IPs to ignore * @property array $urlRules Array of rules for a UrlManger configured to pretty Url * - * @author John Snook The masta with a blasta + * @author John Snook */ class Module extends BaseModule implements BootstrapInterface { @@ -69,7 +69,7 @@ class Module extends BaseModule implements BootstrapInterface { /** * @var string The route to your blowoff page telling the user to pound sand */ - public $blowOff = 'visitor/blowoff'; + public $blowOff = 'ipFilter/visitor/blowoff'; /** * @var string $ipInfoKey Go to https://ipinfo.io/signup for a free API key @@ -104,11 +104,11 @@ class Module extends BaseModule implements BootstrapInterface { /** @var array The rules to be used in URL management. */ public $urlRules = [ // 'visitor/' => '/ipFilter/visitor/', - 'visitor' => '/ipFilter/visitor/index', - 'visitor/index' => '/ipFilter/visitor/index', - 'visitor/blowoff' => '/ipFilter/visitor/blowoff', - 'visitor/' => 'ipFilter/visitor/view', - 'visitor/update/' => 'ipFilter/visitor/update', + 'visitor' => 'ipFilter/visitor/index', + '/visitor/index' => 'ipFilter/visitor/index', + '/visitor/blowoff' => 'ipFilter/visitor/blowoff', + '/visitor/' => '/ipFilter/visitor/view', + '/visitor/update/' => '/ipFilter/visitor/update', ]; /** @@ -129,9 +129,10 @@ public function init() { */ public function bootstrap($app) { + if ($app->hasModule('ipFilter') && ($module = $app->getModule('ipFilter')) instanceof Module) { $app->getUrlManager()->addRules($this->urlRules, false); - + //die(json_encode($app->getUrlManager()->rules)); /** this allows me to do some importing from my old security system */ if ($app instanceof \yii\console\Application) { $this->controllerNamespace = 'johnsnook\ipFilter\commands'; @@ -184,7 +185,7 @@ public function metalDetector(ActionEvent $event) { return true; } elseif (!$alreadyFuckingOff && $visitor->is_blacklisted) { $event->handled = true; - return \Yii::$app->getResponse()->redirect([$this->blowOff, 'visitor' => $visitor])->send(); + return \Yii::$app->getResponse()->redirect([$this->blowOff])->send(); } } diff --git a/README.md b/README.md index 3c2d16f..795bf12 100644 --- a/README.md +++ b/README.md @@ -145,4 +145,20 @@ php yii ipFilter/import/logs '/my/own/private/idaho' php yii ipFilter/import/logs '/etc/httpd/logs' access_log-20180603,access_log-20180610 ``` -To see it live, check out https://snooky.biz/visitor \ No newline at end of file +To see it live, check out https://snooky.biz/visitor + +Screenshots! +----- + +The main screen +![ipfilter1](https://user-images.githubusercontent.com/4065107/42129954-e352eaea-7ca1-11e8-8db8-8cb44ce4f2fc.png) + +Detail visitor view +![ipfilter2](https://user-images.githubusercontent.com/4065107/42129951-e330717c-7ca1-11e8-9337-52f16c8c8a5e.png) + +Updating the name and/or message for a visitor. +![ipfilter3](https://user-images.githubusercontent.com/4065107/42129952-e33bce3c-7ca1-11e8-9fd2-9e06a9833a2f.png) + +The default blocked user view. (As seen from Tor) +![ipfilter4](https://user-images.githubusercontent.com/4065107/42129953-e3476580-7ca1-11e8-84cf-aef11158446b.png) + diff --git a/controllers/VisitorController.php b/controllers/VisitorController.php index 24dacd8..e80de58 100644 --- a/controllers/VisitorController.php +++ b/controllers/VisitorController.php @@ -121,11 +121,9 @@ public function actionBlacklist($id) { * Displays a blowoff Visitor message. * @return mixed */ - public function actionBlowoff($visitor) { + public function actionBlowoff() { $this->layout = 'blowy'; - return $this->render('blowoff', [ - 'visitor' => $visitor, - ]); + return $this->render('blowoff'); } /** diff --git a/migrations/m180630_142222_create_table_visitor_service_error.php b/migrations/m180630_142222_create_table_visitor_service_error.php index 9762594..034e8ec 100644 --- a/migrations/m180630_142222_create_table_visitor_service_error.php +++ b/migrations/m180630_142222_create_table_visitor_service_error.php @@ -2,10 +2,9 @@ use yii\db\Migration; -class m180630_142222_create_table_visitor_service_error extends Migration -{ - public function up() - { +class m180630_142222_create_table_visitor_service_error extends Migration { + + public function up() { $tableOptions = null; if ($this->db->driverName === 'mysql') { $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; @@ -17,13 +16,12 @@ public function up() 'url' => $this->string()->notNull(), 'params' => $this->json(), 'message' => $this->text()->notNull(), - 'is_resolved' => $this->boolean()->notNull()->defaultValue(''), - ], $tableOptions); - + 'is_resolved' => $this->boolean()->notNull()->defaultValue(false), + ], $tableOptions); } - public function down() - { + public function down() { $this->dropTable('{{%visitor_service_error}}'); } + } diff --git a/views/visitor/blowoff.php b/views/visitor/blowoff.php index 02867cf..8f321c3 100644 --- a/views/visitor/blowoff.php +++ b/views/visitor/blowoff.php @@ -9,18 +9,27 @@ */ /* @var $this yii\web\View */ /* @var $visitor johnsnook\ipFilter\models\Visitor */ -$name = (!empty($visitor->name) ? $visitor->name : 'Stranger'); -$message = (!empty($visitor->message) ? $visitor->message : "What's this you've said to me, my good friend? Ill have you know I graduated top of my class in conflict resolution, and Ive been involved in numerous friendly discussions, and I have over 300 confirmed friends. I am trained in polite discussions and I'm the top mediator in the entire neighborhood. You are worth more to me than just another target. I hope we will come to have a friendship never before seen on this Earth. Don't you think you might be hurting someone's feelings saying that over the internet? Think about it, my friend. As we speak I am contacting my good friends across the USA and your P.O. box is being traced right now so you better prepare for the greeting cards, friend. The greeting cards that help you with your hate. You should look forward to it, friend. I can be anywhere, anytime for you, and I can calm you in over seven hundred ways, and that's just with my chess set. Not only am I extensively trained in conflict resolution, but I have access to the entire group of my friends and I will use them to their full extent to start our new friendship. If only you could have known what kindness and love your little comment was about to bring you, maybe you would have reached out sooner. But you couldn't, you didn't, and now we get to start a new friendship, you unique person. I will give you gifts and you might have a hard time keeping up. You're finally living, friend."); +$visitor = \Yii::$app->getModule('ipFilter')->visitor; -$this->title = 'Do\'t go away mad, just go away.'; +$name = (!empty($visitor->name) ? $visitor->name : 'Visitor'); +if (!empty($visitor->message)) { + $message = $visitor->message; +} else { + if ($visitor->proxy === 'no') { + $message = 'An adminstrator has banned your IP address.'; + } else { + $message = "Your IP address has been automatically banned for using a proxy of type $visitor->proxy."; + } +} + +$this->title = 'Don\'t go away mad, just go away.'; ?>
- -

Dear ,

+

If you feel this is in error, you can contact an administrator

>