fbegin.inc 11 KB
Newer Older
Ad Schellevis's avatar
Ad Schellevis committed
1
<?php
2

Ad Schellevis's avatar
Ad Schellevis committed
3
/*
4 5
	Copyright (C) 2014 Deciso B.V.
	Copyright (C) 2008 Scott Ullrich <sullrich@gmail.com>
6
	Copyright (C) 2005-2006 Colin Smith <ethethlay@gmail.com>
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
	All rights reserved.

	Redistribution and use in source and binary forms, with or without
	modification, are permitted provided that the following conditions are met:

	1. Redistributions of source code must retain the above copyright notice,
	   this list of conditions and the following disclaimer.

	2. Redistributions in binary form must reproduce the above copyright
	   notice, this list of conditions and the following disclaimer in the
	   documentation and/or other materials provided with the distribution.

	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
	POSSIBILITY OF SUCH DAMAGE.
Ad Schellevis's avatar
Ad Schellevis committed
29 30 31 32
*/

require_once("shortcuts.inc");

33 34 35 36 37 38 39 40
function find_service_by_name($name) {
	$services = get_services();
	foreach ($services as $service)
		if ($service["name"] == $name)
			return $service;
	return array();
}

Ad Schellevis's avatar
Ad Schellevis committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
/* Determine automated help URL. Should output the page name and
   parameters separately */
$uri_split = "";
preg_match("/\/(.*)\?(.*)/", $_SERVER["REQUEST_URI"], $uri_split);

/* If there was no match, there were no parameters, just grab the filename
   Otherwise, use the matched filename from above. */
if (empty($uri_split[0])) {
	$pagename = ltrim($_SERVER["REQUEST_URI"], '/');
} else {
	$pagename = $uri_split[1];
}
/* If the page name is still empty, the user must have requested / (index.php) */
if (empty($pagename)) {
	$pagename = "index.php";
}

58 59
/* If the filename is wizard.php, reparse looking for the .xml filename */
if ($pagename == 'wizard.php') {
Ad Schellevis's avatar
Ad Schellevis committed
60 61 62 63 64 65 66 67 68
	$param_split = explode('&', $uri_split[2]);
	foreach ($param_split as $param) {
		if (substr($param, 0, 4) == "xml=") {
			$xmlfile = explode('=', $param);
			$pagename = $xmlfile[1];
		}
	}
}

69 70
// link menu system
$menu = new OPNsense\Base\Menu\MenuSystem();
Ad Schellevis's avatar
Ad Schellevis committed
71

72 73
// add interfaces to "Interfaces" menu tab... kind of a hack, may need some improvement.
$cnf = OPNsense\Core\Config::getInstance();
74
$ifarr = array();
75
foreach ($cnf->object()->interfaces->children() as $key => $node) {
76 77 78 79 80 81 82 83 84 85
    $ifarr[$key] = $node;
}
ksort($ifarr);
$ordid = 0;
foreach ($ifarr as $key => $node) {
    $menu->appendItem('Interfaces', $key, array(
        'url' => '/interfaces.php?if=' . $key,
        'order' => ($ordid++),
        'visiblename' => $node->descr ? $node->descr : strtoupper($key)
    ));
Ad Schellevis's avatar
Ad Schellevis committed
86
}
87
unset($ifarr);
88
$menuSystem = $menu->getItems($_SERVER['REQUEST_URI']);
89

90
$aclObj = new \OPNsense\Core\ACL();
Ad Schellevis's avatar
Ad Schellevis committed
91

92 93 94 95 96 97 98 99
/* display a top alert bar if need be */
$need_alert_display = false;
$found_notices = are_notices_pending();
if($found_notices == true) {
	$notices = get_notices();
	if(!$notices) {
		$need_alert_display = true;
		$display_text = print_notices($notices) . "<br />";
Ad Schellevis's avatar
Ad Schellevis committed
100 101
	}
}
102
if($need_alert_display == true) {
Ad Schellevis's avatar
Ad Schellevis committed
103
    echo "<div class=\"col-xs-12\"><div class=\"alert alert-info\"><p>".$display_text."</p></div></div>";
Ad Schellevis's avatar
Ad Schellevis committed
104 105 106
}

?>
107 108

<header class="page-head">
109

110
	<nav class="navbar navbar-default" role="navigation">
