mambax7 /
xooghost
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
| 1 | <?php |
||
| 2 | |||
| 3 | namespace XoopsModules\Xooghost; |
||
| 4 | |||
| 5 | /** |
||
| 6 | * Xoopreferences : Preferences Manager |
||
| 7 | * |
||
| 8 | * You may not change or alter any portion of this comment or credits |
||
| 9 | * of supporting developers from this source code or any supporting source code |
||
| 10 | * which is considered copyrighted (c) material of the original comment or credit authors. |
||
| 11 | * This program is distributed in the hope that it will be useful, |
||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
| 14 | * |
||
| 15 | * @copyright XOOPS Project (https://xoops.org) |
||
| 16 | * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
||
| 17 | * @package Xooghost |
||
| 18 | * @since 2.6.0 |
||
| 19 | * @author Laurent JEN (Aka DuGris) |
||
| 20 | */ |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Class Preferences |
||
| 24 | */ |
||
| 25 | class Preferences |
||
| 26 | { |
||
| 27 | public $config = []; |
||
| 28 | public $basicConfig = []; |
||
| 29 | public $configPath; |
||
| 30 | public $configFile; |
||
| 31 | private $moduleDirName = 'xooghost'; |
||
| 32 | |||
| 33 | public function __construct() |
||
| 34 | { |
||
| 35 | $this->configFile = 'config.' . $this->moduleDirName . '.php'; |
||
| 36 | |||
| 37 | $this->configPath = \XoopsBaseConfig::get('var-path') . '/configs/' . $this->moduleDirName . '/'; |
||
| 38 | |||
| 39 | $this->basicConfig = $this->loadBasicConfig(); |
||
| 40 | $this->config = @$this->loadConfig(); |
||
| 41 | |||
| 42 | if (count($this->config) != count($this->basicConfig)) { |
||
| 43 | $this->config = array_merge($this->basicConfig, $this->config); |
||
| 44 | $this->writeConfig($this->config); |
||
| 45 | } |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @return mixed |
||
| 50 | */ |
||
| 51 | public static function getInstance() |
||
| 52 | { |
||
| 53 | static $instance; |
||
| 54 | if (!isset($instance)) { |
||
| 55 | $class = __CLASS__; |
||
| 56 | $instance = new $class(); |
||
| 57 | } |
||
| 58 | |||
| 59 | return $instance; |
||
| 60 | } |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @return array |
||
| 64 | */ |
||
| 65 | public function getConfig() |
||
| 66 | { |
||
| 67 | return $this->config; |
||
| 68 | } |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Preferences::loadConfig() |
||
| 72 | * |
||
| 73 | * @return array |
||
| 74 | */ |
||
| 75 | public function loadConfig() |
||
| 76 | { |
||
| 77 | if (!$config = $this->readConfig()) { |
||
| 78 | $config = $this->loadBasicConfig(); |
||
| 79 | $this->writeConfig($config); |
||
| 80 | } |
||
| 81 | |||
| 82 | return $config; |
||
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * Preferences::loadBasicConfig() |
||
| 87 | * |
||
| 88 | * @return array |
||
| 89 | */ |
||
| 90 | public function loadBasicConfig() |
||
| 91 | { |
||
| 92 | if (file_exists($file_path = dirname(__DIR__) . '/include/' . $this->configFile)) { |
||
| 93 | $config = include $file_path; |
||
| 94 | } |
||
| 95 | |||
| 96 | return $config; |
||
| 97 | } |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Preferences::readConfig() |
||
| 101 | * |
||
| 102 | * @return array |
||
| 103 | */ |
||
| 104 | public function readConfig() |
||
| 105 | { |
||
| 106 | $file_path = $this->configPath . $this->configFile; |
||
| 107 | \XoopsLoad::load('XoopsFile'); |
||
| 108 | $file = \XoopsFile::getHandler('file', $file_path); |
||
| 109 | |||
| 110 | return eval(@$file->read()); |
||
| 111 | } |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Preferences::writeConfig() |
||
| 115 | * |
||
| 116 | * @param array $config |
||
| 117 | * |
||
| 118 | * @return bool|null |
||
| 119 | * @internal param string $filename |
||
| 120 | */ |
||
| 121 | public function writeConfig($config) |
||
| 122 | { |
||
| 123 | if ($this->createPath($this->configPath)) { |
||
| 124 | $file_path = $this->configPath . $this->configFile; |
||
| 125 | \XoopsLoad::load('XoopsFile'); |
||
| 126 | $file = \XoopsFile::getHandler('file', $file_path); |
||
| 127 | |||
| 128 | return $file->write('return ' . var_export($config, true) . ';'); |
||
| 129 | } |
||
| 130 | |||
| 131 | return null; |
||
| 132 | } |
||
| 133 | |||
| 134 | /** |
||
| 135 | * @param $pathname |
||
| 136 | * @param mixed|string $pathout |
||
| 137 | * |
||
| 138 | * @return bool |
||
| 139 | */ |
||
| 140 | private function createPath($pathname, $pathout = XOOPS_ROOT_PATH) |
||
| 141 | { |
||
| 142 | $xoops = \Xoops::getInstance(); |
||
|
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||
| 143 | $pathname = mb_substr($pathname, mb_strlen(\XoopsBaseConfig::get('root-path'))); |
||
| 144 | $pathname = str_replace(DIRECTORY_SEPARATOR, '/', $pathname); |
||
| 145 | |||
| 146 | $dest = $pathout; |
||
| 147 | $paths = explode('/', $pathname); |
||
| 148 | |||
| 149 | foreach ($paths as $path) { |
||
| 150 | if (!empty($path)) { |
||
| 151 | $dest = $dest . '/' . $path; |
||
| 152 | if (!is_dir($dest)) { |
||
| 153 | if (!mkdir($dest, 0755) && !is_dir($dest)) { |
||
| 154 | return false; |
||
| 155 | } |
||
| 156 | $this->writeIndex(\XoopsBaseConfig::get('uploads-path'), 'index.html', $dest); |
||
| 157 | } |
||
| 158 | } |
||
| 159 | } |
||
| 160 | |||
| 161 | return true; |
||
| 162 | } |
||
| 163 | |||
| 164 | /** |
||
| 165 | * @param $folder_in |
||
| 166 | * @param $source_file |
||
| 167 | * @param $folder_out |
||
| 168 | * |
||
| 169 | * @return bool |
||
| 170 | */ |
||
| 171 | private function writeIndex($folder_in, $source_file, $folder_out) |
||
| 172 | { |
||
| 173 | if (!is_dir($folder_out)) { |
||
| 174 | if (!$this->createPath($folder_out)) { |
||
| 175 | return false; |
||
| 176 | } |
||
| 177 | } |
||
| 178 | |||
| 179 | // Simple copy for a file |
||
| 180 | if (is_file($folder_in . '/' . $source_file)) { |
||
| 181 | return copy($folder_in . '/' . $source_file, $folder_out . '/' . basename($source_file)); |
||
| 182 | } |
||
| 183 | |||
| 184 | return false; |
||
| 185 | } |
||
| 186 | |||
| 187 | /** |
||
| 188 | * @param null $data |
||
| 189 | * @param bool $module |
||
| 190 | * |
||
| 191 | * @return array |
||
| 192 | */ |
||
| 193 | public function prepare2Save($data = null, $module = true) |
||
| 194 | { |
||
| 195 | if (!isset($data)) { |
||
| 196 | $data = $_POST; |
||
| 197 | } |
||
| 198 | |||
| 199 | $config = []; |
||
| 200 | foreach (array_keys($data) as $k) { |
||
| 201 | if (is_array($data[$k])) { |
||
| 202 | $config[$k] = $this->prepare2Save($data[$k], false); |
||
| 203 | } else { |
||
| 204 | if (!$module || false !== mb_strpos($k, $this->moduleDirName . '_')) { |
||
| 205 | $config[$k] = $data[$k]; |
||
| 206 | } |
||
| 207 | } |
||
| 208 | } |
||
| 209 | |||
| 210 | return $config; |
||
| 211 | } |
||
| 212 | } |
||
| 213 |