// 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; foreach ($cfg['params'] as $param) { $ret .= ""; $ret .= ""; $value = $param['value']; // default to text input if (!array_key_exists('type', $param) || $param['type'] == 'directory' || $param['type'] == 'file') { $suggest = ''; if (array_key_exists('suggest', $param)) $suggest = $param['suggest']; $default = ''; if (array_key_exists('default', $param)) $default = $param['default']; $class = ''; if (array_key_exists('type', $param) && ($param['type'] == 'directory' || $param['type'] == 'file')) $class = $param['type']; $ret .= ""; } // checkbox else if ($param['type'] == 'bool') { $checked = ""; if ($value == 'yes') $checked = 'checked'; $ret .= ""; } // password else if ($param['type'] == 'password') { $suggest = ''; if (array_key_exists('suggest', $param)) $suggest = $param['suggest']; $ret .= ""; } $ret .= ""; } $ret .= <<
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); $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 .= <<

$cfg[description]

$cfg[info]

HTML; $ret .= print_config_form($ncp_app, $cfg, $l); $ret .= <<
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); $ret = ""; $sections = array_diff(scandir($bin_dir), array('.', '..', 'l10n')); foreach ($sections as $section) { $ret .= "
  • {$l->__($section, $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); $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 = " ✓"; $selected = ""; if (array_key_exists('app',$_GET) && $_GET['app'] == $ncp_app) $selected = "active"; $ret .= ""; } $ret .= "
  • "; } 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 ?>
    "; if (array_key_exists('default', $param)) $ret .= " "; if (array_key_exists('type', $param) && $param['type'] == 'directory') { if (file_exists($value)) $ret .= " path exists"; else $ret .= " path doesn't exist"; } if (array_key_exists('type', $param) && $param['type'] == 'file') { if (file_exists(dirname($value))) $ret .= " path exists"; else $ret .= " path doesn't exist"; } $ret .= " "; $ret .= ""; $ret .= " "; $ret .= "