added initial files

This commit is contained in:
jan6 2019-05-26 18:47:18 +03:00
parent 1352021d29
commit 76e67bd32d
13 changed files with 379 additions and 3 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.o
*.core

16
Makefile Normal file
View File

@ -0,0 +1,16 @@
CFLAGS=-std=c99 -pedantic -Wall
.PHONY: all clean
all: in out
clean:
rm -f in out *.o *.core
in: in.o
gcc -o $@ in.o
out: out.o
gcc -o $@ out.o
.SUFFIXES: .c .o
.c.o:
gcc $(CFLAGS) -c -o $@ $<

View File

@ -1,4 +1,14 @@
# webii
wii
===
web frontend for ii [Irc It](https://tools.suckless.org/ii/)
rework of https://github.com/younix/wii
Simple web front end for [Irc it](http://tools.suckless.org/ii/).
This web script implements an easy way to chat over an existing
[ii](http://tools.suckless.org/ii/) session.
The web front end it self is written with [W3C standard](http://www.w3.org/)
techniques.
Edit *chat.css* to customize the style of this chat front end.
The C implementations of the CGI scripts should be used within a chrooted
web server.
So no shell utilities have to be inside of the chroot directory.

1
cgi-bin/in Symbolic link
View File

@ -0,0 +1 @@
/tmp/irc/chat.freenode.org/in

6
cgi-bin/in.cgi Executable file
View File

@ -0,0 +1,6 @@
#!/bin/sh
cat - > in
echo Content-type: text/plain
echo

1
cgi-bin/out Symbolic link
View File

@ -0,0 +1 @@
/tmp/irc/out

40
cgi-bin/out.cgi Executable file
View File

@ -0,0 +1,40 @@
#!/bin/sh
echo Content-type: text/plain
echo
#LINES=$(echo $QUERY_STRING | sed -Ene 's/^bytes=([[:digit:]]*)(-)?$/\1/p')
QRY=$(echo $QUERY_STRING | sed -e 's/&/\n/g' -e 's/%23/#/g')
CHANNEL=$(echo "$QRY" | grep -Eim 1 '^channel='|cut -d"=" -f2-)
LINES=$(echo "$QRY" | grep -Eim 1 "lines=[[:digit:]]*"|cut -d"=" -f2-)
DIFF=0
IRCDIR='/tmp/irc/chat.freenode.org/'
CHAN=$(
case "$CHANNEL" in
"SERVER"|"#SERVER"|"") echo "./";;
*) echo "$IRCDIR/$CHANNEL";;
esac
)
#while [ $DIFF -eq 0 ]; do
# sleep 0.5
# DIFF=$(($(stat -Lc '%Z' out) - $LINES))
#done
#echo Content-Length: $DIFF
#printf "\n------\n"
#env
#echo "lines is $LINES"
#date
#DIFF=$(echo "$DIFF"|rev|cut -d"-" -f2-|rev)
#tail -c $DIFF out
echo "--------"
tail -n "${LINES:-"5"}" "$CHAN/out"
printf "%80s\n"|tr " " "-"
printf "$(date "+%F %T") - $CHANNEL"
#echo "
# lines $LINES
# channel $CHANNEL"
#echo "$QUERY_STRING"
#echo "diff $DIFF"

36
chat.css Normal file
View File

@ -0,0 +1,36 @@
body {
background-color: #ccc;
--bg: #123;
background-color: var(--bg);
}
hr{margin:0;padding:0;color:#fff;margin:0.25em}
a{color:white}
a:visited{color:lightgray}
#list{
display:float;
float:left;
}
#out,#in {
box-shadow: inset 0 0 0.5em 0.25em var(--bg), 0 0 0.75em 0.15em var(--bg);
border: none;outline: none;border-style: none;border-color: Transparent;
font-family: monospace;
font-size: 10pt;
overflow: hidden;
background-color: #000000;
color: #d3d7cf;
margin-top: 0.5em;
padding: 0.5em;
padding-bottom: 0.1em;
resize: none;
}
#out {margin-bottom:0;}
#in {margin-top:0;}
#con {
width: 650px;
margin: auto;
}

25
chat.html Normal file
View File

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<title>Irc It - Web Client</title>
<link rel="stylesheet" type="text/css" href="chat.css" />
<script src="chat.js"></script>
<script>get_output();</script>
</head>
<body>
<div id="list">
<ul>
<li> <a href="#SERVER" onClick="get_output();return true;"> #SERVER </a> </li>
<li> <a href="##jan6" onClick="get_output();return true;"> ##jan6 </a> </li>
</ul>
</div>
<div id="con">
<textarea id="out" readonly="readonly" rows="28" cols="80"></textarea>
<!--25 + 1 + 2 for status-->
<hr />
<input id="in" type="text" autofocus="autofocus" size="80" />
</div>
<script>get_output();</script>
</body>
</html>

