Skip to content

Commit a5fe623

Browse files
committed
[SECURITY] Removed SQL Templates
* Remove the entire SQL template system * Secuirty issues arose that can't easily be fixed in MPOS * For the sake of site security, these have been completely removed ! Will require the `templates/cache/bootstrap` and `template/compile/bootstrap` folders to be removed if custom SQL templates were used ! Will fix #2114 once merged.
1 parent 6324471 commit a5fe623

File tree

7 files changed

+1
-311
lines changed

7 files changed

+1
-311
lines changed

public/include/pages/admin/templates.inc.php

Lines changed: 0 additions & 48 deletions
This file was deleted.

public/include/smarty.inc.php

Lines changed: 0 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -7,145 +7,6 @@
77
// Include the actual smarty class file
88
include(SMARTY_DIR . 'Smarty.class.php');
99

10-
/**
11-
* Custom Smarty Template Resource for Pages
12-
* Get templates from Database
13-
* Allow admin to manage his templates from Backoffice
14-
*/
15-
class Smarty_Resource_Database extends Smarty_Resource_Custom {
16-
protected $template;
17-
18-
public function __construct($template) {
19-
$this->template = $template;
20-
}
21-
/**
22-
* Fetch a template and its modification time from database
23-
*
24-
* @param string $name template name
25-
* @param string $source template source
26-
* @param integer $mtime template modification timestamp (epoch)
27-
* @return void
28-
*/
29-
protected function fetch($name, &$source, &$mtime) {
30-
$oTemplate = $this->template->getEntry($this->fullTemplateName($name));
31-
if ( $oTemplate && $oTemplate['active'] ) {
32-
$source = $oTemplate['content'];
33-
$mtime = strtotime($oTemplate['modified_at']);
34-
} else {
35-
$source = null;
36-
$mtime = null;
37-
}
38-
}
39-
40-
/**
41-
* Fetch a template's modification time from database
42-
*
43-
* @note implementing this method is optional. Only implement it if modification times can be accessed faster than loading the comple template source.
44-
* @param string $name template name
45-
* @return integer timestamp (epoch) the template was modified
46-
*/
47-
protected function fetchTimestamp($name) {
48-
$templates = $this->template->cachedGetActiveTemplates();
49-
$mtime = @$templates[$this->fullTemplateName($name)];
50-
return $mtime ? $mtime : false;
51-
}
52-
53-
/**
54-
* Prepend THEME name to template name to get valid DB primary key
55-
*
56-
* @param string $name template name
57-
*/
58-
protected function fullTemplateName($name) {
59-
return $this->normalisePath(THEME . "/" . $name);
60-
}
61-
62-
/**
63-
* Normalise a file path string so that it can be checked safely.
64-
*
65-
* Attempt to avoid invalid encoding bugs by transcoding the path. Then
66-
* remove any unnecessary path components including '.', '..' and ''.
67-
*
68-
* @param $path string
69-
* The path to normalise.
70-
* @return string
71-
* The path, normalised.
72-
* @see https://gist.github.com/thsutton/772287
73-
*/
74-
protected function normalisePath($path) {
75-
// Process the components
76-
$parts = explode('/', $path);
77-
$safe = array();
78-
foreach ($parts as $idx => $part) {
79-
if (empty($part) || ('.' == $part)) {
80-
continue;
81-
} elseif ('..' == $part) {
82-
array_pop($safe);
83-
continue;
84-
} else {
85-
$safe[] = $part;
86-
}
87-
}
88-
// Return the "clean" path
89-
$path = implode(DIRECTORY_SEPARATOR, $safe);
90-
return $path;
91-
}
92-
93-
}
94-
95-
class Smarty_Resource_Hybrid extends Smarty_Resource {
96-
97-
protected $databaseResource;
98-
99-
protected $fileResource;
100-
101-
public function __construct($dbResource, $fileResource) {
102-
$this->databaseResource = $dbResource;
103-
$this->fileResource = $fileResource;
104-
}
105-
106-
/**
107-
* populate Source Object with meta data from Resource
108-
*
109-
* @param Smarty_Template_Source $source source object
110-
* @param Smarty_Internal_Template $_template template object
111-
*/
112-
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template=null) {
113-
if ( !@$_REQUEST['disable_template_override'] ) {
114-
$this->databaseResource->populate($source, $_template);
115-
if( $source->exists )
116-
return;
117-
}
118-
$source->type = 'file';
119-
return $this->fileResource->populate($source, $_template);
120-
}
121-
122-
/**
123-
* Load template's source into current template object
124-
*
125-
* @param Smarty_Template_Source $source source object
126-
* @return string template source
127-
* @throws SmartyException if source cannot be loaded
128-
*/
129-
public function getContent(Smarty_Template_Source $source) {
130-
try {
131-
return $this->databaseResource->getContent($source);
132-
} catch(SmartyException $e) {
133-
return $this->fileResource->getContent($source);
134-
}
135-
}
136-
137-
/**
138-
* Determine basename for compiled filename
139-
*
140-
* @param Smarty_Template_Source $source source object
141-
* @return string resource's basename
142-
*/
143-
public function getBasename(Smarty_Template_Source $source) {
144-
return $this->fileResource->getBasename($source);
145-
}
146-
147-
}
148-
14910
// We initialize smarty here
15011
$debug->append('Instantiating Smarty Object', 3);
15112
$smarty = new Smarty;
@@ -154,11 +15,6 @@ public function getBasename(Smarty_Template_Source $source) {
15415
$debug->append('Define Smarty Paths', 3);
15516
$smarty->template_dir = BASEPATH . 'templates/' . THEME . '/';
15617
$smarty->compile_dir = BASEPATH . 'templates/compile/' . THEME . '/';
157-
$smarty->registerResource('hybrid', new Smarty_Resource_Hybrid(
158-
new Smarty_Resource_Database($template),
159-
new Smarty_Internal_Resource_File()
160-
));
161-
$smarty->default_resource_type = "hybrid";
16218
$smarty_cache_key = md5(serialize($_REQUEST) . serialize(@$_SESSION['USERDATA']['id']));
16319

16420
// Optional smarty caching, check Smarty documentation for details

public/templates/bootstrap/admin/templates/browser.tpl

Lines changed: 0 additions & 48 deletions
This file was deleted.

public/templates/bootstrap/admin/templates/default.tpl

Lines changed: 0 additions & 4 deletions
This file was deleted.

public/templates/bootstrap/admin/templates/editor.tpl

Lines changed: 0 additions & 38 deletions
This file was deleted.

public/templates/bootstrap/admin/templates/tree.tpl

Lines changed: 0 additions & 27 deletions
This file was deleted.

public/templates/bootstrap/global/navigation.tpl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<li>
99
<a href="{$smarty.server.SCRIPT_NAME}?page=dashboard"><i class="fa fa-dashboard fa-fw"></i> Dashboard</a>
1010
</li>
11-
11+
1212
<li {if $smarty.get.page|default:"0" eq "account"}class="active"{/if}>
1313
<a href="#"><i class="fa fa-user-md fa-fw"></i> My Account<span class="fa arrow"></span></a>
1414
<ul class="nav nav-second-level">
@@ -39,7 +39,6 @@
3939
<li><a href="{$smarty.server.SCRIPT_NAME}?page=admin&action=registrations"><i class="fa fa-pencil-square-o fa-fw"></i> Registrations</a></li>
4040
<li><a href="{$smarty.server.SCRIPT_NAME}?page=admin&action=invitations"><i class="fa fa-users fa-fw"></i> Invitations</a></li>
4141
<li><a href="{$smarty.server.SCRIPT_NAME}?page=admin&action=poolworkers"><i class="fa fa-desktop fa-fw"></i> Pool Workers</a></li>
42-
<li><a href="{$smarty.server.SCRIPT_NAME}?page=admin&action=templates"><i class="fa fa-files-o fa-fw"></i> Templates</a></li>
4342
</ul>
4443
<!-- /.nav-second-level -->
4544
</li>

0 commit comments

Comments
 (0)