Git Product home page Git Product logo

Comments (7)

ITwrx avatar ITwrx commented on August 16, 2024 1

i would rather the <link rel="stylesheet" href="darkhttpd.css"> be included in darkhttpd source, so that each user can just read the docs and add an optional darkhttpd.css. That's why i submitted an FR instead of just modifying my copy and moving on, assuming i could do it correctly since i don't write c. :)
thanks

from darkhttpd.

guest271314 avatar guest271314 commented on August 16, 2024

CSS will load with <link rel="stylesheet" href="darkhttpd.css"> and darkhttpd.css in the same directory.

from darkhttpd.

ITwrx avatar ITwrx commented on August 16, 2024

@guest271314 I guess i should have specified that i mean for the html that darkhttpd generates for serving whatever files happen to be in a directory, not serving my theoretical custom static html files. I'm using it for an alpine linux mirror, for example. i don't have any html it's serving. My understanding is that darkhttpd is generating it's own basic html to show the directories and package tarballs, and this FR asks that the <link rel="stylesheet" href="darkhttpd.css"> be added to that darkhttpd generation source code or a --css flag added.

from darkhttpd.

guest271314 avatar guest271314 commented on August 16, 2024

I guess i should have specified that i mean for the html that darkhttpd generates for serving whatever files happen to be in a directory

I'm not familiar with that option.

I was just reading the source code at https://github.com/emikulic/darkhttpd/blob/master/darkhttpd.c#L1530-L1579 however I don't see a way to serve that by passing options.

from darkhttpd.

guest271314 avatar guest271314 commented on August 16, 2024

It looks like this is where the directory listing is generated

darkhttpd/darkhttpd.c

Lines 1966 to 2056 in 11d36de

static void generate_dir_listing(struct connection *conn, const char *path,
const char *decoded_url) {
char date[DATE_LEN], *spaces;
struct dlent **list;
ssize_t listsize;
size_t maxlen = 2; /* There has to be ".." */
int i;
struct apbuf *listing;
listsize = make_sorted_dirlist(path, &list);
if (listsize == -1) {
default_reply(conn, 500, "Internal Server Error",
"Couldn't list directory: %s", strerror(errno));
return;
}
for (i=0; i<listsize; i++) {
size_t tmp = strlen(list[i]->name);
if (maxlen < tmp)
maxlen = tmp;
}
listing = make_apbuf();
append(listing, "<html>\n<head>\n<title>");
append_escaped(listing, decoded_url);
append(listing,
"</title>\n"
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n"
"</head>\n<body>\n<h1>");
append_escaped(listing, decoded_url);
append(listing, "</h1>\n<tt><pre>\n");
spaces = xmalloc(maxlen);
memset(spaces, ' ', maxlen);
for (i=0; i<listsize; i++) {
/* If a filename is made up of entirely unsafe chars,
* the url would be three times its original length.
*/
char safe_url[MAXNAMLEN*3 + 1];
urlencode(list[i]->name, safe_url);
append(listing, "<a href=\"");
append(listing, safe_url);
if (list[i]->is_dir)
append(listing, "/");
append(listing, "\">");
append_escaped(listing, list[i]->name);
append(listing, "</a>");
if (list[i]->is_dir)
append(listing, "/\n");
else {
appendl(listing, spaces, maxlen-strlen(list[i]->name));
appendf(listing, "%10llu\n", llu(list[i]->size));
}
}
cleanup_sorted_dirlist(list, listsize);
free(list);
free(spaces);
append(listing,
"</pre></tt>\n"
"<hr>\n");
rfc1123_date(date, now);
append(listing, generated_on(date));
append(listing, "</body>\n</html>\n");
conn->reply = listing->str;
conn->reply_length = (off_t)listing->length;
free(listing); /* don't free inside of listing */
conn->header_length = xasprintf(&(conn->header),
"HTTP/1.1 200 OK\r\n"
"Date: %s\r\n"
"%s" /* server */
"Accept-Ranges: bytes\r\n"
"%s" /* keep-alive */
"%s" /* custom headers */
"Content-Length: %llu\r\n"
"Content-Type: text/html; charset=UTF-8\r\n"
"\r\n",
date, server_hdr, keep_alive(conn), custom_hdrs,
llu(conn->reply_length));
conn->reply_type = REPLY_GENERATED;
conn->http_code = 200;
}
. In theory you should be able to include the CSS in the source code that generates the HTML in a <style> element, then compile darkhttpd.

from darkhttpd.

emikulic avatar emikulic commented on August 16, 2024

You probably want href="/absolute/path.css" so that it also works from nested directories and not just the root.

This is starting to get into "darkhttpd is not intended to be a production webserver" territory though. Directory listings are meant to be quick and dirty so you can download one of a small number of files in a hurry. If you want stylized ones, at some point you should make your own and save them as a set of index.html files.

from darkhttpd.

ITwrx avatar ITwrx commented on August 16, 2024

sure, my <link> is really just an example to explain the FR. I know dir listings and the auto-generated html is supposed to be minimalist, and i can get behind that, but i can't predict these dirs, as they are pulled in from rsync'd remote source and just being able to control background color, font size, etc of the generated html would make a huge difference, with only the <link> being added to darkhttpd source. I think users would like it, but it's up to you of course.

from darkhttpd.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.