* @desc Process and renders SOAP server config related requests */ // must be run within Dokuwiki if(!defined('DOKU_INC')) die(); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC.'lib/plugins/'); if(!defined('DOKU_FARM_PLUGIN')) define('DOKU_FARM_PLUGIN', DOKU_PLUGIN.'farm/'); if(!defined('DOKU_FARMPLUGINLOADED')) define('DOKU_FARMPLUGINLOADED', true); class dokuwiki_farm_soapconfig { var $data = array(); var $manager = null; var $errors = array(); /** * @param $manager object that must handle error(), success(), nicesize(), getLang() ... calls */ function __construct($manager) { $this->manager = & $manager; } /** * Builds a link inside SOAP config tab * @param $opts farm option array * @return url string */ function wl($opts = array()) { return $this->manager->wl('soapconfig', $opts); } /** * Process requests */ function process() { // Parameters check if( !(isset($this->manager->opt['app']) && isset($this->manager->opt['save'])) && !(isset($this->manager->opt['app']) && isset($this->manager->opt['delete'])) && !(isset($this->manager->opt['new']) && isset($this->manager->opt['save'])) && !isset($this->manager->opt['advancedsave']) ) return; // Security check if(!checkSecurityToken()) { $this->manager->error('system_errors', 'system_badtoken_failure'); return; // any changes done by post } // Text mode save request if(isset($this->manager->opt['advancedsave'])) { if(!isset($_POST['soap_config_advanced']) || empty($_POST['soap_config_advanced'])) { $this->manager->error('system_errors', 'postparametermissing_failure'); return; } if($fp = fopen(DOKU_FARM_PLUGIN.'trusted_apps.php', 'w')) { fwrite($fp, ''."\n".$_POST['soap_config_advanced']); fclose($fp); }else $this->manager->error('soapconfig_errors', 'soapconfig_save_failure'); return; } // Trusted application deletion request if(isset($this->manager->opt['delete']) && isset($this->manager->opt['app'])) { $out = array(); foreach(explode("\n\n", @file_get_contents(DOKU_FARM_PLUGIN.'trusted_apps.php')) as $p) { $appname = ''; foreach(explode("\n", trim($p)) as $f) if(preg_match('`^name\s*=\s*([^#]+)(#.*)?$`i', trim($f), $m)) $appname = trim($m[1]); if($appname != $this->manager->opt['app']) $out[] = $p; } if($fp = fopen(DOKU_FARM_PLUGIN.'trusted_apps.php', 'w')) { fwrite($fp, $out); fclose($fp); unset($this->manager->opt['app']); $this->manager->success('soapconfig_save_success'); }else $this->manager->error('soapconfig_errors', 'soapconfig_save_failure'); return; } // Parameters check if( !isset($_POST['soap_remoteapp_name']) || empty($_POST['soap_remoteapp_name']) || !preg_match('`^[a-z0-9_-]+$`i', $_POST['soap_remoteapp_name']) || !isset($_POST['soap_remoteapp_namecomment']) || !isset($_POST['soap_remoteapp_pwd']) || !isset($_POST['soap_remoteapp_pwdcomment']) || !isset($_POST['soap_remoteapp_serviceallowed']) || !isset($_POST['soap_remoteapp_serviceimposedargs']) || !isset($_POST['soap_remoteapp_servicescomment']) ) { $this->manager->error('system_errors', 'postparametermissing_failure'); return; } // Basic mode save / add $name = $_POST['soap_remoteapp_name']; $namecomment = str_replace(array("\n", "\r"), '', $_POST['soap_remoteapp_namecomment']); $pwdh = function_exists('md5') ? md5($_POST['soap_remoteapp_pwd']) : (function_exists('mhash') ? bin2hex(mhash(1, $_POST['soap_remoteapp_pwd'])) : null); $pwd = preg_match('`^[0-9abcdef]{32}$`i', $_POST['soap_remoteapp_pwd']) ? strtolower($_POST['soap_remoteapp_pwd']) : $pwdh; $pwdclear = str_replace(array("\n", "\r"), '', $_POST['soap_remoteapp_pwd']); $pwdcomment = str_replace(array("\n", "\r"), '', $_POST['soap_remoteapp_pwdcomment']); $allowedcomment = str_replace(array("\n", "\r"), '', $_POST['soap_remoteapp_serviceallowedcomment']); $block = '# '.$name.' app'."\n"; $block .= 'name = '.$name.($namecomment != '' ? ' # '.$namecomment : '')."\n"; $block .= 'pwd = '.$pwd.' '.(($pwdclear != $pwd) || ($pwdcomment != '') ? '# '.($pwd != $pwdclear ? '('.$pwdclear.') ' : '').$pwdcomment : '')."\n"; $allowed = array(); include 'soapserver.php'; foreach(get_class_methods('farmSOAP') as $m) { if(strpos($m, 'service_') !== 0) continue; $m = substr($m, 8); if(isset($_POST['soap_remoteapp_serviceallowed'][$m])) $allowed[] = $m.((isset($_POST['soap_remoteapp_serviceimposedargs'][$m]) && !empty($_POST['soap_remoteapp_serviceimposedargs'][$m])) ? '('.$_POST['soap_remoteapp_serviceimposedargs'][$m].')' : ''); } $block .= 'allowed = '.implode(', ', $allowed).($allowedcomment != '' ? ' # '.$allowedcomment : ''); if(isset($this->manager->opt['new']) && isset($this->manager->opt['save'])) { $app = ''; $file = @file_get_contents(DOKU_FARM_PLUGIN.'trusted_apps.php'); if(!$file) { $this->manager->error('soapconfig_errors', 'soapconfig_corruptedfile_failure'); return; } if($fp = fopen(DOKU_FARM_PLUGIN.'trusted_apps.php', 'w')) { fwrite($fp, $file."\n\n".$block); fclose($fp); $this->manager->opt['app'] = $name; $this->manager->success('soapconfig_save_success'); return; }else $this->manager->error('soapconfig_errors', 'soapconfig_save_failure'); } if(isset($this->manager->opt['save']) && isset($this->manager->opt['app'])) { $out = array(); foreach(explode("\n\n", @file_get_contents(DOKU_FARM_PLUGIN.'trusted_apps.php')) as $p) { $appname = ''; foreach(explode("\n", trim($p)) as $f) if(preg_match('`^name\s*=\s*([^#]+)(#.*)?$`i', trim($f), $m)) $appname = trim($m[1]); if($appname != $this->manager->opt['app']) { $out[] = $p; }else $out[] = $block; } if($fp = fopen(DOKU_FARM_PLUGIN.'trusted_apps.php', 'w')) { fwrite($fp, implode("\n\n", $out)); fclose($fp); $this->manager->opt['app'] = $name; $this->manager->success('soapconfig_save_success'); }else $this->manager->error('soapconfig_errors', 'soapconfig_save_failure'); return; } } /** * Renders */ function html() { global $ID; ptln('