public function getCommand(\Net_SFTP $ssh) { $gitCommand = str_replace("\n", '', $ssh->exec('which git')); if ($gitCommand == '') { throw new \Exception('the git command wasn\'t found on this server'); } return $gitCommand; }
/** * @param $command * * @return string */ public function exec($command) { $sftpDir = $this->pwd(); switch ($this->_connType) { case SftpHelper::TYPE_SFTP: default: $execOutput = $this->_connection->exec('cd ' . $sftpDir . ' && ' . $command); $this->_lastExecExitStatus = $this->_connection->getExitStatus(); break; case SftpHelper::TYPE_FTP: // TODO: test ftp_exec on a server which supports it $execOutput = ''; $res = @ftp_exec($this->_connection, 'cd ' . $sftpDir . ' && ' . $command); $this->_lastExecExitStatus = $res ? 0 : 1; break; } return $execOutput; }
<?php session_start(); include 'header.php'; include 'Net/SFTP.php'; $file = $_GET['file']; $sftp = new Net_SFTP(SSH_HOST); if ($sftp->login($_SESSION['id'], $_SESSION['passwd'])) { $sftp->exec('cd $w/meshslicer/conf/; sed -i "2s/.*/' . $file . '/" config.ini'); $resultFiles = array_map('trimFile', array_filter(explode("\n", $sftp->exec('cd $w/meshslicer/results/; ls')))); $check = true; $index = 1; while ($check) { if (!in_array($file . '.out.parts.' . $_SESSION['config'][8] . '.' . $index, $resultFiles)) { $check = false; } else { $index++; } } $outputFile = '../results/' . $file . '.out.parts.' . $_SESSION['config'][8] . '.' . $index; $result = $sftp->exec('cd $w/meshslicer/conf/; module load metis; ./StandAlone > ' . $outputFile); if ($result == "") { if (preg_match('#.mesh$#', $file)) { $_SESSION['fileList'][] = $file . '.out.eparts.' . $_SESSION['config'][8] . '.' . $index; // INDEX $_SESSION['fileList'][] = $file . '.out.nparts.' . $_SESSION['config'][8] . '.' . $index; // INDEX sort($_SESSION['fileList']); } elseif (preg_match('#.graph$#', $file)) { $_SESSION['fileList'][] = $file . '.out.parts.' . $_SESSION['config'][8] . '.' . $index; // INDEX
<?php session_start(); include 'header.php'; include 'Net/SFTP.php'; if (isset($_SESSION['login'])) { $sftp = new Net_SFTP(SSH_HOST); if (!$sftp->login($_SESSION["id"], $_SESSION["passwd"])) { header("location:signin.php?error=1"); } $ls = array_filter(explode("\n", $sftp->exec("cd \$w; ls -d *\\/"))); if (!in_array("meshslicer/", $ls)) { $sftp->exec("cd \$w; mkdir meshslicer; cd meshslicer; mkdir conf; mkdir results; cd conf; touch config.ini; echo '0 0 0 0 0 0 0 1 2 0\nnone' > config.ini"); $sftp->put('/scratch/' . $_SESSION["id"] . '/meshslicer/conf/StandAlone', 'uploads/StandAlone', NET_SFTP_LOCAL_FILE); $sftp->exec("cd \$w/meshslicer/conf/; chmod 777 StandAlone"); } $_SESSION["fileList"] = array_map('trimFile', array_filter(explode("\n", $sftp->exec("cd \$w/meshslicer; find . -maxdepth 1 -not -type d")))); unset($_SESSION["login"]); } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="description" content=""> <meta name="author" content="">