/** * Method to setup Windows filesharing connection * * @apiMethod GET * @apiUri /tools/{sessionid}/fileshare * @apiParameter { * "name": "sessionid", * "description": "Tool session identifier", * "type": "integer", * "required": true, * "default": 0 * } * @apiParameter { * "name": "username", * "description": "Username", * "type": "string", * "required": false, * "default": null * } * @apiParameter { * "name": "private_ip", * "description": "Private IP Address", * "type": "string", * "required": false, * "default": null * } * @apiParameter { * "name": "public_ip", * "description": "Public IP Address", * "type": "string", * "required": false, * "default": null * } * @return void * * * * @TODO: This is just a rough draft. needs a little polishing. * */ public function fileshareTask() { //$this->requiresAuthentication(); require_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'session.php'; require_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'viewperm.php'; // instantiate middleware database object $mwdb = \Components\Tools\Helpers\Utils::getMWDBO(); // get any request vars $username = Request::getVar('username'); $sessionid = Request::getVar('id'); $private_ip = Request::getVar('private_ip'); $public_ip = Request::getVar('public_ip', Request::ip()); // check to make sure we have a valid sessionid if ($sessionid == '' || !is_numeric($sessionid)) { throw new Exception(Lang::txt('No session ID Specified.'), 401); } // load session $ms = new \Components\Tools\Tables\Session($mwdb); $sess = $ms->loadSession($sessionid); $command = "/usr/bin/sudo /usr/bin/hzappstream --remote 128.46.19.124 fileshare add {$username} {$sessionid} {$public_ip} {$private_ip} --ipsec-use-default-psk"; $command = escapeshellcmd($command); $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w")); $process = proc_open($command, $descriptorspec, $pipes, "/", NULL); if (is_resource($process)) { // $pipes now looks like this: // 0 => writeable handle connected to child stdin // 1 => readable handle connected to child stdout // Any error output will be appended to /tmp/error-output.txt fclose($pipes[0]); $output = stream_get_contents($pipes[1]); fclose($pipes[1]); $error = stream_get_contents($pipes[2]); fclose($pipes[2]); // It is important that you close any pipes before calling // proc_close in order to avoid a deadlock $return_value = proc_close($process); $output = strstr($output, '{'); $joutput = json_decode($output); $object = array('fileserver' => '128.46.19.124', 'username' => $username, 'session' => $sessionid, 'ipsec_ip1' => $public_ip, 'ipsec_ip2' => $private_ip, 'smb_username' => 'smb-' . $sessionid); $object['smb_password'] = $joutput->smb_password; } else { $object = array('fileserver' => '128.46.19.124', 'username' => $username, 'session' => $sessionid, 'ipsec_ip1' => $public_ip, 'ipsec_ip2' => $private_ip, 'ipsec_password' => NULL, 'smb_username' => 'smb-' . $sessionid, 'smb_password' => NULL); } $this->send($object); }
/** * 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 return session screenshot * * @apiMethod GET * @apiUri /tools/{sessionid}/screenshot * @apiParameter { * "name": "sessionid", * "description": "Tool session identifier", * "type": "integer", * "required": true, * "default": 0 * } * @apiParameter { * "name": "type", * "description": "Image format", * "type": "string", * "required": false, * "default": "png", * "allowedValues": "png, jpg, jpeg, gif" * } * @apiParameter { * "name": "notfound", * "description": "Not found", * "type": "integer", * "required": false, * "default": 0 * } * @return void */ public function screenshotTask() { $this->requiresAuthentication(); require_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'session.php'; require_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'viewperm.php'; //instantiate middleware database object $mwdb = \Components\Tools\Helpers\Utils::getMWDBO(); //get any request vars $type = Request::getVar('type', 'png'); $sessionid = Request::getVar('sessionid', ''); $notFound = Request::getVar('notfound', 0); $image_type = IMAGETYPE_PNG; if ($type == 'jpeg' || $type == 'jpg') { $image_type = IMAGETYPE_JPEG; } else { if ($type == 'gif') { $image_type = IMAGETYPE_GIF; } } //check to make sure we have a valid sessionid if ($sessionid == '' || !is_numeric($sessionid)) { throw new Exception(Lang::txt('No session ID Specified.'), 401); } //load session $ms = new \Components\Tools\Tables\Session($mwdb); $sess = $ms->loadSession($sessionid); //check to make sure we have a sessions dir $home_directory = DS . 'webdav' . DS . 'home' . DS . strtolower($sess->username) . DS . 'data' . DS . 'sessions'; if (!is_dir($home_directory)) { clearstatcache(); if (!is_dir($home_directory)) { throw new Exception(Lang::txt('Unable to find users sessions directory: %s', $home_directory), 404); } } //check to make sure we have an active session with the ID supplied $home_directory .= DS . $sessionid . '{,L,D}'; $directories = glob($home_directory, GLOB_BRACE); if (empty($directories)) { throw new Exception(Lang::txt('No Session directory with the ID: %s', $sessionid), 404); } else { $home_directory = $directories[0]; } // check to make sure we have a screenshot $screenshot = $home_directory . DS . 'screenshot.png'; if (!file_exists($screenshot)) { if ($notFound) { $screenshot = dirname(dirname(__DIR__)) . DS . 'site' . DS . 'assets' . DS . 'img' . DS . 'screenshot-notfound.png'; } else { throw new Exception(Lang::txt('No screenshot Found.'), 404); } } // Load image and serve up $image = new \Hubzero\Image\Processor($screenshot); $image->setImageType($image_type); $this->send($image->inline(), 200); }