public function Load() { if (!file_exists(DATA . "/settings.php")) { saveJSON('settings.php', array($this->username => array('codiad.username' => $this->username))); } $settings = getJSON('settings.php'); echo formatJSEND("success", $settings[$this->username]); }
public function Run() { $filepath = "{$this->root}/{$this->get['filepath']}"; $tmpfname = tempnam("/tmp", "shipshape-results-"); $fp = fopen($tmpfname, "w"); fclose($fp); $ret = runShellCommand("shipshape --categories='go vet,JSHint,PyLint' --json_output={$tmpfname}" . " {$this->escapeShellArg($filepath)}"); echo formatJSEND('success', json_decode(file_get_contents($tmpfname))); unlink($tmpfname); }
public function Run() { $filepath = "{$this->root}/{$this->get['filepath']}"; // Truncate the output json file. $fp = fopen("/tmp/shipshape-results.json", "w"); fclose($fp); $ret = runShellCommand("shipshape --categories='go vet,JSHint,PyLint'" . " --json_output=/tmp/shipshape-results.json" . " {$this->escapeShellArg($filepath)}"); if ($ret->exit_code != 0) { // If for any reason shipshape command failed, we don't want to show error message. // The reason could be simply that there is no reference at the requested position. echo formatJSEND('success', 'Running shipshape failed.'); return; } echo formatJSEND('success', json_decode(file_get_contents('/tmp/shipshape-results.json'))); }
public function GetUserCount() { /* Array */ $cur_users = array(); foreach ($this->actives as $data) { if (is_array($data) && isset($data['username']) && $data['username'] != $this->username && $data['path'] == $this->path) { $cur_users[] = $data['username']; } } /* Prepare the return data. */ /* Array */ $data = array(); $data['count'] = count($cur_users); echo formatJSEND("success", $data); }
public function Execute() { $macrolist = $this->Load(); $command = $macrolist[$this->id]['c']; if (!$this->isAbsPath($this->path)) { $this->path = WORKSPACE . '/' . $this->path; } if (is_file($this->path)) { $command = str_replace('%FILE%', $this->path, $command); $command = str_replace('%FOLDER%', dirname($this->path), $command); $command = str_replace('%NAME%', basename($this->path), $command); } else { $command = str_replace('%FOLDER%', $this->path, $command); $command = str_replace('%NAME%', basename($this->path), $command); } shell_exec($command); echo formatJSEND("success", null); }
public function pull() { $cli_params = array(); $cli_params[] = "--non-interactive"; if ($this->username != '') { $cli_params[] = "--username " . $this->username; } if ($this->password != '') { //Need to clean up the password so it can be passed to the cli, If anyone find's or thinks of more let me know tholum@couleetechlink.com $this->password = str_replace(array("*", "^", "&", '"'), array('\\*', '\\^', '\\&', '\\"'), $this->password); $cli_params[] = "--password " . $this->password; } if ($this->svnrepo) { if (!$this->isAbsPath($this->path)) { if (!file_exists(WORKSPACE . '/' . $this->path)) { $this->command_exec = "cd " . WORKSPACE . " && svn co \"" . $this->svnrepo . "\" " . $this->path . " " . implode(" ", $cli_params); } else { die(formatJSEND("success", array("message" => "Folder already exists"))); } } else { if (!file_exists($this->path)) { $this->command_exec = "cd " . WORKSPACE . " && svn co \"" . $this->svnrepo . "\" " . $this->path . " " . implode(" ", $cli_params); } else { die(formatJSEND("success", array("message" => "Folder already exists"))); } } if ($this->newproject) { $this->projects = getJSON('projects.php'); $this->projects[] = array("name" => $this->name, "path" => $this->path); saveJSON('projects.php', $this->projects); } $this->ExecuteCMD(); echo formatJSEND("success", array("message" => "Repo cloned")); } else { echo formatJSEND("error", array("message" => "No Repo specified")); } }
public function pull() { if ($this->gitrepo) { if (!$this->isAbsPath($this->path)) { if (!file_exists(WORKSPACE . '/' . $this->path)) { mkdir(WORKSPACE . '/' . $this->path); $this->command_exec = "cd " . WORKSPACE . '/' . $this->path . " && git init && git pull " . $this->gitrepo . " " . $this->gitbranch; } else { die(formatJSEND("success", array("message" => "Folder already exists"))); } } else { if (!file_exists($this->path)) { mkdir($this->path); $this->command_exec = "cd " . $this->path . " && git init && git pull " . $this->gitrepo . " " . $this->gitbranch; } else { die(formatJSEND("success", array("message" => "Folder already exists"))); } } $this->ExecuteCMD(); echo formatJSEND("success", array("message" => "Repo cloned")); } else { echo formatJSEND("error", array("message" => "No Repo specified")); } }
} } else { // Set the session username. $_SESSION['user'] = $User->username; } // Set the session language, if given, or set it to english as default. if (isset($_POST['language'])) { $_SESSION['lang'] = $_POST['language']; } else { $_SESSION['lang'] = "en"; } // Set the session theme and project. $_SESSION['theme'] = $_POST['theme']; $_SESSION['project'] = $_POST['project']; // Respond by sending verification tokens on success. echo formatJSEND("success", array('username' => $User->username)); header("Location: " . $_SERVER['PHP_SELF'] . "?action=verify"); } } elseif ($count > 1) { // We returned too many results. Error as such. die(formatJSEND("error", "A server error occurred: LDAP filter result is non-unique. Please ensure this is a unique identifier within its context.\n\t\t\t\t\t If the problem persists, please contact the webmaster. If you are the webmaster, please check the LDAP filter used.")); } else { // Invalid login. die(formatJSEND("error", "Incorrect user name or password.")); } } else { // The server is having issues connecting to the LDAP server. Error as such. die(formatJSEND("error", "An error occurred: Cannot connect to LDAP server. Please contact the webmaster. \n If you are the webmaster, please contact your LDAP server administrator or check if your LDAP server is running.")); } } }
public function ListBranches() { $repo = Common::GetProjectRoot(); $ret = runShellCommand("git -C {$this->escapeShellArg($repo)} branch --no-color " . " | awk -F ' +' '! /\\(no branch\\)/ {print \$2}' "); if ($ret->exit_code != 0 || count($ret->output) == 0) { echo formatJSEND('error', 'No branches in this project.'); return; } $branches = $ret->output; $currentBranch = $this->GetCurrentBranchName(); $result = new stdClass(); $result->current_branch = trim($currentBranch); $result->branches = $branches; echo formatJSEND('success', $result); }
public function Check() { $local = $this->getLocalVersion(); $remote = $this->getRemoteVersion("check", $local[0]['version']); $nightly = true; $archive = Common::getConstant('ARCHIVEURL', $this->archive); $latest = ''; foreach ($remote as $tag) { if ($latest == '') { $latest = $tag["name"]; $archive = $tag["zipball_url"]; } if ($local[0]['version'] == $tag["commit"]["sha"]) { $local[0]['version'] = $tag["name"]; $nightly = false; break; } } $search = array("\r\n", "\n", "\r"); $replace = array(" ", " ", " "); $message = ''; $merge = ''; $commits = json_decode(file_get_contents(Common::getConstant('COMMITURL', $this->commits)), true); foreach ($commits as $commit) { if ($local[0]['version'] != $commit["sha"]) { if (strpos($commit["commit"]["message"], "Merge") === false) { $message .= '- ' . str_replace($search, $replace, $commit["commit"]["message"]) . '<br/>'; } else { $merge .= '- ' . str_replace($search, $replace, $commit["commit"]["message"]) . '<br/>'; } } else { break; } } if ($message == '') { $message = $merge; } return "[" . formatJSEND("success", array("currentversion" => $local[0]['version'], "remoteversion" => $latest, "message" => $message, "archive" => $archive, "nightly" => $nightly, "name" => $local[0]['name'])) . "]"; }
////////////////////////////////////////////////////////////////// // Change Password ////////////////////////////////////////////////////////////////// if ($_GET['action'] == 'password') { if (!isset($_POST['username']) || !isset($_POST['password'])) { die(formatJSEND("error", "Missing username or password")); } if (checkAccess() || $_POST['username'] == $_SESSION['user']) { $User->username = $_POST['username']; $User->password = $_POST['password']; $User->Password(); } } ////////////////////////////////////////////////////////////////// // Change Project ////////////////////////////////////////////////////////////////// if ($_GET['action'] == 'project') { if (!isset($_GET['project'])) { die(formatJSEND("error", "Missing project")); } $User->username = $_SESSION['user']; $User->project = $_GET['project']; $User->Project(); } ////////////////////////////////////////////////////////////////// // Verify User Account ////////////////////////////////////////////////////////////////// if ($_GET['action'] == 'verify') { $User->username = $_SESSION['user']; $User->Verify(); }
public function Project() { $revised_array = array(); foreach ($this->users as $user => $data) { if ($this->username == $data['username']) { $revised_array[] = array("username" => $data['username'], "password" => $data['password'], "project" => $this->project); } else { $revised_array[] = array("username" => $data['username'], "password" => $data['password'], "project" => $data['project']); } } // Save array back to JSON saveJSON('users.php', $revised_array); // Response echo formatJSEND("success", null); }
public function GetDebuggee($repo_name, $revision_id) { $token = $this->GetAccessToken(); $project_num = $this->GetCloudProjectNum(); // Call API to get a list of all (active) debugees. $opts = array('http' => array('header' => "Authorization: Bearer {$token}\r\n")); $resp = $this->FileGetContents("{$this->gapi_prefix}/debuggees?project={$project_num}", $opts); if ($resp['code'] !== '200') { throw new Exception('Cannot list debuggees for this Google Cloud project.', $resp['code']); } $resp_json = json_decode($resp['body']); // Debuggees may disappear even if an application is currently deployed, // e.g, if an application has gone offline. if (empty($resp_json->debuggees) || !is_array($resp_json->debuggees) || count($resp_json->debuggees) === 0) { throw new Exception('No debuggee exists in this Google Cloud project.'); } // Try to find a best match with the (numeric) project id, repo name, and revision id. foreach ($resp_json->debuggees as $debuggee) { // 'sourceContexts' may not always exist. if ($debuggee->project === $project_num && !empty($debuggee->sourceContexts)) { foreach ($debuggee->sourceContexts as $context) { if (!empty($context->cloudRepo->repoId->projectRepoId)) { $repo = $context->cloudRepo->repoId->projectRepoId; if ($repo->repoName === $repo_name && $context->cloudRepo->revisionId === $revision_id) { // Found a perfect match. Return its id. Return the entire debuggee list together // anyway so that users may manually select one if they wish to. echo formatJSEND('success', array('id' => $debuggee->id, 'list' => $resp_json->debuggees)); return; } } } } } // Did not find a matching debuggee. Return the entire debuggee list anyway. echo formatJSEND('success', array('list' => $resp_json->debuggees)); }
public function Update($type, $name) { function rrmdir($path) { return is_file($path) ? @unlink($path) : @array_map('rrmdir', glob($path . '/*')) == @rmdir($path); } function cpy($source, $dest, $ign) { if (is_dir($source)) { $dir_handle = opendir($source); while ($file = readdir($dir_handle)) { if (!in_array($file, $ign)) { if (is_dir($source . "/" . $file)) { if (!file_exists($dest . "/" . $file)) { mkdir($dest . "/" . $file); } cpy($source . "/" . $file, $dest . "/" . $file, $ign); } else { copy($source . "/" . $file, $dest . "/" . $file); } } } closedir($dir_handle); } else { copy($source, $dest); } } if (file_exists(BASE_PATH . '/' . $type . '/' . $name . '/' . rtrim($type, "s") . '.json')) { $data = json_decode(file_get_contents(BASE_PATH . '/' . $type . '/' . $name . '/' . rtrim($type, "s") . '.json'), true); if (substr($data[0]['url'], -4) == '.git') { $data[0]['url'] = substr($data[0]['url'], 0, -4); } $data[0]['url'] .= '/archive/master.zip'; $ign = array(".", ".."); if (isset($data[0]['exclude'])) { foreach (explode(",", $data[0]['exclude']) as $exclude) { array_push($ign, $exclude); } } if (file_exists(BASE_PATH . '/' . $type . '/_' . session_id()) || mkdir(BASE_PATH . '/' . $type . '/_' . session_id())) { if (file_put_contents(BASE_PATH . '/' . $type . '/_' . session_id() . '/' . $name . '.zip', fopen($data[0]['url'], 'r'))) { $zip = new ZipArchive(); $res = $zip->open(BASE_PATH . '/' . $type . '/_' . session_id() . '/' . $name . '.zip'); // open downloaded archive if ($res === true) { // extract archive if ($zip->extractTo(BASE_PATH . '/' . $type . '/_' . session_id() . '') === true) { $zip->close(); $srcname = $name; if (substr($srcname, -6) != "master") { $srcname = $srcname . '-master'; } cpy(BASE_PATH . '/' . $type . '/_' . session_id() . '/' . $srcname, BASE_PATH . '/' . $type . '/' . $name, $ign); } else { die(formatJSEND("error", "Unable to open " . $name . ".zip")); } } else { die(formatJSEND("error", "ZIP Extension not found")); } rrmdir(BASE_PATH . '/' . $type . '/_' . session_id()); // Response echo formatJSEND("success", null); } else { die(formatJSEND("error", "Unable to download " . $repo)); } } else { die(formatJSEND("error", "Unable to create temp dir ")); } } else { echo formatJSEND("error", "Unable to find " . $name); } }
// Save array back to JSON and set the session username. $User->users[] = array('username' => $User->username, 'password' => null, 'project' => ""); saveJSON("users.php", $User->users); $_SESSION['user'] = $User->username; } else { // Deny login and send message, the user doesn't exist within users.php. die(formatJSEND("error", "User " . $User->username . " does not exist within Codiad.")); } } else { // Set the session username. $_SESSION['user'] = $User->username; } // Set the session language, if given, or set it to english as default. if (isset($_POST['language'])) { $_SESSION['lang'] = $_POST['language']; } else { $_SESSION['lang'] = "en"; } // Set the session theme and project. $_SESSION['theme'] = $_POST['theme']; $_SESSION['project'] = $_POST['project']; // Respond by sending verification tokens on success. echo formatJSEND("success", array('username' => $User->username)); header("Location: " . $_SERVER['PHP_SELF'] . "?action=verify"); } else { // Invalid login. die(formatJSEND("error", "Invalid user name or password.")); } } } }
} } ////////////////////////////////////////////////////////////////// // Rename Project ////////////////////////////////////////////////////////////////// if ($_GET['action'] == 'rename') { if (!checkPath($_GET['project_path'])) { die(formatJSEND("error", "No Access")); } $Project->path = $_GET['project_path']; $Project->Rename(); } ////////////////////////////////////////////////////////////////// // Delete Project ////////////////////////////////////////////////////////////////// if ($_GET['action'] == 'delete') { if (checkAccess()) { $Project->path = $_GET['project_path']; $Project->Delete(); } } ////////////////////////////////////////////////////////////////// // Return Current ////////////////////////////////////////////////////////////////// if ($_GET['action'] == 'current') { if (isset($_SESSION['project'])) { echo formatJSEND("success", $_SESSION['project']); } else { echo formatJSEND("error", "No Project Returned"); } }
public function GetLocalRefs() { $filepath = $this->escapeShellArg(str_replace($this->project . '/', '', $this->get['filepath'])); $fileTicket = $this->escapeShellArg($this->GetFileTicket($filepath)); $dirtyBuffer = $this->escapeShellArg("{$this->root}/{$this->get['filepath']}"); $cursor = $this->get['cursor']; $ret = runShellCommand("/opt/kythe/tools/kythe --json" . " -api http://localhost:" . KYTHE_SERVER_PORT . " refs --dirty {$dirtyBuffer} {$fileTicket}"); if ($ret->exit_code != 0 || count($ret->output) == 0) { // If for any reason kythe command failed, we don't want to show error message. // The reason could be simply that there is no reference at the requested position. echo formatJSEND('success'); return; } $kythe_refs = json_decode($ret->output[0]); // Go through the kythe's response and build three maps which are addressable by tickets. $refs_target = array(); $refs_source = array(); $nodes = array(); $matchedLocationTickets = array(); foreach ($kythe_refs->reference as $reference) { if (!isset($refs_target[$reference->target_ticket])) { $refs_target[$reference->target_ticket] = array(); } if (!isset($refs_source[$reference->source_ticket])) { $refs_source[$reference->source_ticket] = array(); } $refs_target[$reference->target_ticket][] = $reference; $refs_source[$reference->source_ticket][] = $reference; } foreach ($kythe_refs->node as $node) { $nodes[$node->ticket] = $node; if ($this->LocationMatches($node, $cursor)) { $matchedLocationTickets[] = $refs_source[$node->ticket][0]->target_ticket; } } $ref_locations = array(); // Go through all the nodes in the file. If the location of the node // matches that of the cursor, then use the node's ticket to find all of // the references which target ticket is the same as node's ticket. // For those references get the location of the nodes whose tickets are // the same as the reference's source. foreach ($matchedLocationTickets as $t) { foreach ($refs_target[$t] as $target_ref) { $ref_locations[] = $this->GetLocation($nodes[$target_ref->source_ticket]); } } echo formatJSEND('success', $ref_locations); }
public function MarkFileAsFocused() { foreach ($this->actives as $active => $data) { if (is_array($data) && isset($data['username']) && $this->username == $data['username']) { $this->actives[$active]['focused'] = false; if ($this->path == $data['path']) { $this->actives[$active]['focused'] = true; } } } saveJSON('active.php', $this->actives); echo formatJSEND("success"); }
public static function checkSession() { // Set any API keys $api_keys = array(); // Check API Key or Session Authentication $key = ""; if (isset($_GET['key'])) { $key = $_GET['key']; } if (!isset($_SESSION['user']) && !in_array($key, $api_keys)) { echo formatJSEND('error', 'Session expired. Please refresh your page.'); exit(1); } }
$_GET['no_return'] = 'true'; require_once '../project/controller.php'; } // Release a lock on '$_SESSION'. No one writes to it. session_write_close(); ////////////////////////////////////////////////////////////////// // Handle Action ////////////////////////////////////////////////////////////////// $debugger = new CloudDebugger(); try { switch ($action) { case 'get_debuggee': $debugger->GetDebuggee($_GET['repo_name'], $_GET['revision_id']); break; case 'set_breakpoint': $debugger->SetBreakpoint($_POST['debuggee_id'], $_POST['path'], $_POST['line'], $_POST['cond'], $_POST['exprs']); break; case 'get_breakpoint': $debugger->GetBreakpoint($_GET['did'], $_GET['bid'], $_GET['ignore_err']); break; case 'delete_breakpoint': $debugger->DeleteBreakpoint($_GET['did'], $_GET['bid']); break; default: exit('{"status":"error","message":"Unknown Action"}'); } } catch (Exception $e) { // If a response code is set, print it too. $code = empty($e->getCode()) ? '' : " [code: {$e->getCode()}]"; echo formatJSEND('error', $e->getMessage() . $code); }
public function Remove() { foreach ($this->actives as $active => $data) { if ($this->username == $data['username'] && $this->path == $data['path']) { unset($this->actives[$active]); } } saveJSON('active.php', $this->actives); echo formatJSEND("success"); }
public function Delete() { $revised_array = array(); foreach ($this->projects as $project => $data) { if ($data['path'] != $this->path) { $revised_array[] = array("name" => $data['name'], "path" => $data['path']); } } // Save array back to JSON saveJSON('projects.php', $revised_array); // Response echo formatJSEND("success", null); }
if ($currentTime - $heartbeatTime > $maxHeartbeatInterval) { /* The $user heartbeat time is too old, consider him dead and * remove his 'registered' and 'heartbeat' marker files. */ unregisterFromAllFiles($user); removeHeartbeatMarker($user); onCollaboratorDisconnect($user); } } /* Return the number of connected collaborators. */ $collaboratorCount = count(getUsersAndHeartbeatTime()); $data = array(); $data['collaboratorCount'] = $collaboratorCount; echo formatJSEND('success', $data); break; default: exit(formatJSEND('error', 'Unknown Action ' . $_POST['action'])); } // -------------------- /* $filename must contain only the basename of the file. */ function isUserRegisteredForFile($filename, $user) { $query = array('user' => $user, 'filename' => $filename); $entry = getDB()->select($query, 'registered'); return $entry != null; } /* Unregister the given user from all the files by removing his * 'registered' marker file. */ function unregisterFromAllFiles($user) { $query = array('user' => $user, 'filename' => '*'); $entries = getDB()->select($query, 'registered');
////////////////////////////////////////////////////////////////// // Send a message. ////////////////////////////////////////////////////////////////// if ($_GET['action'] == 'send') { $Message->sender = $_SESSION['user']; $Message->recipient = $_GET['recipient']; $Message->message = $_GET['message']; $results = $Message->Create(); if ($results != null) { echo formatJSEND("success"); } else { echo formatJSEND("error", "Error: Your message could not be sent."); } } ////////////////////////////////////////////////////////////////// // Check for a new message. ////////////////////////////////////////////////////////////////// if ($_GET['action'] == 'checknew') { $Message->recipient = $_SESSION['user']; $data = $Message->CheckNew(); echo formatJSEND("success", $data); } ////////////////////////////////////////////////////////////////// // Mark all messages as read. ////////////////////////////////////////////////////////////////// if ($_GET['action'] == 'markallread') { $Message->sender = $_GET['sender']; $Message->recipient = $_SESSION['user']; $Message->MarkAllRead(); echo formatJSEND("success"); }
* as-is and without warranty under the MIT License. See * [root]/license.txt for more. This information must remain intact. */ require_once '../../common.php'; require_once 'class.settings.php'; if (!isset($_GET['action'])) { die(formatJSEND("error", "Missing parameter")); } ////////////////////////////////////////////////////////////////// // Verify Session or Key ////////////////////////////////////////////////////////////////// checkSession(); $Settings = new Settings(); ////////////////////////////////////////////////////////////////// // Save User Settings ////////////////////////////////////////////////////////////////// if ($_GET['action'] == 'save') { if (!isset($_POST['settings'])) { die(formatJSEND("error", "Missing settings")); } $Settings->username = $_SESSION['user']; $Settings->settings = json_decode($_POST['settings'], true); $Settings->Save(); } ////////////////////////////////////////////////////////////////// // Load User Settings ////////////////////////////////////////////////////////////////// if ($_GET['action'] == 'load') { $Settings->username = $_SESSION['user']; $Settings->Load(); }