111

112 113
		<div class="container-fluid">
			<div class="navbar-header">
114
				<a class="navbar-brand" href="/index.php">
115 116
				<img class="brand-logo" src="/ui/themes/<?=$g['theme'];?>/build/images/default-logo.png" height="30"/>
				<img class="brand-icon" src="/ui/themes/<?=$g['theme'];?>/build/images/icon-logo.png" height="30"/>
Ad Schellevis's avatar
Ad Schellevis committed
117
				</a>
118 119 120 121 122 123 124
				<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navigation">
					<span class="sr-only">Toggle navigation</span>
					<span class="icon-bar"></span>
					<span class="icon-bar"></span>
					<span class="icon-bar"></span>
				</button>
			</div>
125 126 127

			<div class="collapse navbar-collapse">
				<ul class="nav navbar-nav navbar-right">
Ad Schellevis's avatar
Ad Schellevis committed
128 129 130 131 132
					<li id="menu_messages">
					<?php
						echo get_menu_messages();
					?>
					</li>
133
					<?php
134 135 136 137 138
						if (isset($shortcut_section)) {
							echo '<li>'.get_shortcut_main_link($shortcut_section, false).'</li>';
							echo '<li>'.get_shortcut_status_link($shortcut_section, false).'</li>';
							echo '<li>'.get_shortcut_log_link($shortcut_section, false).'</li>';
						}
139
					?>
140 141
					<li><a href="<?= "/help.php?page={$pagename}" ?>" target="_blank" title="<?= gettext('Help for items on this page') ?>"><?= gettext('Help') ?></a></li>
					<li class="active"><a href="/index.php?logout"><?= gettext('Logout') ?></a></li>
142
				</ul>
143

144 145 146
			</div>
		</div>
	</nav>
147

148 149
</header>

150 151 152 153 154 155 156
<main class="page-content col-sm-10 col-sm-push-2">

    <aside id="navigation" class="page-side col-xs-12 col-sm-2 hidden-xs">
        <div class="row">
            <nav class="page-side-nav" role="navigation">
                <div id="mainmenu" class="panel" style="border:0px" >
                    <div class="panel list-group" style="border:0px">
157 158
<?php
                          foreach($menuSystem as $topMenuItem): ?>
159
                            <a href="#<?=$topMenuItem->Id;?>" class="list-group-item <?= $topMenuItem->Selected ? 'active-menu-title' : ""; ?>" data-toggle="collapse" data-parent="#mainmenu"><span class="<?=$topMenuItem->CssClass;?> __iconspacer"></span><?=gettext($topMenuItem->VisibleName);?>  </a>
160 161 162 163
                            <div class="collapse <?=$topMenuItem->Selected ? 'active-menu in' :"";?>" id="<?=$topMenuItem->Id;?>">
<?php
                            foreach($topMenuItem->Children as $subMenuItem): ?>
<?php
164
                              if ($subMenuItem->Url == '' ):?>
165 166 167
                               <a href="#<?=$topMenuItem->Id;?>_<?=$subMenuItem->Id;?>" class="list-group-item <?=$subMenuItem->Selected ? "active-menu-title" : "";?>" data-toggle="collapse" data-parent="#<?=$topMenuItem->Id;?>">
                                  <div style="display: table;width: 100%;">
                                    <div style="display: table-row">
168
                                      <div style="display: table-cell"><?=gettext($subMenuItem->VisibleName);?></div>
169
                                        <div style="display: table-cell; text-align:right; vertical-align:middle;"><span class="<?=$subMenuItem->CssClass;?>"></span></div>
170 171 172
                                      </div>
                                  </div>
                               </a>
173 174 175 176 177
                               <div class="collapse <?=$subMenuItem->Selected ? "active-menu in" :"";?>" id="<?=$topMenuItem->Id;?>_<?=$subMenuItem->Id;?>">
<?php
                                  foreach ($subMenuItem->Children as $subsubMenuItem):?>
<?php
                                    if ($subsubMenuItem->IsExternal == "Y"):?>
178
                                            <a href="<?=$subsubMenuItem->Url;?>" target="_new" class="list-group-item menu-level-3-item <?=$subsubMenuItem->Selected ? "active" :"";?>"><?=gettext($subsubMenuItem->VisibleName);?></a>
