mirror of
https://github.com/jorisvink/kore
synced 2025-03-10 21:19:01 -04:00
Add tools directory.
Includes the kore-serve utility that spins up a Kore instance on the local directory and serves the contents via a filemap on localhost port 8888. Used by myself when hacking on the kore website.
This commit is contained in:
parent
4e384167f0
commit
21d1e5156b
23
Makefile
23
Makefile
@ -6,12 +6,15 @@ PREFIX?=/usr/local
|
||||
OBJDIR?=obj
|
||||
KORE=kore
|
||||
KODEV=kodev/kodev
|
||||
KOREPATH?=$(shell pwd)
|
||||
KORE_CRYPTO?=crypto
|
||||
INSTALL_DIR=$(PREFIX)/bin
|
||||
MAN_DIR?=$(PREFIX)/share/man
|
||||
SHARE_DIR=$(PREFIX)/share/kore
|
||||
INCLUDE_DIR=$(PREFIX)/include/kore
|
||||
|
||||
TOOLS= kore-serve
|
||||
|
||||
GENERATED=
|
||||
PLATFORM=platform.h
|
||||
VERSION=$(OBJDIR)/version.c
|
||||
@ -223,6 +226,26 @@ uninstall:
|
||||
rm -rf $(SHARE_DIR)
|
||||
$(MAKE) -C kodev uninstall
|
||||
|
||||
tools-build: $(KODEV)
|
||||
for t in $(TOOLS); do \
|
||||
pushd tools/$$t; \
|
||||
env KODEV_OUTPUT=$(KOREPATH) $(KOREPATH)/$(KODEV) build; \
|
||||
popd; \
|
||||
done
|
||||
|
||||
tools-clean: $(KODEV)
|
||||
for t in $(TOOLS); do \
|
||||
pushd tools/$$t; \
|
||||
$(KOREPATH)/$(KODEV) clean; \
|
||||
popd; \
|
||||
done
|
||||
|
||||
tools-install:
|
||||
mkdir -p $(DESTDIR)$(INSTALL_DIR)
|
||||
for t in $(TOOLS); do \
|
||||
install -m 555 $$t $(DESTDIR)$(INSTALL_DIR)/$$t; \
|
||||
done
|
||||
|
||||
$(OBJDIR)/%.o: src/%.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
|
6
tools/kore-serve/.gitignore
vendored
Normal file
6
tools/kore-serve/.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
*.o
|
||||
.flavor
|
||||
.objs
|
||||
kore-serve.so
|
||||
assets.h
|
||||
cert
|
11
tools/kore-serve/conf/build.conf
Normal file
11
tools/kore-serve/conf/build.conf
Normal file
@ -0,0 +1,11 @@
|
||||
single_binary=yes
|
||||
kore_source=../../
|
||||
kore_flavor=NOTLS=1
|
||||
|
||||
cflags=-std=c99 -Werror
|
||||
cflags=-Wall -Wmissing-declarations -Wshadow
|
||||
cflags=-Wstrict-prototypes -Wmissing-prototypes
|
||||
cflags=-Wpointer-arith -Wcast-qual -Wsign-compare
|
||||
|
||||
dev {
|
||||
}
|
2
tools/kore-serve/conf/kore-serve.conf
Normal file
2
tools/kore-serve/conf/kore-serve.conf
Normal file
@ -0,0 +1,2 @@
|
||||
# kore-serve configuration
|
||||
# empty
|
94
tools/kore-serve/src/kore-serve.c
Normal file
94
tools/kore-serve/src/kore-serve.c
Normal file
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Joris Vink <joris@coders.se>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Simple static file serving over non TLS. Heavily used by myself
|
||||
* when working on kore-site.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <kore/kore.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"Usage: kore-serve [-i ip] [-p port] [-r root]\n");
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void
|
||||
kore_parent_configure(int argc, char *argv[])
|
||||
{
|
||||
int ch;
|
||||
struct kore_domain *dom;
|
||||
struct kore_server *srv;
|
||||
char *rpath;
|
||||
const char *ip, *port, *root;
|
||||
|
||||
root = ".";
|
||||
port = "8888";
|
||||
ip = "127.0.0.1";
|
||||
|
||||
foreground = 1;
|
||||
kore_quiet = 1;
|
||||
|
||||
skip_runas = 1;
|
||||
skip_chroot = 1;
|
||||
|
||||
kore_filemap_ext = kore_strdup(".html");
|
||||
|
||||
while ((ch = getopt(argc, argv, "hi:p:r:")) != -1) {
|
||||
switch (ch) {
|
||||
case 'i':
|
||||
ip = optarg;
|
||||
break;
|
||||
case 'h':
|
||||
usage();
|
||||
break;
|
||||
case 'p':
|
||||
port = optarg;
|
||||
break;
|
||||
case 'r':
|
||||
root = optarg;
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
}
|
||||
|
||||
if ((rpath = realpath(root, NULL)) == NULL)
|
||||
fatal("realpath(%s): %s", root, errno_s);
|
||||
|
||||
kore_log(LOG_INFO, "%s -> http://%s:%s", rpath, ip, port);
|
||||
|
||||
srv = kore_server_create("kore-serve");
|
||||
srv->tls = 0;
|
||||
|
||||
if (!kore_server_bind(srv, ip, port, NULL))
|
||||
fatal("Failed to bind to %s:%s (%s)", ip, port, errno_s);
|
||||
|
||||
kore_server_finalize(srv);
|
||||
|
||||
dom = kore_domain_new("*");
|
||||
kore_domain_attach(dom, srv);
|
||||
|
||||
if (!kore_filemap_create(dom, rpath, "/"))
|
||||
fatal("failed to create filemap for %s", rpath);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user