LEPTON CMS 7.1.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
76
77if (defined("FRONTEND"))
78{
79 //strip droplets and script tags
80 if (!function_exists('lep_sec_formdata'))
81 {
82 function lep_sec_formdata(array &$arr): void
83 {
84 foreach ($arr as $key => $value)
85 {
86 if (is_array($value))
87 {
88 lep_sec_formdata($value);
89 }
90 else
91 {
92 // remove <script> tags
93 $value = str_replace(array(
94 '<script',
95 '</script'
96 ), array(
97 '&lt;script',
98 '&lt;/script'
99 ), $value);
100 $value = preg_replace('#(\&lt;script.+?)>#i', '$1&gt;', $value);
101 $value = preg_replace('#(\&lt;\/script)>#i', '$1&gt;', $value);
102
103 $arr[$key] = str_replace(array(
104 '[',
105 ']'
106 ), array(
107 '&#91;',
108 '&#93;'
109 ), $value);
110 }
111 }
112 }
113 }
114
115 // secure form input
116 if (isset($_SESSION) && !defined('LEP_SEC_FORMDATA'))
117 {
118 if (!empty($_GET))
119 {
120 lep_sec_formdata($_GET);
121 }
122 if (!empty($_POST))
123 {
124 lep_sec_formdata($_POST);
125 }
126 if (!empty($_REQUEST))
127 {
128 lep_sec_formdata($_REQUEST);
129 }
130
131 // make sure function is only called once
132 define('LEP_SEC_FORMDATA', true);
133 }
134}