File tree Expand file tree Collapse file tree 3 files changed +32
-7
lines changed Expand file tree Collapse file tree 3 files changed +32
-7
lines changed Original file line number Diff line number Diff line change 79
79
80
80
/**
81
81
* Allow access from whitelisted IP's.
82
- * Enter a string of comma separated IP's or null to allow all IP's.
83
- * For example: '1.2.3.4,1.2.3.4'
82
+ * Enter an array or string of comma separated IP's or null to allow all IP's.
83
+ * For example: ['1.2.3.4', '1.2.3.4'] or '1.2.3.4,1.2.3.4'
84
84
* If empty, all IP's are allowed.
85
85
*
86
86
* Default: null
Original file line number Diff line number Diff line change @@ -77,8 +77,7 @@ protected function currentUrlIsIgnored()
77
77
protected function clientIpIsWhitelisted ()
78
78
{
79
79
$ clientIp = Request::ip ();
80
- $ whitelist = explode (', ' , $ this ->getIpWhitelist ());
81
- $ ips = array_map ('trim ' , $ whitelist );
80
+ $ ips = array_map ('trim ' , $ this ->getIpWhitelist ());
82
81
83
82
return in_array ($ clientIp , $ ips );
84
83
}
@@ -90,17 +89,23 @@ protected function clientIpIsWhitelisted()
90
89
*/
91
90
protected function hasIpWhitelist ()
92
91
{
93
- return ! empty (trim ( $ this ->getIpWhitelist () ));
92
+ return ! empty ($ this ->getIpWhitelist ());
94
93
}
95
94
96
95
/**
97
96
* Get the IP whitelist from the config file.
98
97
*
99
- * @return string
98
+ * @return array
100
99
*/
101
100
protected function getIpWhitelist ()
102
101
{
103
- return Config::get ('stagefront.ip_whitelist ' , '' );
102
+ $ whitelist = Config::get ('stagefront.ip_whitelist ' , []);
103
+
104
+ if (is_array ($ whitelist )) {
105
+ return $ whitelist ;
106
+ }
107
+
108
+ return explode (', ' , $ whitelist );
104
109
}
105
110
106
111
/**
Original file line number Diff line number Diff line change @@ -270,6 +270,26 @@ public function it_allows_access_to_whitelisted_ips_only()
270
270
->assertOk ();
271
271
}
272
272
273
+ /** @test */
274
+ public function you_can_add_a_whitelist_as_an_array ()
275
+ {
276
+ $ this ->url = Config::get ('stagefront.url ' );
277
+ $ this ->registerRoute ('/page ' , 'Some Page ' );
278
+
279
+ $ this ->enableStageFront ();
280
+ $ this ->setIntendedUrl ('/page ' );
281
+
282
+ Config::set ('stagefront.ip_whitelist ' , ['0.0.0.0 ' , '1.1.1.1 ' ]);
283
+ Config::set ('stagefront.ip_whitelist_only ' , true );
284
+ Config::set ('stagefront.ip_whitelist_require_login ' , false );
285
+
286
+ $ this ->get ('/page ' , ['REMOTE_ADDR ' => '1.2.3.4 ' ])
287
+ ->assertStatus (403 );
288
+
289
+ $ this ->get ('/page ' , ['REMOTE_ADDR ' => '1.1.1.1 ' ])
290
+ ->assertOk ();
291
+ }
292
+
273
293
/** @test */
274
294
public function it_allows_access_to_whitelisted_ips_only_with_required_login ()
275
295
{
You can’t perform that action at this time.
0 commit comments