Mercurial > imgup
changeset 7:1cf90affaa33
misc: rename the project to imgup
author | David Demelier <markand@malikania.fr> |
---|---|
date | Thu, 26 Nov 2020 19:13:08 +0100 |
parents | 882acedb9b89 |
children | 51b272eab08a |
files | CHANGES.md CONTRIBUTE.md CREDITS.md INSTALL.md LICENSE.md Makefile README.md STYLE.md TODO.md config.c config.h database.h fragment-duration.h fragment-image.h fragment.h http.h image.h imgpaster.1.in imgpaster.sh imgpasterd-clean.8.in imgpasterd-clean.c imgpasterd.8.in imgpasterd.c imgup.1.in imgup.sh imgupd-clean.8.in imgupd-clean.c imgupd.8.in imgupd.c log.c log.h page-download.h page-image.h page-index.h page-new.h page-search.h page-static.h page.h themes/siimple/fragments/header.html util.h |
diffstat | 40 files changed, 769 insertions(+), 764 deletions(-) [+] |
line wrap: on
line diff
--- a/CHANGES.md Thu Nov 26 18:43:33 2020 +0100 +++ b/CHANGES.md Thu Nov 26 19:13:08 2020 +0100 @@ -1,7 +1,12 @@ -imgpaster CHANGES -================= +imgup CHANGES +============= -imgpaster 0.1.0 2020-11-26 --------------------------- +imgup current +---------------------- + +- Rename the project from imgpaster to imgup. + +imgup 0.1.0 2020-11-26 +---------------------- - Initial release.
--- a/CONTRIBUTE.md Thu Nov 26 18:43:33 2020 +0100 +++ b/CONTRIBUTE.md Thu Nov 26 19:13:08 2020 +0100 @@ -1,7 +1,7 @@ -imgpaster CONTRIBUTING GUIDE -============================ +imgup CONTRIBUTING GUIDE +======================== -Read this guide if you want to contribute to imgpaster. The purpose of this +Read this guide if you want to contribute to imgup. The purpose of this document is to describe the steps to submit a patch. You may submit a patch when: @@ -17,9 +17,9 @@ Subscribe to the mailing list ----------------------------- -Discussion and patches are sent to the *imgpaster@malikania.fr* mailing list. +Discussion and patches are sent to the *imgup@malikania.fr* mailing list. You need to subscribe by dropping a mail to -*imgpaster+subscribe@malikania.fr* first. +*imgup+subscribe@malikania.fr* first. Enable patchbomb extension -------------------------- @@ -38,7 +38,7 @@ [email] from = Your Name <youraddress@yourdomain.tld> - to = imgpaster@malikania.fr + to = imgup@malikania.fr [smtp] host = yourdomain.tld @@ -79,10 +79,10 @@ Create your patch ----------------- -Usually, when you create a patch, you should have your own copy of imgpaster +Usually, when you create a patch, you should have your own copy of imgup in your directory. -The following steps assumes that you have already cloned the imgpaster +The following steps assumes that you have already cloned the imgup repository somewhere. Note: the recommended way is to create one unique revision.
--- a/CREDITS.md Thu Nov 26 18:43:33 2020 +0100 +++ b/CREDITS.md Thu Nov 26 19:13:08 2020 +0100 @@ -1,5 +1,5 @@ -imgpaster CREDITS -================= +imgup CREDITS +============= Libraries and projects ----------------------
--- a/INSTALL.md Thu Nov 26 18:43:33 2020 +0100 +++ b/INSTALL.md Thu Nov 26 19:13:08 2020 +0100 @@ -1,5 +1,5 @@ -imgpaster INSTALL -================= +imgup INSTALL +============= Installation instructions. @@ -8,27 +8,27 @@ - [kcgi][], minimal CGI/FastCGI library for C, - [sqlite][], most used database in the world, -- [curl][], (Optional) only for `imgpaster(8)` client. +- [curl][], (Optional) only for `imgup(8)` client. Basic installation ------------------ Quick install. - $ tar xvzf imgpaster-x.y.z-tar.xz - $ cd imgpaster-x.y.z + $ tar xvzf imgup-x.y.z-tar.xz + $ cd imgup-x.y.z $ make # sudo make install To only install the web application: - $ make imgpasterd - # make install-imgpasterd + $ make imgupd + # make install-imgupd To only install the client: - $ make imgpaster - # make install-imgpaster + $ make imgup + # make install-imgup [curl]: https://curl.haxx.se [kcgi]: https://kristaps.bsd.lv/kcgi
--- a/LICENSE.md Thu Nov 26 18:43:33 2020 +0100 +++ b/LICENSE.md Thu Nov 26 19:13:08 2020 +0100 @@ -1,5 +1,5 @@ -imgpaster ISC LICENSE -===================== +imgup ISC LICENSE +================= Copyright (c) 2020 David Demelier <markand@malikania.fr>
--- a/Makefile Thu Nov 26 18:43:33 2020 +0100 +++ b/Makefile Thu Nov 26 19:13:08 2020 +0100 @@ -1,5 +1,5 @@ # -# Makefile -- basic makefile for imgpaster +# Makefile -- basic makefile for imgup # # Copyright (c) 2020 David Demelier <markand@malikania.fr> # @@ -65,7 +65,7 @@ util.h CORE_OBJS= ${CORE_SRCS:.c=.o} CORE_DEPS= ${CORE_SRCS:.c=.d} -CORE_LIB= libimgpaster.a +CORE_LIB= libimgup.a TESTS_SRCS= tests/test-database.c TESTS_OBJS= ${TESTS_SRCS:.c=} @@ -85,9 +85,9 @@ .SUFFIXES: .SUFFIXES: .o .c .in -all: imgpasterd imgpasterd-clean imgpaster +all: imgupd imgupd-clean imgup --include ${CORE_DEPS} imgpaster.d imgpasterd-clean.d +-include ${CORE_DEPS} imgup.d imgupd-clean.d .c.o: ${CC} ${MY_CFLAGS} ${CFLAGS} -c $< @@ -110,53 +110,53 @@ ${CORE_LIB}: ${CORE_OBJS} ${AR} -rc $@ ${CORE_OBJS} -imgpasterd-clean.o: imgpasterd-clean.8 ${CORE_LIB} ${SQLITE_LIB} +imgupd-clean.o: imgupd-clean.8 ${CORE_LIB} ${SQLITE_LIB} -imgpasterd.o: imgpasterd.8 ${CORE_LIB} ${SQLITE_LIB} +imgupd.o: imgupd.8 ${CORE_LIB} ${SQLITE_LIB} -imgpaster: imgpaster.sh imgpaster.1 - cp imgpaster.sh imgpaster - chmod +x imgpaster +imgup: imgup.sh imgup.1 + cp imgup.sh imgup + chmod +x imgup clean: rm -f ${SQLITE_LIB} extern/sqlite3.o rm -f ${CORE_LIB} ${CORE_OBJS} ${CORE_DEPS} - rm -f imgpasterd pasterd.d imgpasterd.o pasterd.8 - rm -f imgpasterd-clean imgpasterd-clean.d imgpasterd-clean.o imgpasterd-clean.8 - rm -f imgpaster imgpaster.1 + rm -f imgupd imgupd.d imgupd.o imgupd.8 + rm -f imgupd-clean imgupd-clean.d imgupd-clean.o imgupd-clean.8 + rm -f imgup imgup.1 rm -f test.db ${TESTS_OBJS} -install-imgpaster: +install-imgup: mkdir -p ${DESTDIR}${BINDIR} mkdir -p ${DESTDIR}${MANDIR}/man1 - cp imgpaster ${DESTDIR}${BINDIR} - cp imgpaster.1 ${DESTDIR}${MANDIR}/man1/imgpaster.1 + cp imgup ${DESTDIR}${BINDIR} + cp imgup.1 ${DESTDIR}${MANDIR}/man1/imgup.1 -install-imgpasterd: +install-imgupd: mkdir -p ${DESTDIR}${BINDIR} mkdir -p ${DESTDIR}${MANDIR}/man8 - cp imgpasterd ${DESTDIR}${BINDIR} - cp imgpasterd-clean ${DESTDIR}${BINDIR} - mkdir -p ${DESTDIR}${SHAREDIR}/imgpaster - cp -R themes ${DESTDIR}${SHAREDIR}/imgpaster - cp imgpasterd.8 ${DESTDIR}${MANDIR}/man8 - cp imgpasterd-clean.8 ${DESTDIR}${MANDIR}/man8 + cp imgupd ${DESTDIR}${BINDIR} + cp imgupd-clean ${DESTDIR}${BINDIR} + mkdir -p ${DESTDIR}${SHAREDIR}/imgup + cp -R themes ${DESTDIR}${SHAREDIR}/imgup + cp imgupd.8 ${DESTDIR}${MANDIR}/man8 + cp imgupd-clean.8 ${DESTDIR}${MANDIR}/man8 -install: install-imgpasterd install-imgpaster +install: install-imgupd install-imgup dist: clean - mkdir -p imgpaster-${VERSION} - cp -R extern imgpaster-${VERSION} - cp -R themes imgpaster-${VERSION} - cp -R tests imgpaster-${VERSION} - cp ${CORE_SRCS} ${CORE_HDRS} imgpaster-${VERSION} - cp imgpasterd.8.in imgpasterd.c imgpaster-${VERSION} - cp imgpasterd-clean.8.in imgpasterd-clean.c imgpaster-${VERSION} - cp imgpaster.1.in imgpaster.sh imgpaster-${VERSION} + mkdir -p imgup-${VERSION} + cp -R extern imgup-${VERSION} + cp -R themes imgup-${VERSION} + cp -R tests imgup-${VERSION} + cp ${CORE_SRCS} ${CORE_HDRS} imgup-${VERSION} + cp imgupd.8.in imgupd.c imgup-${VERSION} + cp imgupd-clean.8.in imgupd-clean.c imgup-${VERSION} + cp imgup.1.in imgup.sh imgup-${VERSION} cp Makefile CHANGES.md CONTRIBUTE.md CREDITS.md INSTALL.md LICENSE.md \ - README.md STYLE.md TODO.md imgpaster-${VERSION} - tar -cJf imgpaster-${VERSION}.tar.xz imgpaster-${VERSION} - rm -rf imgpaster-${VERSION} + README.md STYLE.md TODO.md imgup-${VERSION} + tar -cJf imgup-${VERSION}.tar.xz imgup-${VERSION} + rm -rf imgup-${VERSION} ${TESTS_OBJS}: ${CORE_LIB} ${SQLITE_LIB}
--- a/README.md Thu Nov 26 18:43:33 2020 +0100 +++ b/README.md Thu Nov 26 19:13:08 2020 +0100 @@ -1,12 +1,12 @@ -imgpaster -========= +imgup +===== A minimalist temporary image hosting service written in C11. Documentation ------------- -See `imgpasterd(8)` manual page. +See `imgupd(8)` manual page. Author ------
--- a/STYLE.md Thu Nov 26 18:43:33 2020 +0100 +++ b/STYLE.md Thu Nov 26 19:13:08 2020 +0100 @@ -1,5 +1,5 @@ -imgpaster CODING STYLE -====================== +imgup CODING STYLE +================== File content ============
--- a/TODO.md Thu Nov 26 18:43:33 2020 +0100 +++ b/TODO.md Thu Nov 26 19:13:08 2020 +0100 @@ -1,5 +1,5 @@ -imgpaster TODO -============== +imgup TODO +========== - Allow non-absolute themes paths, relative to data directory, - Add more logs and verbosity levels.
--- a/config.c Thu Nov 26 18:43:33 2020 +0100 +++ b/config.c Thu Nov 26 19:13:08 2020 +0100 @@ -1,5 +1,5 @@ /* - * config.c -- imgpasterd options + * config.c -- imgupd options * * Copyright (c) 2020 David Demelier <markand@malikania.fr> * @@ -19,7 +19,7 @@ #include "config.h" struct config config = { - .databasepath = VARDIR "/imgpaster/imgpaster.db", - .themedir = SHAREDIR "/imgpaster/themes/minimal", + .databasepath = VARDIR "/imgup/imgup.db", + .themedir = SHAREDIR "/imgup/themes/minimal", .verbosity = 1 };
--- a/config.h Thu Nov 26 18:43:33 2020 +0100 +++ b/config.h Thu Nov 26 19:13:08 2020 +0100 @@ -1,5 +1,5 @@ /* - * config.h -- imgpasterd options + * config.h -- imgupd options * * Copyright (c) 2020 David Demelier <markand@malikania.fr> * @@ -16,8 +16,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifndef IMGPASTER_CONFIG_H -#define IMGPASTER_CONFIG_H +#ifndef IMGUP_CONFIG_H +#define IMGUP_CONFIG_H #include <limits.h> @@ -29,4 +29,4 @@ enum log_level verbosity; } config; -#endif /* !IMGPASTER_CONFIG_H */ +#endif /* !IMGUP_CONFIG_H */
--- a/database.h Thu Nov 26 18:43:33 2020 +0100 +++ b/database.h Thu Nov 26 19:13:08 2020 +0100 @@ -16,8 +16,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifndef IMGPASTER_DATABASE_H -#define IMGPASTER_DATABASE_H +#ifndef IMGUP_DATABASE_H +#define IMGUP_DATABASE_H #include <stdbool.h> #include <stddef.h> @@ -48,4 +48,4 @@ void database_finish(void); -#endif /* !IMGPASTER_DATABASE_H */ +#endif /* !IMGUP_DATABASE_H */
--- a/fragment-duration.h Thu Nov 26 18:43:33 2020 +0100 +++ b/fragment-duration.h Thu Nov 26 19:13:08 2020 +0100 @@ -16,12 +16,12 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifndef IMGPASTER_FRAGMENT_DURATION_H -#define IMGPASTER_FRAGMENT_DURATION_H +#ifndef IMGUP_FRAGMENT_DURATION_H +#define IMGUP_FRAGMENT_DURATION_H struct kreq; void fragment_duration(struct kreq *, const char *); -#endif /* !IMGPASTER_FRAGMENT_DURATION_H */ +#endif /* !IMGUP_FRAGMENT_DURATION_H */
--- a/fragment-image.h Thu Nov 26 18:43:33 2020 +0100 +++ b/fragment-image.h Thu Nov 26 19:13:08 2020 +0100 @@ -16,8 +16,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifndef IMGPASTER_FRAGMENT_IMAGE_H -#define IMGPASTER_FRAGMENT_IMAGE_H +#ifndef IMGUP_FRAGMENT_IMAGE_H +#define IMGUP_FRAGMENT_IMAGE_H struct image; struct kreq; @@ -25,4 +25,4 @@ void fragment_image(struct kreq *, const struct image *); -#endif /* !IMGPASTER_FRAGMENT_IMAGE_H */ +#endif /* !IMGUP_FRAGMENT_IMAGE_H */
--- a/fragment.h Thu Nov 26 18:43:33 2020 +0100 +++ b/fragment.h Thu Nov 26 19:13:08 2020 +0100 @@ -16,8 +16,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifndef IMGPASTER_FRAGMENT_H -#define IMGPASTER_FRAGMENT_H +#ifndef IMGUP_FRAGMENT_H +#define IMGUP_FRAGMENT_H struct kreq; struct ktemplate; @@ -25,4 +25,4 @@ void fragment(struct kreq *, const struct ktemplate *, const char *); -#endif /* !IMGPASTER_FRAGMENT_H */ +#endif /* !IMGUP_FRAGMENT_H */
--- a/http.h Thu Nov 26 18:43:33 2020 +0100 +++ b/http.h Thu Nov 26 19:13:08 2020 +0100 @@ -16,8 +16,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifndef IMGPASTER_HTTP_H -#define IMGPASTER_HTTP_H +#ifndef IMGUP_HTTP_H +#define IMGUP_HTTP_H void http_fcgi_run(void); @@ -25,4 +25,4 @@ void http_cgi_run(void); -#endif /* !IMGPASTER_HTTP_H */ +#endif /* !IMGUP_HTTP_H */
--- a/image.h Thu Nov 26 18:43:33 2020 +0100 +++ b/image.h Thu Nov 26 19:13:08 2020 +0100 @@ -16,8 +16,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifndef IMGPASTER_IMAGE_H -#define IMGPASTER_IMAGE_H +#ifndef IMGUP_IMAGE_H +#define IMGUP_IMAGE_H #include <stdbool.h> #include <stddef.h> @@ -51,4 +51,4 @@ bool image_isvalid(const void *, size_t); -#endif /* !IMGPASTER_IMAGE_H */ +#endif /* !IMGUP_IMAGE_H */
--- a/imgpaster.1.in Thu Nov 26 18:43:33 2020 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -.\" -.\" Copyright (c) 2020 David Demelier <markand@malikania.fr> -.\" -.\" Permission to use, copy, modify, and/or 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. -.\" -.Dd 25 November, 2020 -.Dt IMGPASTER 1 -.Os -.\" NAME -.Sh NAME -.Nm imgpaster -.Nd simple image hosting service client -.\" SYNOPSIS -.Sh SYNOPSIS -.Nm -.Op Fl Dpv -.Op Fl a Ar author -.Op Fl d Ar duration -.Op Fl t Ar title -.Ar filename -.Ar host -.\" DESCRIPTION -.Sh DESCRIPTION -The -.Nm -tool is the convenient brother to -.Nm imgpasterd , -it will upload an image into an instance. -.Pp -The -.Ar filename -argument must point to an image and the -.Ar host -argument is a URL where a -.Nm imgpasterd -instance is running. -.Pp -Available options: -.Bl -tag -width Ds -.It Fl D -List all supported durations. -.It Fl p -Store the image as public (default is private). -.It Fl v -Be more verbose. -.It Fl a Ar author -Sets the author, defaults to -.Dq Anonymous . -.Dq "nohighlight" . -.It Fl d Ar duration -Sets the paste lifetime, defaults to -.Dq "day" . -.It Fl t Ar title -Sets a title to the paste, defaults to -.Dq "Untitled" . -.\" EXAMPLES -.Sh EXAMPLES -.Ss Upload the image background.png with a title and an author. -.Bd -literal -offset -imgpaster -t "Nice background" -a Francis background.sh http://example.org -.Ed -.Ss Paste a short duration image. -.Bd -literal -offset -imgpaster -p -d hour secret.png http://example.org -.Ed -.\" AUTHORS -.Sh AUTHORS -.Nm -was written by David Demelier <markand@malikania.fr> -.\" SEE ALSO -.Sh SEE ALSO -.Xr imgpasterd 8
--- a/imgpaster.sh Thu Nov 26 18:43:33 2020 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,117 +0,0 @@ -# -# imgpaster -- convenient front-end to a imgpasterd instance -# -# Copyright (c) 2020 David Demelier <markand@malikania.fr> -# -# Permission to use, copy, modify, and/or 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. -# - -author="Anonymous" -title="Untitled" -duration="day" -public=0 -verbose=0 - -die() -{ - echo "$@" 1>&2 - exit 1 -} - -durations() -{ - echo "hour" - echo "day" - echo "week" - echo "month" - exit 0 -} - -usage() -{ - cat 1>&2 <<-EOF - usage: paster [-Dpv] [-a author] [-d duration] [-t title] filename host - EOF - exit 1 -} - -send() -{ - if [ $public -eq 1 ]; then - with_private="-F private=off" - else - with_private="-F private=on" - fi - - if [ $verbose -eq 0 ]; then - with_verbose="-s" - fi - - curl -i \ - -F author="$author" \ - -F duration="$duration" \ - -F title="$title" \ - -F filename=@"$1" \ - $with_private \ - $with_verbose \ - "$2"/new -} - -if ! command -v curl >/dev/null 2>&1; then - die "abort: curl is required" -fi - -while getopts "Da:d:pt:v" opt; do - case "$opt" in - D) - durations - ;; - a) - author="$OPTARG" - ;; - d) - duration="$OPTARG" - ;; - p) - public=1 - ;; - t) - title="$OPTARG" - ;; - v) - verbose=1 - ;; - *) - usage - ;; - esac -done - -shift $((OPTIND - 1)) - -if [ "$#" -ne 2 ]; then - usage -fi - -# If verbose, dump all headers. -if [ $verbose -eq 1 ]; then - send "$1" "$2" -else - url=$(send "$1" "$2" | grep -E "^Location: " | awk '{ print $2 }') - - if [ -z "$url" ]; then - die "abort: error occured, retry with -v" - fi - - printf "%s%s\n" "$2" "$url" -fi
--- a/imgpasterd-clean.8.in Thu Nov 26 18:43:33 2020 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ -.\" -.\" Copyright (c) 2020 David Demelier <markand@malikania.fr> -.\" -.\" Permission to use, copy, modify, and/or 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. -.\" -.Dd 06 February, 2020 -.Dt IMGPASTERD-CLEAN 8 -.Os -.\" NAME -.Sh NAME -.Nm imgpasterd-clean -.Nd simple image hosting service cleaner -.\" SYNOPSIS -.Sh SYNOPSIS -.Nm -.Op Fl d Ar database-path -.\" DESCRIPTION -.Sh DESCRIPTION -This utility should be used at periodic intervals to clean up the SQLite -database. It will remove deprecated images. -.Pp -Like -.Xr imgpasterd 8 -it can use environment variables or option to specify the database. -.Pp -Available options: -.Bl -tag -width Ds -.It Fl d Ar database-path -Specify an alternate path for the database. -.El -.\" USAGE -.Sh USAGE -This command should be placed in a cron job (or equivalent) at periodic -intervals. Since the minimal lifetime for an image is one hour a periodic job -every hour seems appropriate. -.Pp -Note: make sure to run the cron job in the same user as the pasterd service, -otherwise you may change file permissions. -.Pp -Example of cron job: -.Bd -literal -offset Ds -0 * * * * www imgpasterd-clean -d /var/paster/paster.db -.Ed -.\" ENVIRONMENT -.Sh ENVIRONMENT -The following environment variables are detected: -.Bl -tag -width Ds -.It Va IMGPASTERD_DATABASE_PATH No (string) -Path to the SQLite database. -.El -.\" AUTHORS -.Sh AUTHORS -.Nm -was written by David Demelier <markand@malikania.fr> -.\" SEE ALSO -.Sh SEE ALSO -.Xr imgpasterd 8
--- a/imgpasterd-clean.c Thu Nov 26 18:43:33 2020 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/* - * pasterd-clean.c -- main pasterd-clean(8) file - * - * Copyright (c) 2020 David Demelier <markand@malikania.fr> - * - * Permission to use, copy, modify, and/or 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 <limits.h> -#include <stdio.h> -#include <stdlib.h> -#include <stdnoreturn.h> -#include <unistd.h> - -#include "database.h" -#include "util.h" - -static noreturn void -usage(void) -{ - fprintf(stderr, "usage: imgpasterd-clean [-d database-path]\n"); - exit(1); -} - -int -main(int argc, char **argv) -{ - const char *value; - char path[PATH_MAX] = VARDIR "/imgpaster/imgpaster.db"; - int ch; - - /* Seek environment first. */ - if ((value = getenv("IMGPASTERD_DATABASE_PATH"))) - snprintf(path, sizeof (path), "%s", value); - - while ((ch = getopt(argc, argv, "d:")) != -1) { - switch (ch) { - case 'd': - snprintf(path, sizeof (path), "%s", optarg); - break; - default: - usage(); - break; - } - } - - if (!path[0]) - die("abort: no database specified"); - if (!database_open(path)) - die("abort: could not open database"); - - database_clear(); - database_finish(); -}
--- a/imgpasterd.8.in Thu Nov 26 18:43:33 2020 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,207 +0,0 @@ -.\" -.\" Copyright (c) 2020 David Demelier <markand@malikania.fr> -.\" -.\" Permission to use, copy, modify, and/or 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. -.\" -.Dd 25 November, 2020 -.Dt IMGPASTERD 8 -.Os -.\" NAME -.Sh NAME -.Nm imgpasterd -.Nd simple image hosting service -.\" SYNOPSIS -.Sh SYNOPSIS -.Nm -.Op Fl fqv -.Op Fl d Ar database-path -.Op Fl t Ar theme-directory -.\" DESCRIPTION -.Sh DESCRIPTION -The -.Nm -utility is a simple CGI or FastCGI program to host temporary images over a web -interface. It will show most recent uploaded images and let users to create new -one from a web form. -.Pp -It supports: -.Bl -bullet -compat -.It -Listing of recent images, -.It -Submission of new images, -.It -Searching existing images, -.It -Private images (not listed). -.El -.Pp -To store images, -.Nm -uses a SQLite database that must be writable by the CGI/FastCGI owner. See usage -below. -.Pp -Available options: -.Bl -tag -width Ds -.It Fl f -Starts as FastCGI mode, -.Nm -will wait forever for new requests. -.It Fl d Ar database-path -Specify an alternate path for the database. -.It Fl t Ar theme-directory -Specify an alternate directory for the theme. -.It Fl q -Do not log through syslog at all. -.It Fl v -Increase verbosity level. -.El -.\" USAGE -.Sh USAGE -The -.Nm -utility does not use configuration file as it does not need many adjustments, -instead every parameter could be passed by environment variables or options. -.Pp -By default, -.Nm -will try to use -.Pa @VARDIR@/imgpaster/imgpaster.db -database. -.\" LOGS -.Sh LOGS -The -.Nm -utility will log information through syslog unless verbosity is disabled. -Except at startup where the tool can write to stderr some information if it -can't continue processing, the tool will never write anything to stdout and -use syslog only. -.Pp -The available verbosity level is defined in the following order: -.Bd -literal -offset Ds -none < warnings (default) < info < debug -.Ed -.Pp -Use -.Fl q -or -.Va IMGPASTERD_VERBOSITY=0 -if you want to disable syslog completely. -.\" USING WITH FASTCGI -.Sh USING WITH FASTCGI -The recommended way to use -.Nm -is to deploy using FastCGI. You can use the -.Xr kfcgi 8 -helper to spawn the process for you. -.Pp -Example: -.Bd -literal -offset Ds -kfcgi -p /var/www/imgpaster -- imgpasterd -f -d imgpaster.db -t siimple -.Ed -.Pp -Note: kfcgi chroot to the directory given, you must either statically link -imgpasterd at build time or deploy all required libraries. Also, themes -directory will need to be available in the chroot directory. In the above -example, this will effectively create a database -.Pa /var/www/imgpaster/imgpaster.db -and use the theme -.Pa /var/www/imgpaster/siimple . -.Pp -Then, simply copy the desired theme into the directory. -.Bd -literal -offset Ds -cp -R @SHAREDIR@/imgpaster/themes/siimple /var/www/imgpaster -.Ed -.Pp -As an -.Em insecure -alternative, you can chroot to -.Pa / -to avoid static-linking and copying themes, using: -.Bd -literal -offset Ds -kfcgi -p / -- imgpasterd -f \e - -d /var/www/imgpaster/imgpaster.db \e - -t @SHAREDIR@/imgpaster/themes/siimple -.Ed -.Pp -Both kfcgi invocations will create -.Pa /var/www/run/http.sock -with current user and group. Configure the web server to talk to that socket -and make sure it has appropriate file permissions otherwise see -.Fl u -option in -.Nm kfcgi . -See also the -.Xr kfcgi 8 -manual for more information. -.Pp -Next, configure the web server. -.Pp -Warning: at this moment, -.Nm -requires its own virtual host and can -.Em not -use a url. -.\" Server: nginx -.Ss Server: nginx -The nginx web server requires several parameters to run -.Nm . -.Bd -literal -server { - server_name mypaste.fr; - listen 80; - - location / { - fastcgi_param QUERY_STRING query_string; - fastcgi_param REQUEST_METHOD $request_method; - fastcgi_param CONTENT_TYPE $content_type; - fastcgi_param CONTENT_LENGTH $content_length; - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - fastcgi_param SCRIPT_NAME $fastcgi_script_name; - fastcgi_param PATH_INFO $document_uri; - fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; - fastcgi_param REQUEST_URI $request_uri; - fastcgi_param DOCUMENT_URI $document_uri; - fastcgi_param DOCUMENT_ROOT $document_root; - fastcgi_param SERVER_PROTOCOL $server_protocol; - fastcgi_param GATEWAY_INTERFACE CGI/1.1; - fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; - fastcgi_param REMOTE_ADDR $remote_addr; - fastcgi_param REMOTE_PORT $remote_port; - fastcgi_param SERVER_ADDR $server_addr; - fastcgi_param SERVER_PORT $server_port; - fastcgi_param SERVER_NAME $server_name; - fastcgi_param HTTPS $https; - fastcgi_pass unix:/var/www/run/httpd.sock; - } -} -.Ed -.\" ENVIRONMENT -.Sh ENVIRONMENT -The following environment variables are detected: -.Bl -tag -width Ds -.It Va IMGPASTERD_DATABASE_PATH No (string) -Path to the SQLite database. -.It Va IMGPASTERD_THEME_DIR No (string) -Directory containing the theme. -.It Va IMGPASTERD_VERBOSITY No (number) -Verbosity level, 0 to disable completely. -.El -.\" AUTHORS -.Sh AUTHORS -.Nm -was written by David Demelier <markand@malikania.fr> -.\" SEE ALSO -.Sh SEE ALSO -.Xr imgpaster 1 , -.Xr kfcgi 8
--- a/imgpasterd.c Thu Nov 26 18:43:33 2020 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,107 +0,0 @@ -/* - * imgpasterd.c -- main imgpasterd(8) file - * - * Copyright (c) 2020 David Demelier <markand@malikania.fr> - * - * Permission to use, copy, modify, and/or 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 <stdnoreturn.h> -#include <time.h> -#include <unistd.h> - -#include "config.h" -#include "database.h" -#include "http.h" -#include "log.h" -#include "util.h" - -static void -defaults(void) -{ - snprintf(config.databasepath, sizeof (config.databasepath), - "%s", VARDIR "/imgpaster/imgpaster.db"); -} - -static void -init(void) -{ - srand(time(NULL)); - log_open(); - - if (!config.databasepath[0]) - die("abort: no database specified\n"); - if (!database_open(config.databasepath)) - die("abort: could not open database\n"); -} - -static void -quit(void) -{ - database_finish(); - log_finish(); -} - -static noreturn void -usage(void) -{ - fprintf(stderr, "usage: paster [-fqv] [-d database-path] [-t theme-directory]\n"); - exit(1); -} - -int -main(int argc, char **argv) -{ - const char *value; - int opt; - void (*run)(void) = &(http_cgi_run); - - defaults(); - - /* Seek environment variables before options. */ - if ((value = getenv("IMGPASTERD_DATABASE_PATH"))) - snprintf(config.databasepath, sizeof (config.databasepath), "%s", value); - if ((value = getenv("IMGPASTERD_THEME_DIR"))) - snprintf(config.themedir, sizeof (config.themedir), "%s", value); - if ((value = getenv("IMGPASTERD_VERBOSITY"))) - config.verbosity = atoi(value); - - while ((opt = getopt(argc, argv, "d:ft:qv")) != -1) { - switch (opt) { - case 'd': - snprintf(config.databasepath, sizeof (config.databasepath), "%s", optarg); - break; - case 't': - snprintf(config.themedir, sizeof (config.themedir), "%s", optarg); - break; - case 'f': - run = &(http_fcgi_run); - break; - case 'v': - config.verbosity++; - break; - case 'q': - config.verbosity = 0; - break; - default: - usage(); - break; - } - } - - init(); - run(); - quit(); -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/imgup.1.in Thu Nov 26 19:13:08 2020 +0100 @@ -0,0 +1,82 @@ +.\" +.\" Copyright (c) 2020 David Demelier <markand@malikania.fr> +.\" +.\" Permission to use, copy, modify, and/or 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. +.\" +.Dd 25 November, 2020 +.Dt IMGUP 1 +.Os +.\" NAME +.Sh NAME +.Nm imgup +.Nd simple image hosting service client +.\" SYNOPSIS +.Sh SYNOPSIS +.Nm +.Op Fl Dpv +.Op Fl a Ar author +.Op Fl d Ar duration +.Op Fl t Ar title +.Ar filename +.Ar host +.\" DESCRIPTION +.Sh DESCRIPTION +The +.Nm +tool is the convenient brother to +.Nm imgupd , +it will upload an image into an instance. +.Pp +The +.Ar filename +argument must point to an image and the +.Ar host +argument is a URL where a +.Nm imgupd +instance is running. +.Pp +Available options: +.Bl -tag -width Ds +.It Fl D +List all supported durations. +.It Fl p +Store the image as public (default is private). +.It Fl v +Be more verbose. +.It Fl a Ar author +Sets the author, defaults to +.Dq Anonymous . +.It Fl d Ar duration +Sets the paste lifetime, defaults to +.Dq "day" . +.It Fl t Ar title +Sets a title to the paste, defaults to +.Dq "Untitled" . +.El +.\" EXAMPLES +.Sh EXAMPLES +.Ss Upload the image background.png with a title and an author. +.Bd -literal -offset +imgup -t "Nice background" -a Francis background.sh http://example.org +.Ed +.Ss Paste a short duration image. +.Bd -literal -offset +imgup -p -d hour secret.png http://example.org +.Ed +.\" AUTHORS +.Sh AUTHORS +.Nm +was written by David Demelier <markand@malikania.fr> +.\" SEE ALSO +.Sh SEE ALSO +.Xr imgupd 8
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/imgup.sh Thu Nov 26 19:13:08 2020 +0100 @@ -0,0 +1,117 @@ +# +# imgup -- convenient front-end to a imgupd instance +# +# Copyright (c) 2020 David Demelier <markand@malikania.fr> +# +# Permission to use, copy, modify, and/or 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. +# + +author="Anonymous" +title="Untitled" +duration="day" +public=0 +verbose=0 + +die() +{ + echo "$@" 1>&2 + exit 1 +} + +durations() +{ + echo "hour" + echo "day" + echo "week" + echo "month" + exit 0 +} + +usage() +{ + cat 1>&2 <<-EOF + usage: imgup [-Dpv] [-a author] [-d duration] [-t title] filename host + EOF + exit 1 +} + +send() +{ + if [ $public -eq 1 ]; then + with_private="-F private=off" + else + with_private="-F private=on" + fi + + if [ $verbose -eq 0 ]; then + with_verbose="-s" + fi + + curl -i \ + -F author="$author" \ + -F duration="$duration" \ + -F title="$title" \ + -F filename=@"$1" \ + $with_private \ + $with_verbose \ + "$2"/new +} + +if ! command -v curl >/dev/null 2>&1; then + die "abort: curl is required" +fi + +while getopts "Da:d:pt:v" opt; do + case "$opt" in + D) + durations + ;; + a) + author="$OPTARG" + ;; + d) + duration="$OPTARG" + ;; + p) + public=1 + ;; + t) + title="$OPTARG" + ;; + v) + verbose=1 + ;; + *) + usage + ;; + esac +done + +shift $((OPTIND - 1)) + +if [ "$#" -ne 2 ]; then + usage +fi + +# If verbose, dump all headers. +if [ $verbose -eq 1 ]; then + send "$1" "$2" +else + url=$(send "$1" "$2" | grep -E "^Location: " | awk '{ print $2 }') + + if [ -z "$url" ]; then + die "abort: error occured, retry with -v" + fi + + printf "%s%s\n" "$2" "$url" +fi
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/imgupd-clean.8.in Thu Nov 26 19:13:08 2020 +0100 @@ -0,0 +1,67 @@ +.\" +.\" Copyright (c) 2020 David Demelier <markand@malikania.fr> +.\" +.\" Permission to use, copy, modify, and/or 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. +.\" +.Dd 06 February, 2020 +.Dt IMGUPD-CLEAN 8 +.Os +.\" NAME +.Sh NAME +.Nm imgupd-clean +.Nd simple image hosting service cleaner +.\" SYNOPSIS +.Sh SYNOPSIS +.Nm +.Op Fl d Ar database-path +.\" DESCRIPTION +.Sh DESCRIPTION +This utility should be used at periodic intervals to clean up the SQLite +database. It will remove deprecated images. +.Pp +Like +.Xr imgupd 8 +it can use environment variables or option to specify the database. +.Pp +Available options: +.Bl -tag -width Ds +.It Fl d Ar database-path +Specify an alternate path for the database. +.El +.\" USAGE +.Sh USAGE +This command should be placed in a cron job (or equivalent) at periodic +intervals. Since the minimal lifetime for an image is one hour a periodic job +every hour seems appropriate. +.Pp +Note: make sure to run the cron job in the same user as the imgupd service, +otherwise you may change file permissions. +.Pp +Example of cron job: +.Bd -literal -offset Ds +0 * * * * www imgupd-clean -d /var/imgup/imgup.db +.Ed +.\" ENVIRONMENT +.Sh ENVIRONMENT +The following environment variables are detected: +.Bl -tag -width Ds +.It Va IMGUPD_DATABASE_PATH No (string) +Path to the SQLite database. +.El +.\" AUTHORS +.Sh AUTHORS +.Nm +was written by David Demelier <markand@malikania.fr> +.\" SEE ALSO +.Sh SEE ALSO +.Xr imgupd 8
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/imgupd-clean.c Thu Nov 26 19:13:08 2020 +0100 @@ -0,0 +1,64 @@ +/* + * imgupd-clean.c -- main imgupd-clean(8) file + * + * Copyright (c) 2020 David Demelier <markand@malikania.fr> + * + * Permission to use, copy, modify, and/or 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 <limits.h> +#include <stdio.h> +#include <stdlib.h> +#include <stdnoreturn.h> +#include <unistd.h> + +#include "database.h" +#include "util.h" + +static noreturn void +usage(void) +{ + fprintf(stderr, "usage: imgupd-clean [-d database-path]\n"); + exit(1); +} + +int +main(int argc, char **argv) +{ + const char *value; + char path[PATH_MAX] = VARDIR "/imgup/imgup.db"; + int ch; + + /* Seek environment first. */ + if ((value = getenv("IMGUPD_DATABASE_PATH"))) + snprintf(path, sizeof (path), "%s", value); + + while ((ch = getopt(argc, argv, "d:")) != -1) { + switch (ch) { + case 'd': + snprintf(path, sizeof (path), "%s", optarg); + break; + default: + usage(); + break; + } + } + + if (!path[0]) + die("abort: no database specified"); + if (!database_open(path)) + die("abort: could not open database"); + + database_clear(); + database_finish(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/imgupd.8.in Thu Nov 26 19:13:08 2020 +0100 @@ -0,0 +1,207 @@ +.\" +.\" Copyright (c) 2020 David Demelier <markand@malikania.fr> +.\" +.\" Permission to use, copy, modify, and/or 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. +.\" +.Dd 25 November, 2020 +.Dt IMGUPD 8 +.Os +.\" NAME +.Sh NAME +.Nm imgupd +.Nd simple image hosting service +.\" SYNOPSIS +.Sh SYNOPSIS +.Nm +.Op Fl fqv +.Op Fl d Ar database-path +.Op Fl t Ar theme-directory +.\" DESCRIPTION +.Sh DESCRIPTION +The +.Nm +utility is a simple CGI or FastCGI program to host temporary images over a web +interface. It will show most recent uploaded images and let users to create new +one from a web form. +.Pp +It supports: +.Bl -bullet -compat +.It +Listing of recent images, +.It +Submission of new images, +.It +Searching existing images, +.It +Private images (not listed). +.El +.Pp +To store images, +.Nm +uses a SQLite database that must be writable by the CGI/FastCGI owner. See usage +below. +.Pp +Available options: +.Bl -tag -width Ds +.It Fl f +Starts as FastCGI mode, +.Nm +will wait forever for new requests. +.It Fl d Ar database-path +Specify an alternate path for the database. +.It Fl t Ar theme-directory +Specify an alternate directory for the theme. +.It Fl q +Do not log through syslog at all. +.It Fl v +Increase verbosity level. +.El +.\" USAGE +.Sh USAGE +The +.Nm +utility does not use configuration file as it does not need many adjustments, +instead every parameter could be passed by environment variables or options. +.Pp +By default, +.Nm +will try to use +.Pa @VARDIR@/imgup/imgup.db +database. +.\" LOGS +.Sh LOGS +The +.Nm +utility will log information through syslog unless verbosity is disabled. +Except at startup where the tool can write to stderr some information if it +can't continue processing, the tool will never write anything to stdout and +use syslog only. +.Pp +The available verbosity level is defined in the following order: +.Bd -literal -offset Ds +none < warnings (default) < info < debug +.Ed +.Pp +Use +.Fl q +or +.Va IMGUPD_VERBOSITY=0 +if you want to disable syslog completely. +.\" USING WITH FASTCGI +.Sh USING WITH FASTCGI +The recommended way to use +.Nm +is to deploy using FastCGI. You can use the +.Xr kfcgi 8 +helper to spawn the process for you. +.Pp +Example: +.Bd -literal -offset Ds +kfcgi -p /var/www/imgup -- imgupd -f -d imgup.db -t siimple +.Ed +.Pp +Note: kfcgi chroot to the directory given, you must either statically link +imgupd at build time or deploy all required libraries. Also, themes +directory will need to be available in the chroot directory. In the above +example, this will effectively create a database +.Pa /var/www/imgup/imgup.db +and use the theme +.Pa /var/www/imgup/siimple . +.Pp +Then, simply copy the desired theme into the directory. +.Bd -literal -offset Ds +cp -R @SHAREDIR@/imgup/themes/siimple /var/www/imgup +.Ed +.Pp +As an +.Em insecure +alternative, you can chroot to +.Pa / +to avoid static-linking and copying themes, using: +.Bd -literal -offset Ds +kfcgi -p / -- imgupd -f \e + -d /var/www/imgup/imgup.db \e + -t @SHAREDIR@/imgup/themes/siimple +.Ed +.Pp +Both kfcgi invocations will create +.Pa /var/www/run/http.sock +with current user and group. Configure the web server to talk to that socket +and make sure it has appropriate file permissions otherwise see +.Fl u +option in +.Nm kfcgi . +See also the +.Xr kfcgi 8 +manual for more information. +.Pp +Next, configure the web server. +.Pp +Warning: at this moment, +.Nm +requires its own virtual host and can +.Em not +use a url. +.\" Server: nginx +.Ss Server: nginx +The nginx web server requires several parameters to run +.Nm . +.Bd -literal +server { + server_name mypaste.fr; + listen 80; + + location / { + fastcgi_param QUERY_STRING query_string; + fastcgi_param REQUEST_METHOD $request_method; + fastcgi_param CONTENT_TYPE $content_type; + fastcgi_param CONTENT_LENGTH $content_length; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param SCRIPT_NAME $fastcgi_script_name; + fastcgi_param PATH_INFO $document_uri; + fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; + fastcgi_param REQUEST_URI $request_uri; + fastcgi_param DOCUMENT_URI $document_uri; + fastcgi_param DOCUMENT_ROOT $document_root; + fastcgi_param SERVER_PROTOCOL $server_protocol; + fastcgi_param GATEWAY_INTERFACE CGI/1.1; + fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; + fastcgi_param REMOTE_ADDR $remote_addr; + fastcgi_param REMOTE_PORT $remote_port; + fastcgi_param SERVER_ADDR $server_addr; + fastcgi_param SERVER_PORT $server_port; + fastcgi_param SERVER_NAME $server_name; + fastcgi_param HTTPS $https; + fastcgi_pass unix:/var/www/run/httpd.sock; + } +} +.Ed +.\" ENVIRONMENT +.Sh ENVIRONMENT +The following environment variables are detected: +.Bl -tag -width Ds +.It Va IMGUPD_DATABASE_PATH No (string) +Path to the SQLite database. +.It Va IMGUPD_THEME_DIR No (string) +Directory containing the theme. +.It Va IMGUPD_VERBOSITY No (number) +Verbosity level, 0 to disable completely. +.El +.\" AUTHORS +.Sh AUTHORS +.Nm +was written by David Demelier <markand@malikania.fr> +.\" SEE ALSO +.Sh SEE ALSO +.Xr imgup 1 , +.Xr kfcgi 8
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/imgupd.c Thu Nov 26 19:13:08 2020 +0100 @@ -0,0 +1,107 @@ +/* + * imgupd.c -- main imgupd(8) file + * + * Copyright (c) 2020 David Demelier <markand@malikania.fr> + * + * Permission to use, copy, modify, and/or 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 <stdnoreturn.h> +#include <time.h> +#include <unistd.h> + +#include "config.h" +#include "database.h" +#include "http.h" +#include "log.h" +#include "util.h" + +static void +defaults(void) +{ + snprintf(config.databasepath, sizeof (config.databasepath), + "%s", VARDIR "/imgup/imgup.db"); +} + +static void +init(void) +{ + srand(time(NULL)); + log_open(); + + if (!config.databasepath[0]) + die("abort: no database specified\n"); + if (!database_open(config.databasepath)) + die("abort: could not open database\n"); +} + +static void +quit(void) +{ + database_finish(); + log_finish(); +} + +static noreturn void +usage(void) +{ + fprintf(stderr, "usage: imgupd [-fqv] [-d database-path] [-t theme-directory]\n"); + exit(1); +} + +int +main(int argc, char **argv) +{ + const char *value; + int opt; + void (*run)(void) = &(http_cgi_run); + + defaults(); + + /* Seek environment variables before options. */ + if ((value = getenv("IMGUPD_DATABASE_PATH"))) + snprintf(config.databasepath, sizeof (config.databasepath), "%s", value); + if ((value = getenv("IMGUPD_THEME_DIR"))) + snprintf(config.themedir, sizeof (config.themedir), "%s", value); + if ((value = getenv("IMGUPD_VERBOSITY"))) + config.verbosity = atoi(value); + + while ((opt = getopt(argc, argv, "d:ft:qv")) != -1) { + switch (opt) { + case 'd': + snprintf(config.databasepath, sizeof (config.databasepath), "%s", optarg); + break; + case 't': + snprintf(config.themedir, sizeof (config.themedir), "%s", optarg); + break; + case 'f': + run = &(http_fcgi_run); + break; + case 'v': + config.verbosity++; + break; + case 'q': + config.verbosity = 0; + break; + default: + usage(); + break; + } + } + + init(); + run(); + quit(); +}
--- a/log.c Thu Nov 26 18:43:33 2020 +0100 +++ b/log.c Thu Nov 26 19:13:08 2020 +0100 @@ -33,7 +33,7 @@ log_open(void) { if (config.verbosity > 0) - openlog("imgpaster", 0, LOG_USER); + openlog("imgup", 0, LOG_USER); } void
--- a/log.h Thu Nov 26 18:43:33 2020 +0100 +++ b/log.h Thu Nov 26 19:13:08 2020 +0100 @@ -16,8 +16,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifndef IMGPASTER_LOG_H -#define IMGPASTER_LOG_H +#ifndef IMGUP_LOG_H +#define IMGUP_LOG_H #include <stdarg.h> @@ -43,4 +43,4 @@ void log_finish(void); -#endif /* !IMGPASTER_LOG_H */ +#endif /* !IMGUP_LOG_H */
--- a/page-download.h Thu Nov 26 18:43:33 2020 +0100 +++ b/page-download.h Thu Nov 26 19:13:08 2020 +0100 @@ -16,12 +16,12 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifndef IMGPASTER_PAGE_DOWNLOAD_H -#define IMGPASTER_PAGE_DOWNLOAD_H +#ifndef IMGUP_PAGE_DOWNLOAD_H +#define IMGUP_PAGE_DOWNLOAD_H struct kreq; void page_download(struct kreq *); -#endif /* !IMGPASTER_PAGE_DOWNLOAD_H */ +#endif /* !IMGUP_PAGE_DOWNLOAD_H */
--- a/page-image.h Thu Nov 26 18:43:33 2020 +0100 +++ b/page-image.h Thu Nov 26 19:13:08 2020 +0100 @@ -16,12 +16,12 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifndef IMGPASTER_PAGE_IMAGE_H -#define IMGPASTER_PAGE_IMAGE_H +#ifndef IMGUP_PAGE_IMAGE_H +#define IMGUP_PAGE_IMAGE_H struct kreq; void page_image(struct kreq *); -#endif /* !IMGPASTER_PAGE_IMAGE_H */ +#endif /* !IMGUP_PAGE_IMAGE_H */
--- a/page-index.h Thu Nov 26 18:43:33 2020 +0100 +++ b/page-index.h Thu Nov 26 19:13:08 2020 +0100 @@ -16,8 +16,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifndef IMGPASTER_PAGE_INDEX_H -#define IMGPASTER_PAGE_INDEX_H +#ifndef IMGUP_PAGE_INDEX_H +#define IMGUP_PAGE_INDEX_H #include <stddef.h> @@ -30,4 +30,4 @@ void page_index(struct kreq *); -#endif /* !IMGPASTER_PAGE_INDEX_H */ +#endif /* !IMGUP_PAGE_INDEX_H */
--- a/page-new.h Thu Nov 26 18:43:33 2020 +0100 +++ b/page-new.h Thu Nov 26 19:13:08 2020 +0100 @@ -16,12 +16,12 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifndef IMGPASTER_PAGE_NEW_H -#define IMGPASTER_PAGE_NEW_H +#ifndef IMGUP_PAGE_NEW_H +#define IMGUP_PAGE_NEW_H struct kreq; void page_new(struct kreq *); -#endif /* !IMGPASTER_PAGE_NEW_H */ +#endif /* !IMGUP_PAGE_NEW_H */
--- a/page-search.h Thu Nov 26 18:43:33 2020 +0100 +++ b/page-search.h Thu Nov 26 19:13:08 2020 +0100 @@ -16,12 +16,12 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifndef IMGPASTER_PAGE_SEARCH_H -#define IMGPASTER_PAGE_SEARCH_H +#ifndef IMGUP_PAGE_SEARCH_H +#define IMGUP_PAGE_SEARCH_H struct kreq; void page_search(struct kreq *); -#endif /* !IMGPASTER_PAGE_SEARCH_H */ +#endif /* !IMGUP_PAGE_SEARCH_H */
--- a/page-static.h Thu Nov 26 18:43:33 2020 +0100 +++ b/page-static.h Thu Nov 26 19:13:08 2020 +0100 @@ -16,12 +16,12 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifndef IMGPASTER_PAGE_STATIC_H -#define IMGPASTER_PAGE_STATIC_H +#ifndef IMGUP_PAGE_STATIC_H +#define IMGUP_PAGE_STATIC_H struct kreq; void page_static(struct kreq *); -#endif /* !IMGPASTER_PAGE_STATIC_H */ +#endif /* !IMGUP_PAGE_STATIC_H */
--- a/page.h Thu Nov 26 18:43:33 2020 +0100 +++ b/page.h Thu Nov 26 19:13:08 2020 +0100 @@ -16,8 +16,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifndef IMGPASTER_PAGE_H -#define IMGPASTER_PAGE_H +#ifndef IMGUP_PAGE_H +#define IMGUP_PAGE_H #include <sys/types.h> #include <stdarg.h> @@ -27,4 +27,4 @@ void page(struct kreq *, const struct ktemplate *, enum khttp, const char *); -#endif /* !IMGPASTER_PAGE_H */ +#endif /* !IMGUP_PAGE_H */
--- a/themes/siimple/fragments/header.html Thu Nov 26 18:43:33 2020 +0100 +++ b/themes/siimple/fragments/header.html Thu Nov 26 19:13:08 2020 +0100 @@ -7,7 +7,7 @@ <body> <div class="siimple-navbar"> - <a class="siimple-navbar-title" href="/">imgpaster</a> + <a class="siimple-navbar-title" href="/">imgup</a> <div class="siimple-navbar-subtitle">simple image hosting service</div> <div class="siimple--float-right"> <a class="siimple-navbar-item" href="/new">Create</a>
--- a/util.h Thu Nov 26 18:43:33 2020 +0100 +++ b/util.h Thu Nov 26 19:13:08 2020 +0100 @@ -16,8 +16,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifndef IMGPASTER_UTIL_H -#define IMGPASTER_UTIL_H +#ifndef IMGUP_UTIL_H +#define IMGUP_UTIL_H #include <stddef.h> #include <stdnoreturn.h> @@ -51,4 +51,4 @@ const char * ttl(time_t, long long int); -#endif /* !IMGPASTER_UTIL_H */ +#endif /* !IMGUP_UTIL_H */