| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#include <sys/types.h> |
| 23 |
#include <kore/kore.h> |
| 24 |
#include <kore/hooks.h> |
| 25 |
|
| 26 |
#include <stdlib.h> |
| 27 |
|
| 28 |
static void |
| 29 |
usage(void) |
| 30 |
{ |
| 31 |
fprintf(stderr, |
| 32 |
"Usage: kore-serve [-i ip] [-p port] [-r root]\n"); |
| 33 |
|
| 34 |
exit(1); |
| 35 |
} |
| 36 |
|
| 37 |
void |
| 38 |
kore_parent_configure(int argc, char *argv[]) |
| 39 |
{ |
| 40 |
int ch; |
| 41 |
struct kore_domain *dom; |
| 42 |
struct kore_server *srv; |
| 43 |
char *rpath; |
| 44 |
const char *ip, *port, *root; |
| 45 |
|
| 46 |
root = "."; |
| 47 |
port = "8888"; |
| 48 |
ip = "127.0.0.1"; |
| 49 |
|
| 50 |
kore_quiet = 1; |
| 51 |
kore_foreground = 1; |
| 52 |
|
| 53 |
skip_runas = 1; |
| 54 |
skip_chroot = 1; |
| 55 |
|
| 56 |
kore_filemap_ext = kore_strdup(".html"); |
| 57 |
|
| 58 |
while ((ch = getopt(argc, argv, "hi:p:r:")) != -1) { |
| 59 |
switch (ch) { |
| 60 |
case 'i': |
| 61 |
ip = optarg; |
| 62 |
break; |
| 63 |
case 'h': |
| 64 |
usage(); |
| 65 |
break; |
| 66 |
case 'p': |
| 67 |
port = optarg; |
| 68 |
break; |
| 69 |
case 'r': |
| 70 |
root = optarg; |
| 71 |
break; |
| 72 |
default: |
| 73 |
usage(); |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
if ((rpath = realpath(root, NULL)) == NULL) |
| 78 |
fatal("realpath(%s): %s", root, errno_s); |
| 79 |
|
| 80 |
kore_log(LOG_INFO, "%s -> http://%s:%s", rpath, ip, port); |
| 81 |
|
| 82 |
srv = kore_server_create("kore-serve"); |
| 83 |
srv->tls = 0; |
| 84 |
|
| 85 |
if (!kore_server_bind(srv, ip, port, NULL)) |
| 86 |
fatal("Failed to bind to %s:%s (%s)", ip, port, errno_s); |
| 87 |
|
| 88 |
kore_server_finalize(srv); |
| 89 |
|
| 90 |
dom = kore_domain_new("*"); |
| 91 |
kore_domain_attach(dom, srv); |
| 92 |
|
| 93 |
if (kore_filemap_create(dom, rpath, "/", NULL) == NULL) |
| 94 |
fatal("failed to create filemap for %s", rpath); |
| 95 |
} |