/** * View a session * * @return void */ public function viewTask() { // Check that the user is logged in if (User::isGuest()) { $this->loginTask(); return; } // Incoming $app = new stdClass(); //array(); $app->sess = Request::getInt('sess', 0); // Make sure we have an app to invoke if (!$app->sess) { App::redirect(Route::url($this->config->get('stopRedirect', 'index.php?option=com_members&task=myaccount')), Lang::txt('COM_TOOLS_ERROR_SESSION_NOT_FOUND'), 'error'); return; } $this->view->rtrn = Request::getVar('return', ''); // Get the user's IP address $app->ip = Request::ip(); //Request::getVar('REMOTE_ADDR', '', 'server'); // Double-check that the user can view this session. $mwdb = \Components\Tools\Helpers\Utils::getMWDBO(); $ms = new \Components\Tools\Tables\Session($mwdb); $row = $ms->loadSession($app->sess, $this->config->get('access-manage-session')); if (!is_object($row) || !$row->appname) { App::abort(404, Lang::txt('COM_TOOLS_ERROR_SESSION_NOT_FOUND') . ': ' . $app->sess); return; } $this->view->middleware = new \Components\Tools\Models\Middleware(); //$session = $this->view->middleware->session($app->sess); include_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'version.php'; $tv = new \Components\Tools\Tables\Version($this->database); $tv->loadFromInstance($row->appname); $this->database->setQuery("SELECT zone_id FROM `#__tool_version_zone` WHERE tool_version_id=" . $this->database->quote($tv->id)); $this->view->middleware->set('allowed', $this->database->loadColumn()); $this->view->zone = $this->view->middleware->zone($row->zone_id); if (strstr($row->appname, '_')) { $v = substr(strrchr($row->appname, '_'), 1); $v = str_replace('r', '', $v); Request::setVar('version', $v); } // Get parent tool name - to write correct links //$tv = new \Components\Tools\Tables\Version($this->database); $parent_toolname = $tv->getToolname($row->appname); $toolname = $parent_toolname ? $parent_toolname : $row->appname; // Get the tool's name //$tv->loadFromInstance($row->appname); $app->title = stripslashes($tv->title); $app->params = new \Hubzero\Config\Registry($tv->params); // Ensure we found an active session if (!$row->sesstoken) { App::abort(404, Lang::txt('MW_ERROR_SESSION_NOT_FOUND') . ': ' . $app->sess . '. ' . Lang::txt('MW_SESSION_NOT_FOUND_EXPLANATION')); return; } // Get their disk space usage $app->percent = 0; if ($this->config->get('show_storage')) { $this->_getDiskUsage('soft', false); $app->percent = $this->percent; } // Build the view command if ($this->config->get('access-manage-session')) { $command = "view user="******" ip=" . $app->ip . " sess=" . $app->sess; } else { $command = "view user="******" ip=" . $app->ip . " sess=" . $app->sess; } // Check if we have access to run this tool. // If not, force view to be read-only. // This will happen in the event of sharing. $noaccess = $this->_getToolAccess($row->appname) == false; if ($this->getError()) { echo '<!-- ' . $this->getError() . ' -->'; } if ($noaccess) { $command .= " readonly=1"; } $app->caption = $row->sessname; $app->name = $row->appname; $app->username = $row->username; $app->owns = $ms->checkSession($app->sess); // Get plugins Plugin::import('mw', $app->name); // Trigger any events that need to be called before session start Event::trigger('mw.onBeforeSessionStart', array($toolname, $tv->revision)); // Call the view command $status = $this->middleware($command, $output); // If weber_auth is defined, set a cookie for it. if (isset($output->weber_auth)) { $domain = rtrim(Request::base(), '/'); $domain = preg_replace('/^http:\\/\\//', '', $domain); $domain = preg_replace('/^https:\\/\\//', '', $domain); $name = 'weber-auth-' . preg_replace('/\\./', '-', $domain); $secure = true; $httponly = true; setcookie($name, $output->weber_auth, time() + 86400 * 30, "/", $domain, $secure, $httponly); } // If this is something other than VNC, such as Jupyter, // redirect to the proxy URL provided. And we're done. if (isset($output->redirect_url)) { App::Redirect($output->redirect_url); return; // Do no more after this. } if ($app->params->get('vncEncoding', 0)) { $output->encoding = trim($app->params->get('vncEncoding', ''), '"'); } if ($app->params->get('vncShowControls', 0)) { $output->show_controls = trim($app->params->get('vncShowControls', ''), '"'); } if ($app->params->get('vncShowLocalCursor', 0)) { $output->show_local_cursor = trim($app->params->get('vncShowLocalCursor', ''), '"'); } if ($app->params->get('vncDebug', 0)) { $output->debug = trim($app->params->get('vncDebug', ''), '"'); } foreach ($output as $key => $value) { $output->{$key} = strval($value); } $boolean_keys = array('debug', 'show_local_cursor', 'show_controls', 'view_only', 'trust_all_vnc_certs', 'view_only', 'wsproxy_encrypt'); foreach ($boolean_keys as $key) { if (isset($output->{$key})) { $value = strtolower($output->{$key}); if (in_array($value, array('1', 'y', 'on', 'yes', 't', 'true'))) { $output->{$key} = 'Yes'; } else { $output->{$key} = 'No'; } } } if (empty($output->wsproxy_host)) { $output->wsproxy_host = $_SERVER['SERVER_NAME']; } if (empty($output->wsproxy_port)) { $output->wsproxy_port = '8080'; } if (!isset($output->wsproxy_encrypt)) { $output->wsproxy_encrypt = 'No'; } if (!isset($output->view_only)) { $output->view_only = 'No'; } if (!isset($output->trust_all_vnc_certs)) { $output->trust_all_vnc_certs = 'Yes'; } if (!isset($output->disableSSL)) { $output->disable_ssl = 'No'; } if (!isset($output->name)) { $output->name = 'App Viewer'; } if (!isset($output->offer_relogin)) { $output->offer_relogin = '******'; } if (!isset($output->permissions)) { $output->permissions = 'all-permissions'; } if (!isset($output->code)) { $output->code = 'VncViewer.class'; } if (!isset($output->archive)) { $output->archive = rtrim(Request::base(true), '/') . '/core/components/com_tools/scripts/VncViewer-20150319-01.jar'; } if (!isset($output->id)) { $output->id = 'theapp'; } if (!isset($output->host)) { $output->host = $_SERVER['SERVER_NAME']; } if (!isset($output->password) && !empty($output->encpassword)) { $decpassword = pack("H*", $output->encpassword); $output->password = \Components\Tools\Helpers\Vnc::decrypt($decpassword); } if (!isset($output->token) && !empty($output->connect)) { if (strncmp($output->connect, 'vncsession:', 11) == 0) { $output->token = substr($output->connect, 11); } } if (empty($output->class)) { $cls = array(); if ($app->params->get('noResize', 0)) { $cls[] = 'no-resize'; } if ($app->params->get('noPopout', 0)) { $cls[] = 'no-popout'; } if ($app->params->get('noPopoutClose', 0)) { $cls[] = 'no-popout-close'; } if ($app->params->get('noPopoutMaximize', 0)) { $cls[] = 'no-popout-maximize'; } if ($app->params->get('noRefresh', 0)) { $cls[] = 'no-refresh'; } $output->class = "thisapp"; if (!empty($cls)) { $output->class .= ' ' . implode(' ', $cls); } } // Trigger any events that need to be called after session start Event::trigger('mw.onAfterSessionStart', array($toolname, $tv->revision)); // Set the layout $sublayout = strtolower(Request::getWord('layout', '')); $sublayout = $sublayout == 'display' ? '' : $sublayout; $this->view->setLayout('session' . ($sublayout ? '_' . $sublayout : '')); // Set the page title $title = Lang::txt('COM_RESOURCES') . ': ' . Lang::txt('COM_TOOLS'); $title .= $app->title ? ': ' . $app->title : ': ' . $app->name; $title .= ': ' . Lang::txt('Session'); $title .= $app->caption ? ': ' . $app->sess . ' "' . $app->caption . '"' : ': ' . $app->sess; Document::setTitle($title); // Set the breadcrumbs if (Pathway::count() <= 0) { Pathway::append(Lang::txt('COM_RESOURCES'), 'index.php?option=com_resources'); } Pathway::append(Lang::txt('COM_TOOLS'), 'index.php?option=com_resources&type=tools'); Pathway::append($app->title, 'index.php?option=' . $this->_option . '&controller=' . $this->controller . '&app=' . $toolname); if ($this->_task) { $t = $app->caption ? $app->sess . ' "' . $app->caption . '"' : $app->sess; Pathway::append(Lang::txt('COM_TOOLS_SESSION_NUMBER', $t), 'index.php?option=' . $this->_option . '&controller=' . $this->controller . '&app=' . $toolname . '&task=session&sess=' . $app->sess); } // Get users groups $this->view->mygroups = \Hubzero\User\Helper::getGroups(User::get('id'), 'members', 1); $this->view->app = $app; $this->view->config = $this->config; $this->view->output = $output; $this->view->toolname = $toolname; $this->view->total = $this->total; // Get everyone sharing this session if ($app->sess) { // Get the middleware database $mwdb = \Components\Tools\Helpers\Utils::getMWDBO(); // Load the viewperm $ms = new \Components\Tools\Tables\Viewperm($mwdb); $this->view->shares = $ms->loadViewperm($app->sess); } // Set any error messages foreach ($this->getErrors() as $error) { $this->view->setError($error); } // Output HTML $this->view->display(); }
/** * Method to view tool session * * @apiMethod GET * @apiUri /tools/{session} * @return void */ public function readTask() { //get the userid and attempt to load user profile $userid = App::get('authn')['user_id']; $result = User::getInstance($userid); //make sure we have a user if (!$result->get('id')) { throw new Exception(Lang::txt('Unable to find user.'), 404); } //include needed tool libs include_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'version.php'; require_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'session.php'; require_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'viewperm.php'; //instantiate db objects $database = \App::get('db'); $mwdb = \Components\Tools\Helpers\Utils::getMWDBO(); //get request vars $sessionid = Request::getVar('sessionid', ''); $ip = Request::ip(); //make sure we have the session if (!$sessionid) { throw new Exception(Lang::txt('Session ID Needed'), 400); } //create app object $app = new stdClass(); $app->sess = $sessionid; $app->ip = $ip; //load the session $ms = new \Components\Tools\Models\Middleware\Session($mwdb); $row = $ms->loadSession($app->sess); //if we didnt find a session if (!is_object($row) || !$row->appname) { throw new Exception(Lang::txt('Session Doesn\'t Exist.'), 404); } //get the version if (strstr($row->appname, '_')) { $v = substr(strrchr($row->appname, '_'), 1); $v = str_replace('r', '', $v); Request::setVar('version', $v); } //load tool version $tv = new \Components\Tools\Tables\Version($database); $parent_toolname = $tv->getToolname($row->appname); $toolname = $parent_toolname ? $parent_toolname : $row->appname; $tv->loadFromInstance($row->appname); //command to run on middleware $command = "view user="******" ip=" . $app->ip . " sess=" . $app->sess; //app vars $app->caption = $row->sessname; $app->name = $row->appname; $app->username = $row->username; // Get plugins Plugin::import('mw', $app->name); // Trigger any events that need to be called before session start Event::trigger('mw.onBeforeSessionStart', array($toolname, $tv->revision)); // Call the view command $status = \Components\Tools\Helpers\Utils::middleware($command, $output); // Trigger any events that need to be called after session start Event::trigger('mw.onAfterSessionStart', array($toolname, $tv->revision)); //add the session id to the result $output->session = $sessionid; //add tool title to result $output->tool = $tv->title; $output->session_title = $app->caption; $output->owner = $row->viewuser == $row->username ? 1 : 0; $output->readonly = $row->readonly == 'Yes' ? 1 : 0; //return result if ($status) { $this->send($output); } }