LEPTON CMS 7.2.0
feel free to keep it strictly simple...
Loading...
Searching...
No Matches
secure.php
Go to the documentation of this file.
1<?php
2
18if (!defined('LEPTON_PATH') && !defined('LEPTON_INSTALL_PROCESS'))
19{
20 require_once __DIR__."/functions/function.lepton_autoloader.php";
21 spl_autoload_register( "lepton_autoloader", true);
22
23 // 1.2 Get an instance of the class secure
24 $oSecure = LEPTON_secure::getInstance();
25
26 // 1.3 Is the script called inside a module directory - and if so: is there a file named "register_class_secure"?
27 $temp_path = (dirname($_SERVER['SCRIPT_FILENAME'])) . "/register_class_secure.php";
28 if (file_exists($temp_path))
29 {
30 require_once $temp_path;
31 }
32
33 // 2.0 Testing the filename
34 // @notice: $_SERVER['SCRIPT_NAME'] holds the path to the script witch include this file!
35 $allowed = $oSecure->testFile($_SERVER['SCRIPT_NAME']);
36
37 // 2.1 All failed - we look for some special ones
38 if (!$allowed)
39 {
40 $admin_dir = $oSecure->getAdminDir();
41
42 if ((str_contains($_SERVER['SCRIPT_NAME'], $admin_dir.'/media/index.php')) || (str_contains($_SERVER['SCRIPT_NAME'], $admin_dir.'/preferences/index.php')))
43 {
44 // special: do absolute nothing!
45 }
46 elseif ((str_contains($_SERVER['SCRIPT_NAME'], $admin_dir . '/index.php')))
47 {
48 // special: call start page of admins directory
49 $leptoken = isset($_GET['leptoken']) ? "?leptoken=" . $_GET['leptoken'] : "";
50 header("Location: ../".$admin_dir.'/start/index.php'.$leptoken);
51 exit();
52 }
53 elseif (str_contains($_SERVER['SCRIPT_NAME'], '/index.php'))
54 {
55 // call the main page
56 header("Location: ../index.php");
57 exit();
58 }
59 else
60 {
61 if (!headers_sent())
62 {
63 // set header to 403
64 header($_SERVER['SERVER_PROTOCOL'] . " 403 Forbidden");
65 }
66 // stop program execution
67 exit('<p><b>ACCESS DENIED! [L3]</b> - Invalid call of <i>'.$_SERVER['SCRIPT_NAME'].'</i></p>');
68 }
69 }
70
71 // 3.0 At last - all ok - get the config.php (and process the initialize.php)
72 $config_path = dirname(dirname(__FILE__))."/config/config.php";
73 require_once $config_path;
74}
75
76if (defined("FRONTEND"))
77{
78 //strip droplets and script tags
79 if (!function_exists('lep_sec_formdata'))
80 {
81 function lep_sec_formdata(array &$arr): void
82 {
83 foreach ($arr as $key => $value)
84 {
85 if (is_array($value))
86 {
87 lep_sec_formdata($value);
88 }
89 else
90 {
91 // remove <script> tags
92 $value = str_replace(
93 ['<script', '</script'],
94 ['&lt;script', '&lt;/script' ],
95 $value);
96 $value = preg_replace('#(\&lt;script.+?)>#i', '$1&gt;', $value);
97 $value = preg_replace('#(\&lt;\/script)>#i', '$1&gt;', $value);
98
99 $arr[$key] = str_replace(
100 ['[', ']'],
101 ['&#91;', '&#93;'],
102 $value);
103 }
104 }
105 }
106 }
107
108 // secure form input
109 if (isset($_SESSION) && !defined('LEP_SEC_FORMDATA'))
110 {
111 if (!empty($_GET))
112 {
113 lep_sec_formdata($_GET);
114 }
115 if (!empty($_POST))
116 {
117 lep_sec_formdata($_POST);
118 }
119 if (!empty($_REQUEST))
120 {
121 lep_sec_formdata($_REQUEST);
122 }
123
124 // make sure function is only called once
125 define('LEP_SEC_FORMDATA', true);
126 }
127}
static getInstance(mixed $value=null)