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
|
<?php
///
// NextCloudPi Web Panel Side bar
//
// Copyleft 2018 by Ignacio Nunez Hernanz <nacho _a_t_ ownyourbits _d_o_t_ com>
// GPL licensed (see end of file) * Use at your own risk!
//
// More at https://ownyourbits.com/2017/02/13/nextcloud-ready-raspberry-pi-image/
///
// fill options with contents from directory
function print_config_form( $ncp_app, $cfg, $l )
{
$ret = <<<HTML
<div id="config-box">
<table>
HTML;
foreach ($cfg['params'] as $param)
{
$ret .= "<tr>";
$ret .= "<td><label for=\"$ncp_app-$param[id]\">$param[name]</label></td>";
// default to text input
if (!array_key_exists('type', $param))
{
$ret .= "<td><input type=\"text\" name=\"$param[name]\" id=\"$ncp_app-$param[id]\" value=\"$param[value]\" size=\"40\"></td>";
}
// checkbox
else if ($param['type'] == 'bool')
{
$checked = "";
if ($param['value'] == 'yes')
$checked = 'checked';
$ret .= "<td><input type=\"checkbox\" id=\"$ncp_app-$param[id]\" name=\"$param[name]\" value=\"$param[value]\" $checked></td>";
}
$ret .= "</tr>";
}
$ret .= <<<HTML
</table>
</div>
<div class="config-button-wrapper">
<button id="$ncp_app-config-button" class="config-button">Run</button>
<img class="loading-gif" src="img/loading-small.gif">
<div class="circle-retstatus" class="icon-red-circle"></div>
</div>
</form>
HTML;
return $ret;
}
function print_config_forms( $l /* translations l10n object */ )
{
$bin_dir = '/usr/local/bin/ncp/';
$cfg_dir = '/usr/local/etc/ncp-config.d/';
$d_iterator = new RecursiveDirectoryIterator($bin_dir);
$iterator = new RecursiveIteratorIterator($d_iterator);
$objects = new RegexIterator($iterator, '/^.+\.sh$/i', RecursiveRegexIterator::GET_MATCH);
$ret = "";
$sections = array_diff(scandir($bin_dir), array('.', '..', 'l10n'));
foreach ($sections as $section)
{
$scripts = array_diff(scandir($bin_dir . $section), array('.', '..', 'nc-wifi.sh', 'nc-info.sh'));
foreach ($scripts as $script)
{
$ncp_app = pathinfo($script, PATHINFO_FILENAME);
$cfg_file = $cfg_dir . $ncp_app . ".cfg";
$cfg = json_decode(file_get_contents($cfg_file), true);
$hidden = 'hidden';
if (array_key_exists('app',$_GET) && $_GET['app'] == $ncp_app)
$hidden = '';
$ret .= <<<HTML
<div id="$cfg[id]-config-box" class="$hidden">
<h2 class="text-title">$cfg[description]</h2>
<div class="config-box-info-txt">$cfg[info]</div>
<a href="#" target="_blank">
<div class="icon-info"></div>
</a>
<br/>
<div class="table-wrapper">
HTML;
$ret .= print_config_form($ncp_app, $cfg, $l);
$ret .= <<<HTML
<div id="$ncp_app-details-box" class="details-box outputbox hidden"></div>
</div>
</div>
HTML;
}
}
return $ret;
}
function print_sidebar( $l /* translations l10n object */, $ticks /* wether to calculate ticks(slow) */ )
{
$bin_dir = '/usr/local/bin/ncp/';
$cfg_dir = '/usr/local/etc/ncp-config.d/';
$d_iterator = new RecursiveDirectoryIterator($bin_dir);
$iterator = new RecursiveIteratorIterator($d_iterator);
$objects = new RegexIterator($iterator, '/^.+\.sh$/i', RecursiveRegexIterator::GET_MATCH);
$ret = "";
$sections = array_diff(scandir($bin_dir), array('.', '..', 'l10n'));
foreach ($sections as $section)
{
$ret .= "<li id=\"$section\" class=\"nav-recent\"><span>{$l->__($section, $section)}</span>";
$scripts = array_diff(scandir($bin_dir . $section), array('.', '..', 'nc-wifi.sh', 'nc-info.sh'));
foreach ($scripts as $script)
{
$ncp_app = pathinfo($script, PATHINFO_FILENAME);
$cfg_file = $cfg_dir . $ncp_app . ".cfg";
$cfg = json_decode(file_get_contents($cfg_file), true);
$active = "";
if ( $ticks ) {
exec("bash -c \"source /usr/local/etc/library.sh && is_active_app $ncp_app\"", $output, $retval);
if ($retval == 0)
$active = " ✓";
} else if (sizeof($cfg['params']) > 0 && $cfg['params'][0]['id'] == 'ACTIVE' && $cfg['params'][0]['value'] == 'yes')
$active = " ✓";
$ret .= "<ul id=\"$ncp_app\" class=\"nav-recent\">";
$ret .= "<a href=\"#\"> {$l->__($ncp_app, $ncp_app)}$active </a>";
$ret .= "</ul>";
}
$ret .= "</li>";
}
return $ret;
}
// License
//
// This script 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 2 of the License, or
// (at your option) any later version.
//
// This script 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 script; if not, write to the
// Free Software Foundation, Inc., 59 Temple Place, Suite 330,
// Boston, MA 02111-1307 USA
?>
|