Repository navigation
Expand file tree
/
Copy pathiframe.php
More file actions
165 lines (147 loc) · 6.61 KB
/
Copy pathiframe.php
File metadata and controls
165 lines (147 loc) · 6.61 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php
declare(strict_types=1);
// $active_page must be set before config/menu so the nav highlights correctly.
// It will be overwritten below once the module key is validated.
$active_page = '';
require_once('./include/init.php');
// ── Module validation ─────────────────────────────────────────────────────────
$module = trim((string)($_GET['module'] ?? ''));
// $module is only ever used to look up an entry in $gumcp_modules, so it cannot
// be turned into an arbitrary path — the config is the whitelist. A disabled
// module is treated as absent, so switching one off in config.php really does
// make it unreachable rather than only hiding it from the navbar.
if ($module === ''
|| !isset($gumcp_modules[$module])
|| empty($gumcp_modules[$module]['module_active'])) {
header('Location: index.php');
exit;
}
$module_config = $gumcp_modules[$module];
// Resolve and validate the module file path before any output.
$module_path_raw = $module_config['module_index_file_relative_path'] ?? '';
if ($module_path_raw === '' || !file_exists(__DIR__ . '/' . $module_path_raw)) {
header('Location: index.php');
exit;
}
$active_page = $module;
$module_title = htmlspecialchars($module_config['module_title'] ?? 'Module', ENT_QUOTES, 'UTF-8');
$module_path = htmlspecialchars($module_path_raw, ENT_QUOTES, 'UTF-8');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="GumCP Module: <?php echo $module_title; ?>">
<link rel="shortcut icon" href="./static/images/raspberry.png" type="image/png">
<link rel="icon" href="./static/images/raspberry.png" type="image/png">
<title><?php echo $module_title; ?> — GumCP</title>
<link href="./static/css.php?v=<?php echo gumcp_asset_version(); ?>" rel="stylesheet" type="text/css">
<script src="./static/js.php?v=<?php echo gumcp_asset_version(); ?>" type="text/javascript"></script>
<style>
.iframe-container { position:relative; width:100%; min-height:500px; }
.iframe-container iframe { display:block; width:100%; min-height:500px; border:none; background:#fff; }
.iframe-loading {
position:absolute; top:50%; left:50%;
transform:translate(-50%,-50%);
text-align:center; z-index:1;
}
.iframe-loading i { font-size:48px; color:#5bc0de; }
</style>
<script>
$(document).ready(function() {
var $iframe = $('#module-iframe');
var $loading = $('.iframe-loading');
$iframe.on('load', function() {
$loading.fadeOut(300);
try {
var doc = $iframe[0].contentDocument || $iframe[0].contentWindow.document;
var height = $(doc).height();
if (height > 0) $iframe.height(height + 50);
} catch (e) { /* cross-origin — use default height */ }
});
$iframe.on('error', function() {
$loading.hide();
$('.iframe-container').html(
'<div class="text-center" style="padding:40px;color:#a94442">' +
'<i class="fa fa-exclamation-triangle fa-3x"></i>' +
'<h3>Failed to load module</h3>' +
'<p>The module could not be loaded.</p></div>'
);
});
// Fallback: hide spinner after 10 s regardless of load event.
setTimeout(function() { $loading.fadeOut(300); }, 10000);
});
</script>
<script>
// Apply the saved theme before first paint, so dark mode never flashes white.
try { if (localStorage.getItem('gumcp-theme') === 'dark') document.documentElement.className += ' gumcp-dark'; } catch (e) {}
</script>
</head>
<body>
<div class="container">
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="./index.php">
<img src="./static/images/raspberry.png" alt="Logo"> GumCP
</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<?php require_once('./include/menu.php'); ?>
</ul>
</div>
</div>
</nav>
<div class="page-header">
<h1>
<?php echo $module_title; ?>
<?php if (!empty($module_config['module_description'])): ?>
<small><?php echo htmlspecialchars($module_config['module_description'], ENT_QUOTES, 'UTF-8'); ?></small>
<?php endif; ?>
</h1>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><i class="fa fa-cube"></i> <?php echo $module_title; ?></h3>
</div>
<div class="panel-body">
<div class="iframe-container">
<div class="iframe-loading">
<i class="fa fa-spinner fa-spin"></i>
<p>Loading module…</p>
</div>
<iframe id="module-iframe"
src="<?php echo $module_path; ?>"
title="<?php echo $module_title; ?>"
sandbox="allow-same-origin allow-scripts allow-forms allow-popups allow-modals"
loading="lazy">
<p>Your browser does not support iframes.
<a href="<?php echo $module_path; ?>">Open the module directly.</a></p>
</iframe>
</div>
</div>
</div>
</div>
<footer class="footer">
<div class="container">
<p class="text-muted">
GumCP <a href="https://github.com/gumslone/GumCP" target="_blank" rel="noopener">GitHub</a>.
<a href="https://www.paypal.com/donate/?hosted_button_id=VCWHQPACTXV5N"
target="_blank" rel="noopener">
<img src="./static/images/Donate-PayPal-green.svg" alt="Donate">
</a>
</p>
</div>
</footer>
</body>
</html>