diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/api.c | 2 | ||||
-rw-r--r-- | src/css.css | 13 | ||||
-rw-r--r-- | src/example.conf | 7 | ||||
-rw-r--r-- | src/hp.html | 12 | ||||
-rw-r--r-- | src/i18n.h | 5 | ||||
-rw-r--r-- | src/log.c | 7 | ||||
-rw-r--r-- | src/main.c | 5 | ||||
-rwxr-xr-x | src/openrc.sh | 46 | ||||
-rw-r--r-- | src/structs.c | 2 |
9 files changed, 84 insertions, 15 deletions
@@ -154,11 +154,11 @@ enum sc_return sc_query_google (const char * s, /* breaking change: changed retu char * imageclass = NULL; htmlDocPtr xmldoc = NULL; char * txtdoc = NULL; + int qwasgiven = 0; if (!s || !c) { rs = SC_BADCALL; goto rc; } - int qwasgiven = 0; int sl = strlen(s); if (!q) q = sc_query_init(); diff --git a/src/css.css b/src/css.css index 0293e79..dc78c9f 100644 --- a/src/css.css +++ b/src/css.css @@ -38,7 +38,7 @@ } } -input, textarea { +input, textarea, button { background: var(--bgc2); color: var(--fgc1); } @@ -79,7 +79,7 @@ code { color: var(--fgcodec); background-color: var(--bgcodec); } -input[type=password], input[type=text], input[type=submit], input[type=button] { +input[type=text], button { height: 1cm; font-size: large; } @@ -95,8 +95,9 @@ input[type=password], input[type=text], input[type=submit], input[type=button] { } input[name=q] { flex-grow: 4; + width: 100%; } -input[type=submit] { +button { flex-basis: 12.5%; } .SC_LOG_ERROR { @@ -127,3 +128,9 @@ input[type=submit] { .result img { height: 10em; } +button::after { + content: attr(value); +} +button span { /* rationale: links browser does not support CSS and emojis, therefore it'll show */ + display: none; /* basic default text instead of emojis. */ +} /* if browser does not support ::after, content or attr, but supports other CSS, button is blank */ diff --git a/src/example.conf b/src/example.conf new file mode 100644 index 0000000..fb406db --- /dev/null +++ b/src/example.conf @@ -0,0 +1,7 @@ +# Example config for sear.c. +# Config is read by the service manager, like systemd or openrc, sear.c does not read files. +# All configuration is passed to sear.c process via environment variables. +SC_PORT=7327 +SC_LOGLEVEL=SC_LOG_ERROR,SC_LOG_WARNING,SC_LOG_INFO,SC_LOG_DEBUG +# Enable below option and set to another search provider to fallback to when upstream sends captchas. +# SC_FALLBACK=http://sear.c.fallback:7327/? diff --git a/src/hp.html b/src/hp.html index dcde692..050c8dd 100644 --- a/src/hp.html +++ b/src/hp.html @@ -7,7 +7,7 @@ <title> %s :: sear.c </title> - <meta name=viewport content="width=device-width, initial-scale=1.0"> + <meta name=viewport content="width=device-width, initial-scale=1"> <link rel=stylesheet href=/css.css /> <link rel="shortcut icon" href=data:image/x-icon;, type=image/x-icon> <!-- prevents favicon lookups --> <link rel=icon href="data:;base64,iVBORw0KGgo="> @@ -15,10 +15,10 @@ </head> <body> <form class=container action=.> - <input accesskey=s type=text name=q value="%s" placeholder="sear.c ..." /> - <input type=submit value=🔍 /> <!-- magnifying glass emoji --> - <input accesskey=f type=submit name=f value=Ʊ /> <!-- horseshoe unicode character --> - <input accesskey=i type=submit name=i value=🖼 /> <!-- framed picture emoji - img search --> + <input accesskey=s type=text name=q value="%s" placeholder="sear.c ..." size=128/> + <button type=submit value=🔍 ><span>=></span></button> + <button accesskey=f type=submit name=f value=Ʊ ><span>1.</span></button> + <button accesskey=i type=submit name=i value=🖼 ><span>[^]</span></button> <!-- <input type=submit name=v value=🎬/> --> <!-- that thing they use in movies - vid search N/I --> %s </form> @@ -29,7 +29,7 @@ <hr> <h4 align=center> <a href=//git.sijanec.eu/sijanec/sear.c >sear.c</a> - <!-- the following is replaced by git or gentoo version --> <!--ver--> + <!-- the following is replaced by git or ebuild version --> <!--ver--> </h4> </body> </html> @@ -29,6 +29,9 @@ "katerega naj so ob takih napakah preusmerjena iskanja, dokler niso le-ta spet omogočena." #define SC_I18N_LOGS "dnevniški zapisi" #define SC_I18N_LOGS_ERROR "napaka pri branju dnevnikov" -#define SC_I18N_LOGS_NOT_ENABLED "Zbiranje dnevniških zapisov v delovni pomnilnik ni omogočeno. <code>sear.c</code> prevedite z <code>make -e CC=\"cc -DSC_LOGMEM\"</code>; z nastavitvijo zastavice <code>SC_LOGMEM</code> omogočite pregled dnevniških zapisov znotraj aplikacije. Vselej pa se vsi dnevniški zapisi pišejo tudi na standardni izhod, kar se v primeru uporabe <code>sear.c</code> kot <code>systemd</code> storitve shranjuje v sistemske dnevnike." +#define SC_I18N_LOGS_NOT_ENABLED "Zbiranje dnevniških zapisov v delovni pomnilnik ni omogočeno. <code>sear.c</code> prevedite z <code>CFLAGS=-DSC_LOGMEM make</code>; z nastavitvijo zastavice <code>SC_LOGMEM</code> omogočite pregled dnevniških zapisov znotraj aplikacije. Vselej pa se vsi dnevniški zapisi pišejo tudi na standardni izhod, kar se v primeru uporabe <code>sear.c</code> kot <code>systemd</code> storitve shranjuje v sistemske dnevnike." #define SC_I18N_GIT_URL "//git.sijanec.eu/sijanec/sear.c" #define SC_I18N_HORSESHOE_RESPONSE "Če vidite to besedilo, vaš brskalnik ne podpira preusmeritev. V tem primeru ne uporabljajte argumenta f." +#define SC_I18N_SEARCH "išči" +#define SC_I18N_HORSESHOE "hitro" +#define SC_I18N_IMAGES "slike" @@ -1,3 +1,6 @@ +#ifndef SC_LOGLEVEL +#define SC_LOGLEVEL "SC_LOG_ERROR SC_LOG_WARNING SC_LOG_INFO SC_LOG_DEBUG" +#endif const char * sc_log_str (SC_OPT_TYPE t) { switch (t & SC_LOG_MASK) { case SC_LOG_ERROR: @@ -24,9 +27,11 @@ struct sc_logentry * sc_logentry_init () { return l; } #endif -int sc_push_log (unsigned char t, struct sc_cache * c, const char * ca, char * f, size_t l, unsigned short int isf, char * m, ...) { +int sc_push_log (SC_OPT_TYPE t, struct sc_cache * c, const char * ca, char * f, size_t l, unsigned short int isf, char * m, ...) { #define SC_PLL c->logentries[c->logentries_length-1] char * compiled_message = NULL; + if (!strstr(getenv("SC_LOGLEVEL") ? getenv("SC_LOGLEVEL") : SC_LOGLEVEL, sc_log_str(t))) + return 0; #ifdef SC_LOGMEM if (!c) return -1; @@ -86,7 +86,7 @@ void sc_signalhander (int s) { int main (int argc, char ** argv) { int rs = 0; struct sc_cache * c = sc_cache_init(); - struct MHD_Daemon * d; + struct MHD_Daemon * d = NULL; if (!c) { rs = 1; goto rc; @@ -103,8 +103,9 @@ int main (int argc, char ** argv) { fprintf(stderr, "cleaning up!\n"); fflush(stderr); rc: + if (d) + MHD_stop_daemon(d); /* stop the daemon and then free, threads might still be run */ xmlCleanupParser(); - MHD_stop_daemon(d); /* stop the daemon first and the free, threads might still be running */ sc_cache_free(c); return rs; } diff --git a/src/openrc.sh b/src/openrc.sh new file mode 100755 index 0000000..192c03e --- /dev/null +++ b/src/openrc.sh @@ -0,0 +1,46 @@ +#!/sbin/openrc-run +depend() { + need net +} +# poor man's DynamicUser+TemporaryFileSystem+BindReadOnlyPaths implementation in OpenRC +command=sear.c +command_args="" +chroot=/var/run/sear.c +command_background=true +command_user="searc:searc" +pidfile=/var/run/sear.c/pid +# files read by sear.c as observed on 2022-04-17 on i386 debian: see misc/files.txt +mount_chroot() { + [ -d $1 ] && mkdir -p /var/run/sear.c$1 + [ -f $1 ] && mkdir -p /var/run/sear.c`echo $1 | rev | cut -d/ -f 2- | rev` && touch /var/run/sear.c$1 + [ -e $1 ] && mount -o nosuid,ro --bind $1 /var/run/sear.c$1 +} +start_pre() { + [ -f /etc/sear.c ] && . /etc/sear.c + export SC_PORT SC_FALLBACK SC_LOGLEVEL + checkpath --directory-truncate --directory --mode 0755 --owner root:root /var/run/sear.c + pidfile=/pid # logger runs without chroot as searc user in order to show searc instead of root in syslog. + which logger 2>&1 > /dev/null \ + && start_stop_daemon_args="--stderr-logger-before-chroot \"su searc --shell `which logger`\" --stdout-logger-before-chroot \"su searc --shell `which logger`\"" + mount_chroot /lib # a question for anyone reading this: we have now two processes on the system, one chrooted that runs sear.c and one outside of chroot that runs + mount_chroot /lib64 # logger. could the chrooted process somehow get access to the outside of the chroot by somehow communicating with his logger process? note that + mount_chroot /usr/lib # procfs is not mounted. Could it do that if procfs was to be mounted? + mount_chroot /usr/lib64 + mount_chroot /usr/bin/sear.c + mount_chroot /etc/gai.conf + mount_chroot /etc/host.conf + mount_chroot /etc/hosts + mount_chroot /etc/localtime + mount_chroot /etc/nsswitch.conf + mount_chroot /etc/resolv.conf + mount_chroot /etc/ld.so.conf + mount_chroot /etc/ld.so.conf.d + mount_chroot /etc/ld.so.cache +} +stop_post() { + nodelete=0 + for dir in `grep run/sear.c /proc/mounts | cut -d' ' -f2`; do # /var/run is usually symlink to /run, so we only grep for run/sear.c + umount $dir || nodelete=1 + done + [ $nodelete -eq 0 ] && rm -rf /var/run/sear.c +} diff --git a/src/structs.c b/src/structs.c index 650eb88..6deea3e 100644 --- a/src/structs.c +++ b/src/structs.c @@ -50,7 +50,7 @@ struct sc_cache { pthread_rwlock_t * logentries_lock; #endif }; -int sc_push_log (unsigned char t, struct sc_cache * c, const char * ca, char * f, size_t l, unsigned short int isf, char * m, ...); +int sc_push_log (SC_OPT_TYPE t, struct sc_cache * c, const char * ca, char * f, size_t l, unsigned short int isf, char * m, ...); struct sc_result { struct sc_query * query; /* nofree - free from sc_cache */ char * url; /* yesfree - url of referer page when image searching */ |