@@ -58,7 +58,7 @@ private function getBlacklists() {
5858 */
5959 private function searchIp ($ clientIp ) {
6060 try {
61- if (($ key = array_search ($ clientIp , array_column ($ this ->list_object , "ip " ), TRUE )) !== FALSE ) {
61+ if (($ key = array_search ($ clientIp , array_column ($ this ->list_object , "client_ip " ), TRUE )) !== FALSE ) {
6262 return $ key ;
6363 } else {
6464 return FALSE ;
@@ -85,13 +85,14 @@ public function checkIp($clientIp) {
8585 /**
8686 * Prevention of illegal input based on filter rules file
8787 *
88- * @param \Illuminate\Http\Request $ request
88+ * @param array $data the request data
8989 * @param bool $blocker add client IP to blacklists if contains illegal input
90+ * @param $clientIp the visitor client IP
9091 * @return void/bool
9192 *
9293 * @throws \Symfony\Component\HttpKernel\Exception\HttpException
9394 */
94- public function filterInput (Request $ request , $ blocker = FALSE ) {
95+ public function filterInput ($ data = [] , $ blocker = FALSE , $ clientIp ) {
9596 $ filterRules = __DIR__ . "/ " . $ this ->filterRules ;
9697 $ getRule = @file_get_contents ($ filterRules );
9798
@@ -101,10 +102,10 @@ public function filterInput(Request $request, $blocker = FALSE) {
101102
102103 $ objectRules = json_decode ($ getRule , TRUE )['filters ' ];
103104
104- foreach ($ request -> all () as $ key => $ value ) {
105+ foreach ($ data as $ key => $ value ) {
105106 foreach ($ objectRules as $ key => $ object ) {
106107 if (preg_match ("/ " . $ object ['rule ' ] . "/ " , $ value )) {
107- if ($ blocker === TRUE ) $ this ->addToBlacklisted ($ request -> ip () , $ object ['description ' ] . " ( " . $ value . ") " );
108+ if ($ blocker === TRUE ) $ this ->addToBlacklisted ($ clientIp , $ object ['description ' ] . " ( " . $ value . ") " );
108109 return abort ($ this ->abort );
109110 }
110111 }
@@ -123,9 +124,9 @@ public function filterInput(Request $request, $blocker = FALSE) {
123124 public function addToBlacklisted ($ clientIp , $ attack = NULL ) {
124125 $ add = $ this ->list_object ;
125126 $ data = [
126- 'ip ' => $ clientIp ,
127- 'attack ' => ($ attack = NULL ? "added manually " : $ attack ),
128- 'time ' => date ('Y-m-d H:i:s ' )
127+ 'client_ip ' => $ clientIp ,
128+ 'attack_type ' => ($ attack = NULL ? "added manually " : $ attack ),
129+ 'date_time ' => date ('Y-m-d H:i:s ' )
129130 ];
130131 array_push ($ add , $ data );
131132
@@ -134,15 +135,15 @@ public function addToBlacklisted($clientIp, $attack = NULL) {
134135
135136
136137 /**
137- * Run rules to clean client IP from blacklists
138+ * Clean the client IP from blacklists
138139 *
139140 * @return array
140141 */
141142 public function cronBlacklistedRules () {
142143 foreach ($ this ->list_object as $ key => $ object ) {
143144 $ getDiffInHours = (int ) round (abs (strtotime ('now ' ) - strtotime ($ object ['time ' ])) / 3600 , 0 );
144145 if ($ getDiffInHours >= $ this ->options ['expired ' ]) {
145- return $ this ->removeFromBlacklists ($ object ['ip ' ]);
146+ return $ this ->removeFromBlacklists ($ object ['client_ip ' ]);
146147 }
147148 }
148149 }
0 commit comments