@@ -34,7 +34,7 @@ class Module
3434 *
3535 * @since 1.0.0
3636 */
37- const VERSION = '1.0.24 ' ;
37+ const VERSION = '1.0.25 ' ;
3838
3939 /**
4040 * Load module config file
@@ -47,6 +47,17 @@ public function getConfig() : array
4747 return include __DIR__ . '/../config/module.config.php ' ;
4848 }
4949
50+ /**
51+ * Get Modules File Directory
52+ *
53+ * @return string
54+ * @since 1.0.25
55+ */
56+ public static function getModuleDir () : string
57+ {
58+ return __DIR__ .'/../ ' ;
59+ }
60+
5061 /**
5162 * On Bootstrap - is executed on every page request
5263 *
@@ -71,6 +82,8 @@ function ($e) {
7182 $ app = $ e ->getApplication ();
7283 $ routeMatch = $ e ->getRouteMatch ();
7384 $ sm = $ app ->getServiceManager ();
85+ $ sRouteName = $ routeMatch ->getMatchedRouteName ();
86+ $ aRouteInfo = $ routeMatch ->getParams ();
7487
7588 $ oDbAdapter = $ sm ->get (AdapterInterface::class);
7689
@@ -103,11 +116,19 @@ function ($e) {
103116 $manager = new SessionManager($config);
104117 **/
105118
106- $ sRouteName = $ routeMatch ->getMatchedRouteName ();
107- $ aRouteInfo = $ routeMatch ->getParams ();
108-
109119 $ app ->getMvcEvent ()->getViewModel ()->setVariables (['sRouteName ' => $ sRouteName ]);
110120
121+ /**
122+ * preparign for firewall access log
123+
124+ $log = "User: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a").PHP_EOL.
125+ "URL: ".$sRouteName.PHP_EOL.
126+ "Attempt: ".('Success').PHP_EOL.
127+ "-------------------------".PHP_EOL;
128+ //Save string to log, use FILE_APPEND to append.
129+ file_put_contents('./log_'.date("Y-m-d").'.log', $log, FILE_APPEND);
130+ * */
131+
111132 # get session
112133 $ container = new Container ('plcauth ' );
113134 $ bLoggedIn = false ;
@@ -125,18 +146,27 @@ function ($e) {
125146
126147 $ bIsSetupController = stripos ($ aRouteInfo ['controller ' ], 'InstallController ' );
127148 if ($ bIsSetupController === false ) {
128- if (! $ container ->oUser ->hasPermission ($ aRouteInfo ['action ' ], $ aRouteInfo ['controller ' ])
129- && $ sRouteName != 'denied ' ) {
130- $ response = $ e ->getResponse ();
131- $ response ->getHeaders ()->addHeaderLine (
132- 'Location ' ,
133- $ e ->getRouter ()->assemble (
134- ['permission ' => $ aRouteInfo ['action ' ].'- ' .str_replace (['\\' ],['- ' ],$ aRouteInfo ['controller ' ])],
135- ['name ' => 'denied ' ]
136- )
137- );
138- $ response ->setStatusCode (302 );
139- return $ response ;
149+ $ aWhiteListedRoutes = [];
150+ $ aWhiteListedRoutesDB = json_decode (CoreController::$ aGlobalSettings ['firewall-user-whitelist ' ]);
151+ if (is_array ($ aWhiteListedRoutesDB )) {
152+ foreach ($ aWhiteListedRoutesDB as $ sWhiteRoute ) {
153+ $ aWhiteListedRoutes [$ sWhiteRoute ] = [];
154+ }
155+ }
156+ if (!array_key_exists ($ sRouteName , $ aWhiteListedRoutes )) {
157+ if (! $ container ->oUser ->hasPermission ($ aRouteInfo ['action ' ], $ aRouteInfo ['controller ' ])
158+ && $ sRouteName != 'denied ' ) {
159+ $ response = $ e ->getResponse ();
160+ $ response ->getHeaders ()->addHeaderLine (
161+ 'Location ' ,
162+ $ e ->getRouter ()->assemble (
163+ ['permission ' => $ aRouteInfo ['action ' ].'- ' .str_replace (['\\' ],['- ' ],$ aRouteInfo ['controller ' ])],
164+ ['name ' => 'denied ' ]
165+ )
166+ );
167+ $ response ->setStatusCode (302 );
168+ return $ response ;
169+ }
140170 }
141171 } else {
142172 # let user install module
@@ -165,13 +195,17 @@ function ($e) {
165195
166196 # Whitelisted routes that need no authentication
167197 $ aWhiteListedRoutes = [
168- 'tokenlogin ' => [],
169198 'setup ' => [],
170199 'login ' => [],
171- 'reset-pw ' => [],
172- 'forgot-pw ' => [],
173- 'register ' => [],
174200 ];
201+ if (isset (CoreController::$ aGlobalSettings ['firewall-whitelist ' ])) {
202+ $ aWhiteListedRoutesDB = json_decode (CoreController::$ aGlobalSettings ['firewall-whitelist ' ]);
203+ if (is_array ($ aWhiteListedRoutesDB )) {
204+ foreach ($ aWhiteListedRoutesDB as $ sWhiteRoute ) {
205+ $ aWhiteListedRoutes [$ sWhiteRoute ] = [];
206+ }
207+ }
208+ }
175209
176210 /**
177211 * Redirect to Login Page if not logged in
@@ -278,6 +312,14 @@ public function getControllerConfig() : array
278312 $ container
279313 );
280314 },
315+ Controller \FirewallController::class => function ($ container ) {
316+ $ oDbAdapter = $ container ->get (AdapterInterface::class);
317+ return new Controller \FirewallController (
318+ $ oDbAdapter ,
319+ $ container ->get (Model \UserTable::class),
320+ $ container
321+ );
322+ },
281323 ],
282324 ];
283325 }
0 commit comments