function _settings_err($msg = '') { @ob_start(); echo '<!-- // ', _snomCnfXmlEsc($msg != '' ? str_replace('--', '- -', $msg) : 'Error'), ' // -->', "\n"; if (!headers_sent()) { header('Content-Type: text/plain; charset=utf-8'); header('Content-Length: ' . (int) @ob_get_length()); } @ob_end_flush(); exit(1); }
function _settings_out() { global $settings, $fw_vers_nrml, $prov_url_snom; if (_snomAppCmp($fw_vers_nrml, '7.1.8') < 0) { header('Content-Type: text/plain; charset=utf-8'); # the Content-Type header is ignored by the Snom foreach ($settings as $name => $a1) { if (subStr($name, 0, 1) === '_') { continue; } if (!array_key_exists('_is_array', $a1)) { echo $name, $a1['w'] ? '$' : '&', ': ', $a1['v'], "\n"; } else { if ($name !== 'fkey') { foreach ($a1 as $idx => $a2) { if ($idx === '_is_array') { continue; } echo $name, $idx, $a2['w'] ? '$' : '&', ': ', $a2['v'], "\n"; } } else { foreach ($a1 as $idx => $a2) { if ($idx === '_is_array') { continue; } echo $name, $idx, $a2['w'] ? '$' : '&', ': ', $a2['v'], "\n"; if (is_array($a2['a']) && array_key_exists('context', $a2['a'])) { echo $name, '_context', $idx, $a2['w'] ? '$' : '&', ': ', $a2['a']['context'], "\n"; } } } } /* ! means writeable by the user, but will not overwrite existing $ means writeable by the user, but will overwrite existing (available since version 4.2) & (or no flag) means read only, but will overwrite existing */ } unset($settings); } else { header('Content-Type: application/xml; charset=utf-8'); echo '<', '?xml version="1.0" encoding="utf-8"?', '>', "\n"; echo '<settings>', "\n\n"; $xml_cats = array(); foreach ($settings as $name => $a1) { if (!array_key_exists('_is_array', $a1)) { $attrstr = ''; if (is_array($a1['a'])) { foreach ($a1['a'] as $attr => $attrval) { $attrstr .= ' ' . $attr . '="' . _snomCnfXmlEsc($attrval) . '"'; } } $line = '<' . $name . $attrstr . ' perm="' . ($a1['w'] ? 'RW' : 'R') . '">' . _snomCnfXmlEsc($a1['v']) . '</' . $name . '>'; _add_to_cat($xml_cats, $name, $line); } else { if ($name === '_gui_lang' || $name === '_web_lang') { foreach ($a1 as $idx => $a2) { if ($idx === '_is_array') { continue; } $attrstr = ''; if (is_array($a2['a'])) { foreach ($a2['a'] as $attr => $attrval) { $attrstr .= ' ' . $attr . '="' . _snomCnfXmlEsc($attrval) . '"'; } } $line = '<language url="' . $prov_url_snom . 'sw/' . _snomCnfXmlEsc($a2['v']) . '" name="' . _snomCnfXmlEsc($idx) . '"' . $attrstr . ' />'; $langfile = GS_DIR . 'htdocs/prov/snom/sw/' . $a2['v']; $langfile_lock = $langfile . '.lock'; $langfiles_dir = dirName($langfile) . '/'; $langfile_url = 'http://provisioning.snom.com/config/snom' . $a2['v']; if (file_exists($langfile) && is_readable($langfile) && file_exists($langfile . '.done')) { //gs_log(GS_LOG_DEBUG, '---1'); _add_to_cat($xml_cats, $name, $line); } else { /* gs_log(GS_LOG_DEBUG, '---2'); if (! file_exists($langfiles_dir)) { gs_log(GS_LOG_DEBUG, '---3'); @exec( 'sudo mkdir -p '. qsa($langfiles_dir) .' 1>>/dev/null 2>>/dev/null' ); } if (file_exists($langfiles_dir)) { gs_log(GS_LOG_DEBUG, '---4'); $err=0; $out=array(); @exec( 'sudo touch '. qsa($langfile_lock) .' && sudo chmod 666 '. qsa($langfile_lock) .' 1>>/dev/null 2>>/dev/null', $out, $err ); if ($err==0) { gs_log(GS_LOG_DEBUG, '---5'); $lockfh = @fOpen( $langfile_lock, 'wb' ); if ($lockfh) { gs_log(GS_LOG_DEBUG, '---6'); $would_block = false; if (@flock($lockfh, LOCK_SH, $would_block)) { gs_log(GS_LOG_DEBUG, '---7'); if (! $would_block) { gs_log(GS_LOG_DEBUG, '---8'); gs_log( GS_LOG_NOTICE, 'Trying to wget '. qsa($langfile_url) ); @exec( 'sudo cd '. qsa($langfiles_dir) .' && sudo wget -q -a /dev/null -t 1 -T 300 -nc -c '. qsa($langfile_url) .' && sudo touch '. qsa($langfile.'.done') .' 1>>/dev/null 2>>/dev/null &' ); } @flock($lockfh, LOCK_UN); } @fClose($lockfh); } } } */ gs_log(GS_LOG_NOTICE, 'Please cd ' . qsa($langfiles_dir) . ' && wget ' . qsa($langfile_url) . ' && touch ' . qsa(baseName($langfile) . '.done')); } } } else { foreach ($a1 as $idx => $a2) { if ($idx === '_is_array') { continue; } $attrstr = ''; if (is_array($a2['a'])) { foreach ($a2['a'] as $attr => $attrval) { $attrstr .= ' ' . $attr . '="' . _snomCnfXmlEsc($attrval) . '"'; } } $line = '<' . $name . $attrstr . ' idx="' . $idx . '" perm="' . ($a2['w'] ? 'RW' : 'R') . '">' . _snomCnfXmlEsc($a2['v']) . '</' . $name . '>'; _add_to_cat($xml_cats, $name, $line); } } } } unset($settings); foreach ($xml_cats as $cat => $lines) { echo "\t", '<', $cat, '>', "\n"; foreach ($lines as $line) { echo $line, "\n"; } echo "\t", '</', $cat, '>', "\n\n"; } unset($xml_cats); echo '</settings>', "\n"; } }