69
chat.js Normal file
View File

@ -0,0 +1,69 @@
var http_in = new XMLHttpRequest();
var http_out = new XMLHttpRequest();
var offset = 0;
var lines = 25;
get_output();
var chan=""
chan=window.location.hash.substr(1);
if (chan == "") {chan="SERVER";}
else {chan="#"+chan;};
var channel=chan
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}
function out_event() {
setTimeout(function() {
if (http_out.readyState == 4) {
if (http_out.status != 500) {
// var len = parseInt(http_out.getResponseHeader("Content-Length"));
var len = 0;
// offset += isNaN(len) ? 0 : len;
offset = 0;
out_area = document.getElementById("out");
out_area.value += http_out.responseText;
out_area.scrollTop = out_area.scrollHeight;
}
// sleep(500);
get_output();
chan="";chan=window.location.hash.substr(1);
if (chan == "") {chan="SERVER";}
else {chan="#"+chan;};
console.log("selected channel: "+chan);
channel=chan;
}
},500)}
function get_output() {
setTimeout(function() {
http_out.onreadystatechange = out_event;
// range = "bytes=" + offset.toString() + "-";
http_out.open("GET", "/cgi-bin/out.cgi"+"?channel="+encodeURIComponent(channel)+"&lines="+encodeURIComponent(lines), true);
// http_out.setRequestHeader("Range", range);
http_out.send();
},10)}
function submit_input() {
var msg = document.getElementById("in").value + '\n';
document.getElementById("in").value = "";
http_in.open("POST", "/cgi-bin/in.cgi", true);
http_in.send(msg);
}
function key(e) {
if (e.keyCode == 13)
submit_input();
}
window.onload = function(e) {
document.getElementById("in").onkeyup = key;
get_output();
}

45
in.c Executable file
View File

@ -0,0 +1,45 @@
/*
* Copyright (c) 2013 - 2014 Jan Klemkow <j.klemkow@wemelug.de>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
int
main(int argc, char**argv)
{
char *file = "in";
char buf[BUFSIZ];
size_t size;
int fd;
if ((fd = open(file, O_WRONLY)) < 0)
goto err;
while ((size = read(STDIN_FILENO, buf, sizeof buf)) > 0)
if (write(fd, buf, size) < 0)
goto err;
if (size < 0)
goto err;
printf("Content-type: text/plain\n\n");
return EXIT_SUCCESS;
err:
perror(NULL);
return EXIT_FAILURE;
}

58
mobile.html Normal file
View File

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN"
"http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">
<html>
<head>
<title>wii - mobile</title>
<meta charset="utf-8"/>
<link rel="stylesheet" type="text/css" href="mobile.css"/>
<script src="layout.js"></script>
<!-- this is for phones -->
<meta name="viewport" content="width=device-width, initial-scale=1.0,
user-scalable=no" />
<meta name="mobile-web-app-capable" content="yes"/>
<link rel="icon" sizes="256x256" href="icon.png"/>
</head>
<body>
<div class="chat" id="one">
<textarea class="out" readonly="readonly">
a
a
a
a
a
a
a
a
a
a
a
a
a
</textarea>
<input class="in" type="text" />
</div>
<div class="chat" id="two" style="display: none;">
<textarea class="out" readonly="readonly">
b
b
b
b
b
b
b
b
b
b
b
b
b
</textarea>
<input class="in" type="text" />
</div>
</body>
</html>

67
out.c Executable file
View File

@ -0,0 +1,67 @@
/*
* Copyright (c) 2013 Jan Klemkow <j.klemkow@wemelug.de>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
off_t
get_range(void)
{
char *str = getenv("HTTP_RANGE");
if (str == NULL)
return 0;
if ((str = strchr(str, '=')) == NULL)
return 0;
return strtol(str + 1, NULL, 10);
}
int
main(int argv, char**argc)
{
char *file = "out";
int fd;
char buf[BUFSIZ];
size_t size, diff = 0;
off_t range = get_range();
if ((fd = open(file, O_RDONLY)) < 0)
goto err;
if (lseek(fd, range, SEEK_SET) < 0)
goto err;
/* TODO: if eof than use libevent to detect file changes */
printf("Content-Length: %zd\n", diff);
printf("Content-type: text/plain\n\n");
while ((size = read(fd, buf, BUFSIZ)) > 0)
if (write(STDOUT_FILENO, buf, size) < 0)
goto err;
if (size < 0)
goto err;
return EXIT_SUCCESS;
err:
perror(NULL);
return EXIT_FAILURE;
}