$php_bin_set = true; switch ($php_bin_sapi) { case 'cli': break; case 'cgi': print "\n*NOTICE*\nWe found php.exe under {$php_bin}, it uses a {$php_bin_sapi} SAPI. PEAR commandline\ntool works well with it, if you have a CLI php.exe available, we\nrecommand to use it.\n"; break; default: print "\n*WARNING*\nWe found php.exe under {$php_bin}, it uses an unknown SAPI. PEAR commandline\ntool has not been tested with it, if you have a CLI (or CGI) php.exe available,\nwe strongly recommand to use it.\n\n"; break; } } #### # Temp stuff #### $foo = tmp_dir(); $ptmp = tempnam($foo, 'gope'); if (WINDOWS) { $ptmp = str_replace($foo, '', $ptmp); $foo = str_replace("\\\\", '/', $foo); $s = substr($ptmp, 0, 1); if ($s == "\\" || $s == '/') { $ptmp = $foo . '/' . substr($ptmp, 1); } else { $ptmp = $foo . '/' . $ptmp; } } rm_rf($ptmp); mkdir_p($ptmp, 0700); $ok = @chdir($ptmp); // If for some reason the user has no rights to access to
/** * Delete a temporary (working) repository * @param $param[1] temporary repository */ function api_post_temp_delete($param = array()) { $temp = $param[1]; if (!@is_dir(tmp_dir($temp))) { router_error_404('Cannot get ' . $temp); } if (false === rm_recursive(tmp_dir($temp))) { router_error_500('Cannot delete ' . $temp); } return true; }
$php_bin_set = true; switch ($php_bin_sapi) { case 'cli': break; case 'cgi': print "\n*NOTICE*\nWe found php.exe under {$php_bin}, it uses a {$php_bin_sapi} SAPI. PEAR commandline\ntool works well with it, if you have a CLI php.exe available, we\nrecommand to use it.\n"; break; default: print "\n*WARNING*\nWe found php.exe under {$php_bin}, it uses an unknown SAPI. PEAR commandline\ntool has not been tested with it, if you have a CLI (or CGI) php.exe available,\nwe strongly recommand to use it.\n\n"; break; } } #### # Temp stuff #### tmp_dir(); $foo = $ptmp; $ptmp = tempnam($foo, 'gope'); if (WINDOWS) { $ptmp = str_replace($foo, '', $ptmp); $foo = str_replace("\\\\", '/', $foo); $s = substr($ptmp, 0, 1); if ($s == "\\" || $s == '/') { $ptmp = $foo . '/' . substr($ptmp, 1); } else { $ptmp = $foo . '/' . $ptmp; } } rm_rf($ptmp); mkdir_p($ptmp, 0700); $ok = @chdir($ptmp);
function inject_uploaded_file($tmp_key, $file, $auto_convert = true) { // establish destination filename $dest_fn = get_uploaded_file_dest_fn($tmp_key, $file['name'], $file['type'], $file['tmp_name']); if ($dest_fn === false) { return array(); } // make sure the containing directories exist create_containing_dir(tmp_dir($tmp_key) . '/' . $dest_fn); // move to destination if (false === @move_uploaded_file($file['tmp_name'], tmp_dir($tmp_key) . '/' . $dest_fn)) { return array(); } if ($auto_convert) { // convert Word documents instantaneously to Markdown $start = time(); if (filext($dest_fn) === 'docx') { make_run(tmp_dir($tmp_key), 'markdowns'); // XXX (later): run "make clean" here? } $modified_after = repo_get_modified_files_after($tmp_key, $start - 1); // make sure the destination filename is part of th array if (is_array($modified_after) && !in_array($dest_fn, $modified_after)) { $modified_after[] = $dest_fn; } return $modified_after; } return array($dest_fn); }
echo 'done'; } echo "\n"; echo "\n" . 'Checking Pandoc... '; $pandoc_ver = get_pandoc_version(); if ($pandoc_ver === false) { echo 'Not installed' . "\n"; } else { echo $pandoc_ver . "\n"; } echo "\n" . 'Checking content dir... '; if (check_content_dir()) { echo 'done' . "\n"; } else { echo 'failed. Make sure the webserver process can write to ' . config('content_dir') . '.' . "\n"; } echo "\n" . 'Checking cache health... '; if (check_cache_lru()) { echo 'done' . "\n"; } else { echo 'failed. Some files in ' . config('content_dir') . '/cache might not be removable by the webserver process.' . "\n"; } echo "\n" . 'Checking tmp dir health... '; if (check_tmp_dir_age()) { echo 'done' . "\n"; } else { echo 'failed. Some files in ' . config('content_dir') . '/tmp might not be removable by the webserver process.' . "\n"; } echo "\n" . 'Checking available disk space... '; echo disk_free_space(tmp_dir('')) . ' bytes' . "\n"; echo "\n" . 'All done.';
function github_post_push($param = array()) { $commit_msg_prefix = 'Regenerate output files'; $payload = json_decode($param['payload'], true); // prevent error on "ping" notifications if (!isset($payload['head_commit']['message'])) { return 'Not a commit'; } // prevent recursions if (substr($payload['head_commit']['message'], 0, strlen($commit_msg_prefix)) === $commit_msg_prefix) { return 'Not acting on my own changes'; } // ref is like "refs/heads/master" $branch = @array_pop(explode('/', $payload['ref'])); $tmp_key = get_repo($payload['repository']['clone_url'], $branch, true); if ($tmp_key === false) { router_error_500('Error getting branch ' . $branch . ' of ' . $payload['repository']['clone_url']); } $ret_val = make_run(tmp_dir($tmp_key), 'all', $out); // run "make clean" to remove temporary files (but not output files, that's the idea) make_run(tmp_dir($tmp_key), 'clean'); $modified = repo_get_modified_files($tmp_key); if (empty($modified) && $ret_val === 0) { // nothing to commit, no error return 'No changes'; } $ret = repo_stage_files($tmp_key, $modified); if ($ret === false) { router_error_500('Error staging files ' . implode(', ', $modified) . ' to ' . $tmp_key); } // setup commit message $msg = $commit_msg_prefix; // this needs to come first if ($ret_val !== 0) { $msg .= ' (error)' . "\n\n"; $msg .= 'The process returned error code ' . $ret_val . '. '; } else { $msg .= "\n\n"; } $msg .= 'The version of Pandoc used is ' . get_pandoc_version() . '.' . "\n\n"; $msg .= 'Output:' . "\n"; $msg .= implode("\n", $out); $ret = repo_commit($tmp_key, $msg); if ($ret === false) { router_error_500('Error committing ' . $tmp_key); } $ret = repo_push($tmp_key, $payload['repository']['ssh_url']); if ($ret === false) { router_error_500('Error pushing to ' . $payload['repository']['ssh_url']); } // count the number of collaborators $seen = array(); foreach ($payload['commits'] as $commit) { if (!in_array($commit['author']['email'], $seen)) { $seen[] = $commit['author']['email']; } } if (1 < $seen) { // subtract the sausage machine $seen--; } // XXX (later): create helper functions, make atomic $s = @file_get_contents(rtrim(config('content_dir', 'content'), '/') . '/projects.json'); $projects = @json_decode($s, true); if (!@is_array($projects)) { $projects = array(); } foreach ($projects as &$p) { if ($payload['repository']['full_name'] === $p['github_repo']) { $p['updated'] = time(); $p['collaborators'] = count($seen); } } $old_umask = @umask(00); @file_put_contents(rtrim(config('content_dir', 'content'), '/') . '/projects.json', json_encode($projects)); @umask($old_umask); return 'Success'; }
/** * Prevent the repository from being automatically cleaned after a set time * @param $tmp_key tmp key */ function repo_touch($tmp_key) { // update file modification time @touch(tmp_dir($tmp_key)); }