179 180
<?php
                                    elseif ($aclObj->isPageAccessible($_SESSION['Username'],$subsubMenuItem->Url)):?>
181
                                            <a href="<?=$subsubMenuItem->Url;?>" class="list-group-item menu-level-3-item <?=$subsubMenuItem->Selected ? "active" :"";?>"><?=gettext($subsubMenuItem->VisibleName);?></a>
182 183 184 185 186 187
<?php
                                    endif;
                                  endforeach;?>
                                </div>
<?php
                              elseif ($subMenuItem->IsExternal == "Y" ):?>
188 189 190
                                <a href="<?=$subMenuItem->Url;?>" target="_new" class="list-group-item <?=$subMenuItem->Selected ? "active" : "";?>">
                                  <div style="display: table;width: 100%;">
                                    <div style="display: table-row">
191
                                      <div style="display: table-cell"><?=gettext($subMenuItem->VisibleName);?></div>
192
                                        <div style="display: table-cell; text-align:right; vertical-align:middle;"><span class="<?=$subMenuItem->CssClass;?>"></span></div>
193 194 195
                                      </div>
                                  </div>
                                </a>
196 197
<?php
                              elseif ($aclObj->isPageAccessible($_SESSION['Username'],$subMenuItem->Url)):?>
198 199 200
                                <a href="<?=$subMenuItem->Url;?>" class="list-group-item <?=$subMenuItem->Selected ? "active" :"";?>">
                                  <div style="display: table;width: 100%;">
                                    <div style="display: table-row">
201
                                      <div style="display: table-cell"><?=gettext($subMenuItem->VisibleName);?></div>
202
                                        <div style="display: table-cell; text-align:right; vertical-align:middle;"><span class="<?=$subMenuItem->CssClass;?>"></span></div>
203
                                    </div>
204
                                  </div>
205
                                </a>
206 207 208 209 210 211 212
<?php
                              endif;?>
<?php
                            endforeach; ?>
                            </div>
<?php
                        endforeach; ?>
213 214 215 216 217
                    </div>
                </div>
            </nav>
        </div>
    </aside>
218

219
	<div class="row">
220

221 222
		<header class="page-content-head">
			<div class="container-fluid">
Ad Schellevis's avatar
Ad Schellevis committed
223
			    <form action="<?=$_SERVER['REQUEST_URI'];?>" method="post">
224
				<ul class="list-inline">
225
					<li class="__mb"><h1><?=gentitle($pgtitle);?></h1></li>
226

227
					<li class="btn-group-container">
228

229
						<?php
230

Ad Schellevis's avatar
Ad Schellevis committed
231
						if (isset($shortcut_section) && !empty($shortcuts[$shortcut_section]['service'])) {
232 233 234 235 236 237 238
							$ssvc = array();
							switch ($shortcut_section) {
								case "openvpn":
									$ssvc = find_service_by_openvpn_vpnid($vpnid);
									break;
								default:
									$ssvc = find_service_by_name($shortcuts[$shortcut_section]['service']);
239

240 241 242 243 244 245
							}
							if (!empty($ssvc)) {
								echo get_service_status_icon($ssvc, false);
								echo get_service_control_links($ssvc, false);
							}
						}
246

247
						?>
248 249 250

						<? if (!empty($main_buttons)): foreach ($main_buttons as $button): ?>
							<a href="<?=$button['href'];?>" class="btn btn-primary"><span class="glyphicon glyphicon-plus-sign __iconspacer"></span><?=$button['label'];?></a>
251
						<? endforeach; endif; ?>
252

Ad Schellevis's avatar
Ad Schellevis committed
253
						<? if (isset($widgetfiles)): ?>
254 255


Ad Schellevis's avatar
Ad Schellevis committed
256
							<a href="#" id="updatepref" style="display:none" onclick="return updatePref();" class="btn btn-primary"><?=gettext("Save Settings");?></a>
257

258
							<button type="button" class="btn btn-default" data-toggle="modal" data-target="#modal_widgets"><span class="glyphicon glyphicon-plus-sign __iconspacer"></span><?= gettext('Add widget') ?></button>
Ad Schellevis's avatar
Ad Schellevis committed
259
						<? endif; ?>
260 261
					</li>
				</ul>
262
			    </form>
263
			</div>
264
		</header>