hello linter??

This commit is contained in:
Letter N
2020-12-29 11:49:03 +08:00
parent 3c1cfca9c5
commit 08c94a408c
2 changed files with 43 additions and 241 deletions

View File

@@ -1,198 +0,0 @@
<?php
//Tool for web based TGUI compilation
//by Cyberboss
//RESTRICTIONS
//Restricted to Windows for now because it uses mklink cmd function
//INSTALLATION
//Setup PHP
//Place this file in it's own directory and rewrite all requests to the directory to this file
//add extension=php_fileinfo.dll to php.ini
//ensure fastcgi.impersonate is set to 0 in php.ini
//clone a tgui repository and place next to this file
//run install_dependencies.bat
//MOVE (not copy) the node_modules folder next to this file
try{
//CONFIG
$repo_dir = 'tgstation';
$path_to_tgui_from_repo = '/tgui';
$full_path_to_gulp = 'C:/Users/Cyberboss/AppData/Roaming/npm/gulp'; //this needs to be read/executable by the PHP app pool
$max_number_of_uploads = 20;
//END CONFIG
function getGitRevision()
{
global $tgdir;
$rev = trim(file_get_contents($tgdir . '/.git/HEAD'));
if (substr($rev, 0, 4) == 'ref:') {
$tmp = explode('/', $rev);
$ref = end($tmp);
$rev = trim(file_get_contents($tgdir . "/.git/refs/heads/{$ref}"));
}
return $rev;
}
function extrapolate_git_url(){
global $tgdir;
$config = file($tgdir . '/.git/config', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach($config as $line)
if(strpos($line, 'url = ') !== false)
return trim(explode('=', $line)[1]);
}
function download_file($path){
header('Content-type: application/zip');
header('Content-Disposition: attachment; filename=' . basename($path));
header('Content-length: ' . filesize($path));
header('Pragma: no-cache');
header('Expires: 0');
readfile($path);
}
function recurse_copy($src,$dst) {
$dir = opendir($src);
@mkdir($dst);
while(false !== ( $file = readdir($dir)) ) {
if (( $file != '.' ) && ( $file != '..' )) {
if ( is_dir($src . '/' . $file) ) {
recurse_copy($src . '/' . $file,$dst . '/' . $file);
}
else {
copy($src . '/' . $file,$dst . '/' . $file);
}
}
}
closedir($dir);
}
function rrmdir($dir) {
if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if (is_dir($dir."/".$object))
rrmdir($dir."/".$object);
else
unlink($dir."/".$object);
}
}
rmdir($dir);
}
}
function update_git(){
global $tgdir;
shell_exec('cd ' . $tgdir . ' && git pull');
}
$full_path_to_gulp = str_replace('/', '\\', $full_path_to_gulp);
$parent_dir = str_replace('\\', '/', realpath(dirname(__FILE__)));
$tgdir = $parent_dir . '/' . $repo_dir;
$revision = getGitRevision();
$git_base = extrapolate_git_url();
if($git_base)
$commit_url = $git_base . '/commit/' . $revision;
else
$error = 'Unable to determine github URL!';
if($_SERVER['REQUEST_METHOD'] === 'POST'){
$updated_git = isset($_POST['pull']);
if($updated_git){
update_git();
$revision = getGitRevision();
}
$good_files = array();
$finfo = new finfo(FILEINFO_MIME_TYPE);
foreach($_FILES as $F){
$name = $F['name'];
if(isset($F['error']) && !is_array($F['error']) && $F['error'] == UPLOAD_ERR_OK && $F['size'] > 0 && strpos($name, '\\') == false && strpos($name, '/') == false){
$ext = pathinfo($name, PATHINFO_EXTENSION);
$mime = $finfo->file($F['tmp_name']);
if($ext == 'ract' && $mime == 'text/plain')
$good_files[] = $F;
}
}
$the_count = count($good_files);
if($the_count > 0 && $the_count < $max_number_of_uploads){
$tgtgui_path = $tgdir . $path_to_tgui_from_repo;
$requests_dir = $parent_dir . '/requests';
if(!is_dir($requests_dir))
mkdir($requests_dir);
$target_path = str_replace('\\', '/', tempnam($requests_dir, 'tgui'));
unlink($target_path);
recurse_copy($tgtgui_path, $target_path);
$parent_node = $parent_dir . '/node_modules';
$target_node = $target_path . '/node_modules';
exec('mklink /j "' . str_replace('/', '\\', $target_node) . '" "' . str_replace('/', '\\', $parent_node) . '"');
//now copy the uploads to the thing
$target_interfaces = $target_path . '/src/interfaces/';
foreach($good_files as $F){
$target_name = $target_interfaces . $F['name'];
if(file_exists($target_name))
unlink($target_name); //remove the file
move_uploaded_file($F['tmp_name'], $target_name);
}
//compile
$command = '"' . $full_path_to_gulp . '" --cwd "' . str_replace('/', '\\', $target_path) . '" --min 2>&1';
$output = shell_exec($command);
$zip = new ZipArchive();
$zippath = $target_path . '/TGUI.zip';
if($zip->open($zippath, ZipArchive::CREATE) == TRUE){
$zip->addFile($target_path . '/assets/tgui.css', 'tgui.css');
$zip->addFile($target_path . '/assets/tgui.js', 'tgui.js');
$zip->addFromString('gulp_output.txt', $output);
$zip->close();
download_file($zippath);
}
else
$error = 'Unable to create output zipfile!';
exec('rmdir "' . str_replace('/', '\\', $target_node) . '"'); //improtant
rrmdir($target_path);
}
else if(!$updated_git)
throw new RuntimeException('No valid files uploaded!');
}
}
catch(Exception $e){
$error = $e->getMessage();
}
?>
<!DOCTYPE html>
<html>
<head>
<title>TGUI .ract Compiler</title>
</head>
<body>
<?php if(isset($error)) echo '<h5><font color="red">An error occured:</font> ' . $error . '</h5><br><br>'; ?>
<h1>Upload up to <?php echo $max_number_of_uploads; ?> .ract files<h2>
<h4>Based off revision: <?php echo isset($commit_url) ? '<a href="' . $commit_url . '">' . $revision . '</a>' : $revision; ?>
<form id='file_form' action = '' method = 'post' enctype='multipart/form-data'>
<input type='checkbox' name='pull'>Update to latest revision (don't use this unless you have to)<br>
<div id='files_field'>
<input name='f1' type='file'><br>
</div>
<button id='add_more'>Add Another File</button>
<button type='submit'>Submit</button>
</form>
</body>
<script type='text/javascript' src='https://code.jquery.com/jquery-3.2.1.min.js'></script>
<script type='text/javascript'>
$(function(){
var next_id = 2;
$("#add_more").click(function(e){
$("#files_field").append("<input name='f" + next_id + "' type='file'><br>");
++next_id;
if(next_id > <?php echo $max_number_of_uploads; ?>)
$("#add_more").remove();
});
});
</script>
</html>

View File

@@ -11,7 +11,7 @@
/**CREDITS:
* GitHub webhook handler template.
*
*
* @see https://developer.github.com/webhooks/
* @author Miloslav Hula (https://github.com/milo)
*/
@@ -126,24 +126,24 @@ switch (strtolower($_SERVER['HTTP_X_GITHUB_EVENT'])) {
function apisend($url, $method = 'GET', $content = null, $authorization = null) {
if (is_array($content))
$content = json_encode($content);
$headers = array();
$headers[] = 'Content-type: application/json';
if ($authorization)
$headers[] = 'Authorization: ' . $authorization;
$scontext = array('http' => array(
'method' => $method,
'header' => implode("\r\n", $headers),
'ignore_errors' => true,
'user_agent' => 'tgstation13.org-Github-Automation-Tools'
));
if ($content)
$scontext['http']['content'] = $content;
return file_get_contents($url, false, stream_context_create($scontext));
}
function github_apisend($url, $method = 'GET', $content = NULL) {
@@ -178,7 +178,7 @@ function validate_user($payload) {
$res = github_apisend('https://api.github.com/search/issues?q='.$querystring);
$res = json_decode($res, TRUE);
return $res['total_count'] >= (int)$validation_count;
}
function get_labels($payload){
@@ -227,7 +227,7 @@ function tag_pr($payload, $opened) {
sleep(10);
$payload['pull_request'] = json_decode(github_apisend($url), TRUE);
}
$tags = array();
$title = $payload['pull_request']['title'];
if($opened) { //you only have one shot on these ones so as to not annoy maintainers
@@ -235,7 +235,7 @@ function tag_pr($payload, $opened) {
if(strpos(strtolower($title), 'refactor') !== FALSE)
$tags[] = 'Refactor';
if(strpos(strtolower($title), 'revert') !== FALSE)
$tags[] = 'Revert';
if(strpos(strtolower($title), 'removes') !== FALSE)
@@ -302,7 +302,7 @@ function check_ready_for_review($payload, $labels = null, $remove = array()){
if($L == $r4rlabel)
$has_label_already = true;
}
if($has_label_already && $should_not_have_label){
$remove[] = $r4rlabel;
return $returned;
@@ -340,7 +340,7 @@ function check_ready_for_review($payload, $labels = null, $remove = array()){
//make sure they are part of an offending review
if(!in_array($C['pull_request_review_id'], $reviews_ids_with_changes_requested))
continue;
//review comments which are outdated have a null position
if($C['position'] !== null){
if($has_label_already)
@@ -363,10 +363,10 @@ function check_dismiss_changelog_review($payload){
if(!$require_changelog)
return;
if(!$no_changelog)
checkchangelog($payload, false);
$review_message = 'Your changelog for this PR is either malformed or non-existent. Please create one to document your changes.';
$reviews = get_reviews($payload);
@@ -427,8 +427,8 @@ function handle_pr($payload) {
break;
default:
return;
}
}
$pr_flags = 0;
if (strpos(strtolower($payload['pull_request']['title']), '[s]') !== false) {
$pr_flags |= F_SECRET_PR;
@@ -438,7 +438,7 @@ function handle_pr($payload) {
}
discord_announce($action, $payload, $pr_flags);
game_announce($action, $payload, $pr_flags);
}
function filter_announce_targets($targets, $owner, $repo, $action, $pr_flags) {
@@ -447,7 +447,7 @@ function filter_announce_targets($targets, $owner, $repo, $action, $pr_flags) {
unset($targets[$i]);
continue;
}
if (isset($target['announce_secret']) && $target['announce_secret']) {
if (!($pr_flags & F_SECRET_PR) && $target['announce_secret'] === 'only') {
unset($targets[$i]);
@@ -457,7 +457,7 @@ function filter_announce_targets($targets, $owner, $repo, $action, $pr_flags) {
unset($targets[$i]);
continue;
}
if (isset($target['announce_unvalidated']) && $target['announce_unvalidated']) {
if (!($pr_flags & F_UNVALIDATED_USER) && $target['announce_unvalidated'] === 'only') {
unset($targets[$i]);
@@ -467,7 +467,7 @@ function filter_announce_targets($targets, $owner, $repo, $action, $pr_flags) {
unset($targets[$i]);
continue;
}
$wildcard = false;
if (isset($target['include_repos'])) {
foreach ($target['include_repos'] as $match_string) {
@@ -490,7 +490,7 @@ function filter_announce_targets($targets, $owner, $repo, $action, $pr_flags) {
continue;
}
}
if (isset($target['exclude_repos']))
foreach ($target['exclude_repos'] as $match_string) {
$owner_repo_pair = explode('/', strtolower($match_string));
@@ -517,13 +517,13 @@ function filter_announce_targets($targets, $owner, $repo, $action, $pr_flags) {
function game_announce($action, $payload, $pr_flags) {
global $servers;
$msg = '['.$payload['pull_request']['base']['repo']['full_name'].'] Pull Request '.$action.' by '.htmlSpecialChars($payload['sender']['login']).': <a href="'.$payload['pull_request']['html_url'].'">'.htmlSpecialChars('#'.$payload['pull_request']['number'].' '.$payload['pull_request']['user']['login'].' - '.$payload['pull_request']['title']).'</a>';
$game_servers = filter_announce_targets($servers, $payload['pull_request']['base']['repo']['owner']['login'], $payload['pull_request']['base']['repo']['name'], $action, $pr_flags);
$msg = '?announce='.urlencode($msg).'&payload='.urlencode(json_encode($payload));
foreach ($game_servers as $serverid => $server) {
$server_message = $msg;
if (isset($server['comskey']))
@@ -554,9 +554,9 @@ function discord_announce($action, $payload, $pr_flags) {
'username' => 'GitHub',
'avatar_url' => $payload['pull_request']['base']['user']['avatar_url'],
);
$content = 'Pull Request #'.$payload['pull_request']['number'].' *'.$action.'* by '.discord_sanitize($payload['sender']['login'])."\n".discord_sanitize($payload['pull_request']['user']['login']).' - __**'.discord_sanitize($payload['pull_request']['title']).'**__'."\n".'<'.$payload['pull_request']['html_url'].'>';
$embeds = array(
array(
'title' => '__**'.discord_sanitize($payload['pull_request']['title'], S_MARKDOWN).'**__',
@@ -586,22 +586,22 @@ function discord_announce($action, $payload, $pr_flags) {
}
discord_webhook_send($discordWebHook['url'], $sending_data);
}
}
function discord_sanitize($text, $flags = S_MENTIONS|S_LINK_EMBED|S_MARKDOWN) {
function discord_sanitize($text, $flags = S_MENTIONS|S_LINK_EMBED|S_MARKDOWN) {
if ($flags & S_MARKDOWN)
$text = str_ireplace(array('\\', '*', '_', '~', '`', '|'), (array('\\\\', '\\*', '\\_', '\\~', '\\`', '\\|')), $text);
if ($flags & S_HTML_COMMENTS)
$text = preg_replace('/<!--(.*)-->/Uis', '', $text);
if ($flags & S_MENTIONS)
$text = str_ireplace(array('@everyone', '@here', '<@'), array('`@everyone`', '`@here`', '@<'), $text);
if ($flags & S_LINK_EMBED)
$text = preg_replace("/((https?|ftp|byond)\:\/\/)([a-z0-9-.]*)\.([a-z]{2,3})(\:[0-9]{2,5})?(\/(?:[a-z0-9+\$_-]\.?)+)*\/?(\?[a-z+&\$_.-][a-z0-9;:@&%=+\/\$_.-]*)?(#[a-z_.-][a-z0-9+\$_.-]*)?/mi", '<$0>', $text);
return $text;
}
@@ -673,7 +673,7 @@ function get_pr_code_friendliness($payload, $oldbalance = null){
$maxNegative = min($friendliness, $maxNegative);
}
}
$affecting = abs($maxNegative) >= $maxPositive ? $maxNegative : $maxPositive;
return $affecting;
}
@@ -805,7 +805,7 @@ function checkchangelog($payload, $compile = true) {
}
if (!$incltag)
continue;
$firstword = explode(' ', $line)[0];
$pos = strpos($line, " ");
$item = '';
@@ -815,7 +815,7 @@ function checkchangelog($payload, $compile = true) {
} else {
$firstword = $line;
}
if (!strlen($firstword)) {
$currentchangelogblock[count($currentchangelogblock)-1]['body'] .= "\n";
continue;
@@ -933,7 +933,7 @@ function checkchangelog($payload, $compile = true) {
case 'server':
if($item != 'something server ops should know')
$currentchangelogblock[] = array('type' => 'server', 'body' => $item);
break;
break;
default:
//we add it to the last changelog entry as a separate line
if (count($currentchangelogblock) > 0)
@@ -970,10 +970,10 @@ function checkchangelog($payload, $compile = true) {
function game_server_send($addr, $port, $str) {
// All queries must begin with a question mark (ie "?players")
if($str{0} != '?') $str = ('?' . $str);
/* --- Prepare a packet to send to the server (based on a reverse-engineered packet structure) --- */
$query = "\x00\x83" . pack('n', strlen($str) + 6) . "\x00\x00\x00\x00\x00" . $str . "\x00";
/* --- Create a socket and connect it to the server --- */
$server = socket_create(AF_INET,SOCK_STREAM,SOL_TCP) or exit("ERROR");
socket_set_option($server, SOL_SOCKET, SO_SNDTIMEO, array('sec' => 2, 'usec' => 0)); //sets connect and send timeout to 2 seconds
@@ -981,7 +981,7 @@ function game_server_send($addr, $port, $str) {
return "ERROR: Connection failed";
}
/* --- Send bytes to the server. Loop until all bytes have been sent --- */
$bytestosend = strlen($query);
$bytessent = 0;
@@ -989,22 +989,22 @@ function game_server_send($addr, $port, $str) {
//echo $bytessent.'<br>';
$result = socket_write($server,substr($query,$bytessent),$bytestosend-$bytessent);
//echo 'Sent '.$result.' bytes<br>';
if ($result===FALSE)
if ($result===FALSE)
return "ERROR: " . socket_strerror(socket_last_error());
$bytessent += $result;
}
/* --- Idle for a while until recieved bytes from game server --- */
$result = socket_read($server, 10000, PHP_BINARY_READ);
socket_close($server); // we don't need this anymore
if($result != "") {
if($result{0} == "\x00" || $result{1} == "\x83") { // make sure it's the right packet format
// Actually begin reading the output:
$sizebytes = unpack('n', $result{2} . $result{3}); // array size of the type identifier and content
$size = $sizebytes[1] - 1; // size of the string/floating-point (minus the size of the identifier byte)
if($result{4} == "\x2a") { // 4-byte big-endian floating-point
$unpackint = unpack('f', $result{5} . $result{6} . $result{7} . $result{8}); // 4 possible bytes: add them up together, unpack them as a floating-point
return $unpackint[1];
@@ -1012,7 +1012,7 @@ function game_server_send($addr, $port, $str) {
else if($result{4} == "\x06") { // ASCII string
$unpackstr = ""; // result string
$index = 5; // string index
while($size > 0) { // loop through the entire ASCII string
$size--;
$unpackstr .= $result{$index}; // add the string position to return string