Sandbot
Some useful links / notes related to the sandbot setup.
Running something as www-data
sudo su www-data -s /bin/sh
Setting up /var/www/html with githook:
sudo chown www-data /var/www/html git remote set-url origin https://git.xpub.nl/XPUB/sandbot.git
Created file /usr/lib/cgi-bin/pull_XXXXXXXXXX.cgi
#!/bin/bash
echo "Content-type:text/html"
echo
cd /var/www/html
git fetch --all
git reset --hard origin/master
Testing the webhook...
sudo su www-data -s /bin/sh cd /usr/lib/cgi-bin ./pull_XXXXXX.cgi
Test from browser:
https://hub.xpub.nl/sandbot/cgi-bin/pull_XXXXXX.cgi
Directory listing
<!DOCTYPE html>
<html>
<?php
$cwd = getcwd();
$path=explode('/', $cwd);
$depth=count($path);
$files = scandir($cwd);
?>
<head>
<meta charset="utf-8">
<title><?=end($path)?></title>
<link rel="stylesheet" href="/sandbot/PrototypingTimes/tic80/gamelisting.css"
</head>
<body class="depth<?=$depth?>">
<h1><?=end($path)?></h1>
<ul id="files">
<li><a href='../'>..</a></li>
<?php
foreach ($files as $file):
if (preg_match('/^\./', $file) || $file == 'index.php'):
continue;
elseif (preg_match('/\.tic$/', $file)):
echo "<li><a class='file tic' href='/sandbot/PrototypingTimes/tic80/tic80.php?cart=/sandbot".$_SERVER[REQUEST_URI].urlencode($file)."'>$file</a></li>\n";
elseif (is_dir($cwd.'/'.$file)):
echo "<li><a class='folder' href='$file/'>$file</a></li>\n";
else:
echo "<li><a class='file' href='$file'>$file</a></li>\n";
endif;
endforeach;
?>
</ul>
</html>
nginx
CORS
https://enable-cors.org/server_nginx.html
# # Wide-open CORS config for nginx # location / { if ($request_method = 'OPTIONS') { add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; # # Custom headers and headers various browsers *should* be OK with but aren't # add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'; # # Tell client that this pre-flight info is valid for 20 days # add_header 'Access-Control-Max-Age' 1728000; add_header 'Content-Type' 'text/plain; charset=utf-8'; add_header 'Content-Length' 0; return 204; } if ($request_method = 'POST') { add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'; add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range'; } if ($request_method = 'GET') { add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'; add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range'; } }