aboutsummaryrefslogtreecommitdiff
path: root/modules.php
blob: e57688147becd0af84a8bdbfe445eac162d4bc03 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
/**
 * Bayonet Content Management System
 * Copyright (C) 2008  Joseph Hunkeler
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */ 
 
define("MODULE_FILE",true);
global $load,$index_module;

/**
 * Assign _GET variables
 */
if(isset($_GET['load']))
    $load = $_GET['load'];

if(isset($_GET['file']))
    $file = $_GET['file'];

/** 
 * Determine the default module to load
 */
if(is_null($load))
{
	$load = $config['modules']['default'];
}

/**
 * If the error stack has recieved messages, output each failure in a clean fashion 
 */
global $error_stack_messages;
if(!empty($error_stack_messages))
{
	$messageBuffer = NULL;
	foreach($error_stack_messages as $order => $error)
	{
		$messageBuffer .= "<p><b>Stack Order:</b> $order<br/>$error</p>";
	}
	ReportError($messageBuffer);
	//exit(1);
}

$module_path = "modules/" . $load;
$module_index = $module_path . "/index.php";
$module_internal_file = "modules/" . $load . "/" . $file;

/** Sanity Check
 * If the module or a file associated with the module is a symbolic link then
 * commit suicide.  Symbolic links to malicious code can be dangerous. 
 */
if(isset($load) || isset($file))
{
	if(is_link($module_path))
	{
		decho("Refusing to follow symbolic link to '$load'");
		exit(1);	
	}
	
	if(is_link($module_internal_file))
	{
		decho("Refusing to follow symbolic link to '$file'");
		exit(1);
	}
}

/** Sanity Check
 * Determine if the module or file passed into $load actually exists
 * If everything checks out, load the module or file, else commit suicide.
 */
if(isset($load) && !empty($load) && !isset($file))
{	
    if(file_exists($module_path))
	{
		include $module_index;
		decho("'$load' module loaded");
    }
    else
    {
        ReportError("Cannot load module directory.<br>\n"); 
    }
}
/**
 * Load an internal module file
 */
elseif(isset($load) && isset($file))
{
	if(file_exists($module_path))
	{    	
    	if(file_exists($module_internal_file))
    	{	
      		include $module_internal_file;
	  		decho("Loaded '$file' file from $load module");     
    	}
    	else
    	{
      		ReportError("Cannot load module directory.<br>\n");     
    	}
	}
	else
	{
    	ReportError("Cannot load module file.<br>\n");
	}
}
else
{
	ReportError("Failure to load module.<br>\n");  
}


?>