This commit is contained in:
parent
2c4b0cf6c4
commit
67e4b234d3
6
.gitmodules
vendored
Normal file
6
.gitmodules
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[submodule "html/staticsimponic"]
|
||||||
|
path = html/staticsimponic
|
||||||
|
url = https://git.simponic.xyz/simponic/static.simponic.xyz
|
||||||
|
[submodule "html/the-abstraction-engine"]
|
||||||
|
path = html/the-abstraction-engine
|
||||||
|
url = https://git.simponic.xyz/simponic/the-abstraction-engine
|
@ -2,8 +2,9 @@
|
|||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
mkdir -p dist
|
git submodule update --init --recursive
|
||||||
|
|
||||||
|
mkdir -p dist
|
||||||
pwd=$PWD
|
pwd=$PWD
|
||||||
|
|
||||||
for source in "html" "gemini" "gopher"; do
|
for source in "html" "gemini" "gopher"; do
|
||||||
|
@ -1,5 +1,23 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
mkdir -p ../dist/public_html
|
||||||
|
|
||||||
cp -r ./public ../dist/public_html
|
cp -r ./public ../dist/public_html
|
||||||
|
mv staticsimponic/turing-machine ../dist/public_html
|
||||||
|
mv staticsimponic/euler-golf ../dist/public_html
|
||||||
|
mv staticsimponic/godel-explorer ../dist/public_html
|
||||||
|
|
||||||
|
cd the-abstraction-engine/
|
||||||
|
npm install
|
||||||
|
npm run build
|
||||||
|
cd ..
|
||||||
|
cp -r the-abstraction-engine/dist ../dist/public_html/the-abstraction-engine
|
||||||
|
|
||||||
|
mkdir -p ../dist/fruitvote
|
||||||
|
cd fruitvote
|
||||||
|
go build -o ../../dist/fruitvote/fruitvote
|
||||||
|
cd ..
|
||||||
|
cp start.sh ../dist/fruitvote/start.sh
|
||||||
|
|
||||||
echo "finished building HTML"
|
echo "finished building HTML"
|
||||||
|
|
||||||
|
1
html/fruitvote/.gitignore
vendored
Normal file
1
html/fruitvote/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
main
|
57
html/fruitvote/main.go
Normal file
57
html/fruitvote/main.go
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func indexHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
w.Write([]byte("Hello, this is a Unix socket HTTP server in Go!"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
socketPath, users := getArgs()
|
||||||
|
os.Remove(socketPath)
|
||||||
|
|
||||||
|
listener, err := net.Listen("unix", socketPath)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
os.Chmod(socketPath, 0700)
|
||||||
|
defer listener.Close()
|
||||||
|
|
||||||
|
for _, user := range strings.Split(users, ",") {
|
||||||
|
setACL(socketPath, user)
|
||||||
|
}
|
||||||
|
|
||||||
|
mux := http.NewServeMux()
|
||||||
|
mux.HandleFunc("/", indexHandler)
|
||||||
|
|
||||||
|
http.Serve(listener, mux)
|
||||||
|
}
|
||||||
|
|
||||||
|
func setACL(socketPath, user string) {
|
||||||
|
cmd := exec.Command("setfacl", "-m", "u:"+user+":rwx", socketPath)
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
|
panic("failed to set ACL: " + err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getArgs() (string, string) {
|
||||||
|
socketPath := flag.String("socket-path", "/tmp/go-server.sock", "Path to the Unix socket")
|
||||||
|
users := flag.String("users", "", "Comma-separated list of users for ACL")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
if *users == "" {
|
||||||
|
fmt.Println("You must specify at least one user with --users")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return *socketPath, *users
|
||||||
|
}
|
77
html/public/css/style.css
Normal file
77
html/public/css/style.css
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
/* Basic Reset */
|
||||||
|
*,
|
||||||
|
*::before,
|
||||||
|
*::after {
|
||||||
|
box-sizing: border-box;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
background-color: #2a2a2a; /* Dark background */
|
||||||
|
color: #f4c2c2; /* Soft pink text, typical of a girly 90s vibe */
|
||||||
|
font-family: "Comic Sans MS", "Chalkboard SE", sans-serif; /* Retro, playful font */
|
||||||
|
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: #ff47da; /* Bright pink for links */
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
a:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
button,
|
||||||
|
input[type="submit"],
|
||||||
|
input[type="button"] {
|
||||||
|
background-color: #ff69b4; /* Bright pink for buttons */
|
||||||
|
border: none;
|
||||||
|
color: white;
|
||||||
|
padding: 10px 20px;
|
||||||
|
text-transform: uppercase;
|
||||||
|
font-family: "Comic Sans MS", "Chalkboard SE", sans-serif;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background-color 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
button:hover,
|
||||||
|
input[type="submit"]:hover,
|
||||||
|
input[type="button"]:hover {
|
||||||
|
background-color: #ff1493; /* Darker pink on hover */
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type="text"],
|
||||||
|
input[type="password"],
|
||||||
|
textarea {
|
||||||
|
background-color: #333; /* Darker elements for inputs */
|
||||||
|
border: 1px solid #f4c2c2; /* Soft pink border */
|
||||||
|
color: #f4c2c2; /* Soft pink text */
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Example of styling a specific component differently */
|
||||||
|
.special-button {
|
||||||
|
background-color: #ff47da; /* A different shade of pink */
|
||||||
|
border-radius: 20px; /* Rounded edges for a more playful look */
|
||||||
|
}
|
||||||
|
|
||||||
|
h1,
|
||||||
|
h2,
|
||||||
|
h3,
|
||||||
|
h4,
|
||||||
|
h5,
|
||||||
|
h6 {
|
||||||
|
color: #ff69b4;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
li {
|
||||||
|
margin-left: 20px;
|
||||||
|
}
|
88
html/public/fruitvote/GoPage.php
Normal file
88
html/public/fruitvote/GoPage.php
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
<?php
|
||||||
|
class GoPage {
|
||||||
|
private $page;
|
||||||
|
private $socket;
|
||||||
|
private $template;
|
||||||
|
|
||||||
|
public function __construct($page, $socket = "/home/lizzy/fruitvote/http.sock", $start_cmd="/home/simponic/fruitvote/start.sh", $template="../template.html") {
|
||||||
|
$this->page = $page;
|
||||||
|
$this->socket = $socket;
|
||||||
|
$this->template = $template;
|
||||||
|
|
||||||
|
// test if socket exists
|
||||||
|
if (!file_exists($socket)) {
|
||||||
|
// start the server
|
||||||
|
exec($start_cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
for ($i = 0; $i < 10; $i++) {
|
||||||
|
if (file_exists($socket)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
usleep(100_000); // wait 100ms
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!file_exists($socket)) {
|
||||||
|
throw new Exception("Could not start server");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public function go() {
|
||||||
|
$ch = curl_init();
|
||||||
|
$url = "http://localhost".$this->page;
|
||||||
|
|
||||||
|
curl_setopt($ch, CURLOPT_URL, $url);
|
||||||
|
curl_setopt($ch, CURLOPT_UNIX_SOCKET_PATH, $this->socket);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
|
|
||||||
|
// forward headers
|
||||||
|
$headers = array();
|
||||||
|
foreach ($_SERVER as $key => $value) {
|
||||||
|
if (substr($key, 0, 5) == "HTTP_") {
|
||||||
|
$key = str_replace(" ", "-", ucwords(strtolower(str_replace("_", " ", substr($key, 5)))));
|
||||||
|
$headers[] = "$key: $value";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||||
|
|
||||||
|
// forward params depending on http method
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] == "POST" || $_SERVER['REQUEST_METHOD'] == "PUT" || $_SERVER['REQUEST_METHOD'] == "DELETE") {
|
||||||
|
curl_setopt($ch, CURLOPT_POST, 1);
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents('php://input'));
|
||||||
|
} else {
|
||||||
|
$url .= "?".$_SERVER['QUERY_STRING'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// forward cookies
|
||||||
|
$cookie = array();
|
||||||
|
foreach ($_COOKIE as $key => $value) {
|
||||||
|
$cookie[] = "$key=$value";
|
||||||
|
}
|
||||||
|
|
||||||
|
$output = curl_exec($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
// forward headers back to client
|
||||||
|
$headers = explode("\n", $output);
|
||||||
|
foreach ($headers as $header) {
|
||||||
|
if (strpos($header, "HTTP/") === false) {
|
||||||
|
header($header);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// forward cookies back to client
|
||||||
|
$cookie = explode("\n", $output);
|
||||||
|
foreach ($cookie as $cookie) {
|
||||||
|
if (strpos($cookie, "Set-Cookie:") !== false) {
|
||||||
|
header($cookie);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function render() {
|
||||||
|
$response = $this->go();
|
||||||
|
$template = file_get_contents($this->template);
|
||||||
|
return str_replace("{{content}}", $response, $template);
|
||||||
|
}
|
||||||
|
}
|
7
html/public/fruitvote/index.php
Normal file
7
html/public/fruitvote/index.php
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once("GoPage.php");
|
||||||
|
|
||||||
|
$page = new GoPage("/");
|
||||||
|
echo $page->render();
|
||||||
|
?>
|
BIN
html/public/img/penguin.gif
Normal file
BIN
html/public/img/penguin.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 52 KiB |
@ -1,19 +1,49 @@
|
|||||||
<?php
|
<?php
|
||||||
// todo: startup go program if not started. use low cpu priority.
|
$content = '
|
||||||
|
<p>you are at my <a href="https://tilde.club">tilde.club</a> page right now! hi!</p>
|
||||||
|
|
||||||
$ch = curl_init();
|
|
||||||
|
|
||||||
$url = "http:/localhost";
|
<img src="/img/penguin.gif" alt="a penguin" style="width: 200px; height: 200px;"/>
|
||||||
$unix = "/home/simponic/http.sock";
|
<p><em>this is a penguin</em></p>
|
||||||
|
|
||||||
if (defined('CURLOPT_UNIX_SOCKET_PATH')) {
|
<p>here you can:</p>
|
||||||
curl_setopt($ch, CURLOPT_UNIX_SOCKET_PATH, $unix);
|
|
||||||
curl_setopt($ch, CURLOPT_URL, $url);
|
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
||||||
|
|
||||||
$response = curl_exec($ch);
|
<ul>
|
||||||
echo $response;
|
<li>vote on your favorite <a href="/fruit">fruit</a></li>
|
||||||
}
|
<li>play <a href="/the-abstraction-engine">the abstraction engine</a> (WIP)</li>
|
||||||
|
<li>play <a href="/euler-golf">euler golf 2</a></li>
|
||||||
|
<li>program a <a href="/turing-machine">turing machine</a></li>
|
||||||
|
<li>mess with <a href="/godel-explorer">godel numbers</a></li>
|
||||||
|
<li>more to come?</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
curl_close($ch);
|
<br />
|
||||||
|
<br />
|
||||||
|
|
||||||
|
<p>
|
||||||
|
here are some stuffs i like:
|
||||||
|
<ul>
|
||||||
|
<li>penguins, dogs, birds</li>
|
||||||
|
<li>programming (((with parentheses)))</li>
|
||||||
|
<li>compilers, languages, distributed systems</li>
|
||||||
|
<li>emacs</li>
|
||||||
|
<li>math</li>
|
||||||
|
<li>boys (and girls) 🏳️🌈</li>
|
||||||
|
<li>gruvbox & catpuccin</li>
|
||||||
|
</ul>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
here are some stuffs i don\'t like:
|
||||||
|
<ul>
|
||||||
|
<li>bugs (hahahaha)</li>
|
||||||
|
<li>capitalism, expensive healthcare, yadayada</li>
|
||||||
|
<li>mmmm i can\'t think of more</li>
|
||||||
|
</ul>
|
||||||
|
</p>
|
||||||
|
';
|
||||||
|
|
||||||
|
$template = file_get_contents('template.html');
|
||||||
|
|
||||||
|
echo str_replace("{{content}}", $content, $template);
|
||||||
?>
|
?>
|
||||||
|
38
html/public/template.html
Normal file
38
html/public/template.html
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>~simponic</title>
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="/css/style.css">
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div>
|
||||||
|
<h1><a href="/">~simponic</a></h1>
|
||||||
|
<ul>
|
||||||
|
<li style="display:inline; margin-right: 20px; margin-left: 0px;"><a href="/">home</a></li>
|
||||||
|
<li style="display:inline; margin-right: 20px; margin-left: 0px;"><a href="/fruitvote">fruitvote</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<br />
|
||||||
|
|
||||||
|
{{content}}
|
||||||
|
|
||||||
|
<br />
|
||||||
|
<hr />
|
||||||
|
<br />
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li style="display:inline; margin-right: 20px; margin-left: 0px;"><a href="https://git.simponic.xyz/simponic">gitea</a></li>
|
||||||
|
<li style="display:inline; margin-right: 20px; margin-left: 0px;"><a href="https://git.simponic.xyz/simponic/tilde.club">source</a></li>
|
||||||
|
<li style="display:inline; margin-right: 20px; margin-left: 0px;"><a href="mailto:elizabeth.hunt@simponic.xyz">email</a></li>
|
||||||
|
<li style="display:inline; margin-right: 20px; margin-left: 0px;"><a href="https://www.linkedin.com/in/simponic/">linkedin</a></li>
|
||||||
|
<li style="display:inline; margin-right: 20px; margin-left: 0px;"><a href="http://tilde.club/~harper/link.html?action=random">random tilde.club page</a></li>
|
||||||
|
</ul>
|
||||||
|
<br />
|
||||||
|
<a href="https://tilde.club"><img src="http://tilde.club/~harper/webring.png" border="0" usemap="#notepad.map"></a>
|
||||||
|
</body>
|
||||||
|
</html>
|
7
html/start.sh
Executable file
7
html/start.sh
Executable file
@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
nice -n 19 /home/simponic/fruitvote/fruitvote \
|
||||||
|
--users simponic,nginx \
|
||||||
|
--socket-path /home/simponic/fruitvote/http.sock \
|
||||||
|
--database /home/simponic/fruitvote/db.sqlite \
|
||||||
|
&
|
1
html/staticsimponic
Submodule
1
html/staticsimponic
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit d3a0fd124549f0f66d80c107ed4a8e73ca2e67e9
|
1
html/the-abstraction-engine
Submodule
1
html/the-abstraction-engine
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit ce403459fa82025bd969d1938ed4034a10c2e751
|
Loading…
Reference in New Issue
Block a user