major revamp

This commit is contained in:
tavo-wasd 2023-11-18 00:35:38 -06:00
parent a97e36cd52
commit babf9c9458

View file

@ -16,49 +16,63 @@
along with Foobar. If not, see <https://www.gnu.org/licenses/>. along with Foobar. If not, see <https://www.gnu.org/licenses/>.
--> -->
<html> <html>
<?php <?php
# Generate an uid for each new document exec("mkdir -p gen && rm -rf gen/*");
$uid = exec("head /dev/urandom | tr -dc 'a-zA-Z0-9' | head -c 10"); $uid = bin2hex(random_bytes(5));
# groff settings
$groff = "/usr/bin/groff";
$comp = "$groff -ketpG -mspdf -Tpdf tmp/$uid.ms > tmp/$uid.pdf";
# In case you want to use an external
# script to compile with groff:
#$comp = "sh groff-compiler.sh";
?>
# Configuration
$groff = "/usr/bin/groff";
$cmd = "$groff -ketpG -mspdf -Tpdf gen/$uid.ms > gen/$uid.pdf";
# In case you want to use an external script
#$cmd = "sh groff-compiler.sh";
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['codebox'])) {
$code = $_POST['codebox'];
file_put_contents("gen/$uid.ms", $code);
exec("$cmd");
}
?>
<head> <head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Minimal web front-end to the GNU roff typesetting program.">
<title>Groff Web</title> <title>Groff Web</title>
<link rel="shortcut icon" href="#">
<style> <style>
* { body,pre,.button {
background-color: #121212; background-color: #121212;
color: #928374;
font-family: monospace; font-family: monospace;
text-align: center; text-align: center;
margin: 4px auto; border-radius: 10px;
color: #928374; border-width: 1px;
padding: 10px 30px;
margin: 10px auto;
} }
textarea,pre,.button {
h1,h2,h3,h4,h5 { border: 1px solid #3a3e41;
}
.button:hover {
border-color: #928374;
color: #fe8019;
}
strong,a {
background-color: #121212;
color: #fe8019; color: #fe8019;
} }
textarea,object,.columns { textarea,object,.columns {
border-radius: 10px; border-radius: 10px;
border-width: 1px; border-width: 1px;
max-width: 1300px; max-width: 1300px;
margin: 10px auto;
width: 100%; width: 100%;
columns: 2; columns: 2;
} }
@media only screen and (max-width: 800px) { @media only screen and (max-width: 800px) {
.columns { .columns {
columns: 1; columns: 1;
width: 90%; width: 90%;
} }
} }
/* codebox */ /* codebox */
textarea { textarea {
background-color: #282828; background-color: #282828;
@ -66,56 +80,71 @@
color: #83a598; color: #83a598;
height: 734px; height: 734px;
} }
/* pdf */ /* pdf */
object { object {
height: 800px; height: 800px;
} }
pre {
.button { text-align: left;
border-radius: 10px; white-space: pre-wrap;
border-width: 1px; font-family: monospace;
padding: 5px 30px; }
margin: 10px; textarea:focus {
outline: none !important;
border:1px solid #928374;
} }
</style> </style>
</head> </head>
<?php
exec("mkdir -p tmp && rm -rf tmp/*");
if($_POST['codebox']){
$file_open = fopen("tmp/$uid.ms","w+");
fwrite($file_open, $_POST['codebox']);
fclose($file_open);
}
exec("$comp");
?>
<body> <body>
<h1>Groff Web</h1> <header><p>
<p><?php echo exec("$groff -v | head -n 1")?></p> <strong>Groff Web</strong> | <?php echo exec("$groff -v | head -n 1")?>
</p> </header>
<div class=columns> <div class="columns">
<div style="width: 100%"><form method="POST"> <form method="POST">
<div><input type=submit value="Compile PDF" class=button></div> <div><input type="submit" value="Compile" class="button"></div>
<textarea name="codebox"><?= htmlspecialchars(file_get_contents("gen/$uid.ms")) ?></textarea>
<textarea id="codebox" name="codebox"><?php </form>
$datalines = file ("tmp/$uid.ms"); <object type="application/pdf" data="/gen/<?php echo $uid?>.pdf?#&navpanes=0">
foreach ($datalines as $zz) { <div><button class="button"><a href="/gen/<?php echo $uid?>.pdf">Download PDF</a></div>
echo $zz; } <div>
?></textarea> <pre><code>
</form></div> .\" Template
.\" .ds FAM T \" H=Helvetica C=Courier
<object type="application/pdf" data="/tmp/<?php echo $uid?>.pdf?#&navpanes=0"> .\" .nr PS 10p \" Point size
<p>PDF cannot be displayed.</p> .\" .nr VS 12p \" Line spacing
.\" .so report.tmac \" Cover page
.\" .so utils.tmac \" General utils
.\" .so toc.tmac \" Relocate toc
.\" .so md.tmac \" Md-like sections
.\" .so math.tmac \" Math utils
.\" .so es.tmac \" Spanish
.
.TL
title
.AU
author
.AI
institution
.
.AB
abstract
.AE
.
.NH
.XN "numbered heading"
.
.PP
indented \f[CW]paragraph\f[] \m[blue]with\m[] \f[B]some\f[] \f[I]formatting\f[]
.
.\" .TC
</code></pre>
</div>
</object> </object>
</div> </div>
<footer><p> <footer><p>
Copyright (C) 2023 Gustavo Calvo | Copyright (C) 2023 Gustavo Calvo |
<a href="https://gitlab.com/tavo-wasd/groff-web" target="_blank" rel="noopener noreferrer">Source</a> | <a href="https://gitlab.com/tavo-wasd/groff-web" target="_blank" rel="noopener noreferrer">Source</a> |
<a href="https://www.gnu.org/licenses/gpl-3.0.txt" target="_blank" rel="noopener noreferrer">GPL-3.0</a> <a href="https://www.gnu.org/licenses/gpl-3.0.txt" target="_blank" rel="noopener noreferrer">GPL-3.0</a>
</p></footer> </p></footer>
</body> </body>
</html> </html>