commit c21844b749afd8752405fc7b355d7eccfcb69657
parent 81bdbf7bbc2df3163eb7ec33764be98c801e52b4
Author: Charlie Root <root@riga.magicfreedom.com>
Date: Mon, 6 Feb 2023 23:11:44 +0400
first commit
Diffstat:
10 files changed, 350 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
@@ -1,3 +1,13 @@
# dmesgdb
-OpenBSD dmesg collection
-\ No newline at end of file
+OpenBSD dmesg collection
+
+## Install
+```
+cd /var/www
+git clone https://git.openbsd.org.ru/vasyahacker/dmesgdb.git
+echo 'include "/var/www/dmesgdb/etc/httpd.conf"' >> /etc/httpd.conf
+rcctl enable slowcgi httpd
+rcctl set slowcgi flags -p /var/www/dmesgdb
+rcctl start slowcgi httpd
+```
diff --git a/bin/need.txt b/bin/need.txt
@@ -0,0 +1,16 @@
+cat
+date
+dd
+expr
+grep
+ln
+ls
+md5
+mkdir
+rm
+sed
+sh
+sort
+stty
+uniq
+wc
+\ No newline at end of file
diff --git a/etc/httpd.conf b/etc/httpd.conf
@@ -0,0 +1,22 @@
+server "dmesg.devel" {
+ listen on 10.7.0.1 port 80
+ root "/dmesgdb/var/www"
+ log syslog
+
+ location "/list/*" {
+ directory auto index
+ }
+
+ location "/beautylist" {
+ fastcgi strip 1
+ }
+
+ location "/upload" {
+ fastcgi strip 1
+ }
+
+ location "/" {
+ directory index upload
+ }
+}
+
diff --git a/usr/lib/need.txt b/usr/lib/need.txt
@@ -0,0 +1,3 @@
+libc.so.96.2
+libutil.so.16.0
+libz.so.7.0
+\ No newline at end of file
diff --git a/usr/libexec/need.txt b/usr/libexec/need.txt
@@ -0,0 +1 @@
+ld.so
+\ No newline at end of file
diff --git a/var/common.sh b/var/common.sh
@@ -0,0 +1,25 @@
+
+MAX_DMESG_SIZE=262144
+
+DB=/var/db
+
+export PATH=/bin
+
+fail() {
+# echo -en "Status: 500 Internal Server Error\r\n"
+ echo -en "Content-type: text/html\r\n\r\n"
+ echo "$1"
+ exit 1
+}
+
+str_purifier() {
+ sed -e 's/[^A-Za-z0-9\_\.\+\%\-]*//g' -e 's/\+/\\ /g' -e 's/%2B/+/g' -e 's/%3A/:/g'
+}
+
+get_param() {
+ _name="$1"
+ _value="$(echo "$REQUEST_URI" | sed -n "s/^.*$_name=\([^&]*\).*\$/\1/p" | str_purifier)"
+ eval $_name="$_value"
+ [ -z "$(eval "echo -ne \$$_name")" ] && eval $_name="Unknow"
+}
+
diff --git a/var/tpl/_footer.html b/var/tpl/_footer.html
@@ -0,0 +1,2 @@
+
+</body></html>
diff --git a/var/tpl/_header.html b/var/tpl/_header.html
@@ -0,0 +1,84 @@
+<!DOCTYPE html>
+<html><head>
+ <meta charset="utf-8">
+ <title>OpenBSD dmesg database</title>
+ <style type="text/css"><!--
+ input[type="text"] {
+ border: 1px solid #cfcece;
+ padding: 7px;
+ border-radius: 3px;
+ }
+
+ body {
+ background-color: white;
+ color: black;
+ font-family: Helvetica, sans-serif;
+ padding: 20px;
+ line-height: 1.5em;
+ font-size: 17px;
+ }
+
+span.Good:after,
+span.Bad:after,
+span.Middle:after {
+ content: '';
+ width: 15px;
+ height: 15px;
+ display: inline-block;
+ border-radius: 50%;
+ vertical-align: middle;
+ margin: 0 4px 0 0;
+}
+
+ span.Good:after {
+ background: rgb(10 177 28);
+ }
+
+ span.Bad:after {
+ background: rgb(237 0 0);
+ }
+
+ span.Middle:after {
+ background: rgb(255 206 0);
+ }
+ ul {
+ list-style: none;
+ padding: 0 0 0 1em;
+ }
+ span.Good,
+ span.Bad,
+ span.Middle {
+ font-size: 0;
+ display: inline-block;
+ vertical-align: middle;
+ }
+ span.Good + span,
+ span.Bad + span,
+ span.Middle + span {
+ display: none;
+ }
+ a.dmesg-link:after {
+ content: '';
+ display: block;
+ }
+ span.notconf {
+ margin-left: 24px;
+ }
+ a.dmesg-link ~ * {
+ font-size: 14px;
+ color: #6f6f6f;
+ }
+ span.date:before {
+ content: '';
+ color: #c8c3c3;
+ margin: 0 4px 0 10px;
+ background-image: url("data:image/svg+xml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UgNC41LTIgNC41LTQuNS0yLTQuNS00LjUtNC41djB6Ij48L3BhdGg+Cjwvc3ZnPg==");
+ display: inline-block;
+ width: 14px;
+ height: 14px;
+ background-size: contain;
+ vertical-align: text-bottom;
+ }
+ --></style>
+</head><body>
+ <h1>OpenBSD dmesg collection</h1>
diff --git a/var/www/beautylist b/var/www/beautylist
@@ -0,0 +1,50 @@
+#!/bin/sh
+
+. /var/common.sh
+
+LIST=""
+vendors=""
+_SOURCE=$DB/*
+
+get_param search
+
+[ "$search" != "Unknow" ] && {
+ _SOURCE="$(grep -i -m1 -R -l "$search" $DB | sed -E -n 's/^(.*)\/(dmesg|state|vendor|date)$/\1/p' | sort | uniq)"
+ [ -z "$_SOURCE" ] && LIST="<h2>Not found</h2>" || LIST="<h2>Search result for '$search':</h2>"
+} || search=""
+
+# Assoc array challange accepted!
+for _d in $_SOURCE
+do
+ _vendor="$(<$_d/vendor)"
+ _model="$(<$_d/model)"
+ _state="$(<$_d/state)"
+ _date="$(<$_d/date)"
+ _notconf="$(<$_d/notconf)"
+ _md5="$(<$_d/md5)"
+ _dmesg_link="/list/$_vendor-$_model[$_state]-$_md5.txt"
+ _device_html="
+ <li>
+ <a class='dmesg-link' href='$_dmesg_link'>
+ <span class='$_state' title='$_state'>[$_state]</span>
+ $_model</a>
+ <span class='notconf'>Not configured: </span><span class='notconf-val'>$_notconf</span><span class='date'>$_date</span>
+ </li>"
+ vendors="${vendors}\n${_vendor}"
+ eval "vendor_$_vendor=\"\$vendor_$_vendor $_device_html\""
+done
+
+vendors="$(echo "$vendors" | sort | uniq)"
+for _v in $vendors
+do
+ LIST="$LIST\n<div><h3>$_v</h3>\n<ul>$(eval "echo \$vendor_$_v")</ul></div>"
+done
+
+
+# Challange complete
+echo -en "Status: 200 OK\r\n"
+echo -en "Content-type: text/html\r\n\r\n"
+echo "$(<../tpl/_header.html)"
+echo "<form method='GET'><input type='text' name='search' value='$search' placeholder='search'></form>"
+echo "$LIST"
+echo "$(<../tpl/_footer.html)"
diff --git a/var/www/upload b/var/www/upload
@@ -0,0 +1,133 @@
+#!/bin/sh
+. /var/common.sh
+
+LIST=/var/www/list
+
+[ -e "$DB" ] || mkdir -p "$DB"
+
+gen_user_token() {
+ get_param token
+ [ "$token" != "Unknow" ] && [ -e "$DB/$token" ] && {
+ echo -en "$token"
+ true
+ } || {
+ echo -en "$REMOTE_ADDR $REMOTE_PORT $HTTP_USER_AGENT $(date +%s) ${RANDOM}" | md5
+ }
+}
+
+save_dmesg() {
+ _to_file=$1
+ _length=$(expr $2 - 7)
+ _ret=0
+ stty -icanon -echo
+ _bsd_check="$(dd bs=1 count=7)"
+ [ "$_bsd_check" == "OpenBSD" ] && {
+ echo -en "$_bsd_check" > $_to_file
+ dd bs=1 count=$_length >> $_to_file #2>/dev/null
+ #if !OpenBSD or dd return error than _ret=1
+ } || _ret=1
+ stty icanon echo
+ return $_ret
+}
+
+check_dmesg_file() {
+ #_file="$1"
+ #_type="$(file -b $_file)"
+ #[ "$_type" = "ASCII text" ] return 0
+ # it was bad idea because "file: unknown user _file"
+ return 0
+}
+
+#get_params() {
+# _vendor="$(echo "$REQUEST_URI" | sed -n 's/^.*vendor=\([^&]*\).*$/\1/p' | str_purifier)"
+#
+# _model="$(echo "$REQUEST_URI" | sed -n 's/^.*model=\([^&]*\).*$/\1/p' | str_purifier)"
+#
+# _state="$(echo "$REQUEST_URI" | sed -n 's/^.*state=\([^&]*\).*$/\1/p' | str_purifier)"
+#
+# [ -z "$_vendor" ] && _vendor="Unknow"
+# [ -z "$_model" ] && _model="Unknow"
+# [ -z "$_state" ] && _state="Unknow"
+# echo -en "$_vendor" > "$HD/vendor"
+# echo -en "$_model" > "$HD/model"
+# echo -en "$_state" > "$HD/state"
+# mkdir -p "$LIST/$_vendor"
+# echo "$_vendor-_-$_model-[$_state]"
+#}
+
+_RESULT=""
+
+[ "$REQUEST_METHOD" = "POST" -a "$CONTENT_LENGTH" -gt 0 ] && {
+
+ [ "$CONTENT_LENGTH" -gt $MAX_DMESG_SIZE ] && fail "too much data size"
+
+ TOKEN="$(gen_user_token)"
+ HD="$DB/$TOKEN"
+ DFILE="$HD/dmesg"
+ mkdir -p "$HD"
+
+ [ "$token" != "Unknow" ] && {
+ _v="$(<$HD/vendor)"
+ _m="$(<$HD/model)"
+ _s="$(<$HD/state)"
+ _md5="$(<$HD/md5)"
+ _OLD_FLN="$_v-$_m[$_s]-${_md5}.txt"
+ _OLD_LN="$_m[$_s]-${_md5}.txt"
+ rm -f "$LIST/$_OLD_FLN"
+ rm -f "$LIST/#$vendor/$_OLD_LN"
+ }
+
+ #LINK_NAME="$(gen_names)"
+ get_param vendor
+ get_param model
+ get_param state
+ echo -en "$vendor" > "$HD/vendor"
+ echo -en "$model" > "$HD/model"
+ echo -en "$state" > "$HD/state"
+ date "+%Y.%m.%d %H:%M" > "$HD/date"
+
+ save_dmesg "$DFILE" "$CONTENT_LENGTH" || {
+ rm -rf "$HD"
+ fail "save dmesg error"
+ }
+
+ check_dmesg_file "$DFILE" || {
+ rm -rf "$HD"
+ fail "Bad dmesg type"
+ }
+
+ grep "not configured" "$DFILE" | wc -l | sed 's/ //g' > "$HD/notconf"
+
+ MD5="$(md5 -q "$DFILE")"
+ echo -en "$MD5" > "$HD/md5"
+
+ FULL_LINK_NAME="$vendor-$model[$state]-${MD5}.txt"
+ LINK_NAME="$model[$state]-${MD5}.txt"
+
+ mkdir -p "$LIST/#$vendor"
+ ln -s "../../db/$TOKEN/dmesg" "$LIST/$FULL_LINK_NAME"
+ ln -s "../../../db/$TOKEN/dmesg" "$LIST/#$vendor/$LINK_NAME"
+
+ _RESULT="
+ Thank you, your dmesg was uploaded!
+ Link: http://$HTTP_HOST/list/$FULL_LINK_NAME
+ Edit URI: /upload?token=$TOKEN&vendor=$vendor&model=$model&state=$state
+"
+}
+
+echo -en "Status: 200 OK\r\n"
+echo -en "Content-type: text/html\r\n\r\n"
+[ ! -z "$_RESULT" ] && {
+ echo "$_RESULT"
+ exit 0
+}
+echo "<HTML><HEAD><title>OpenBSD dmesg database</title></HEAD>\n";
+echo "<body>";
+echo '
+<h1>OpenBSD dmesg collection</h1>
+<p><a href="/list">List of all files</a></p>
+<p>You can send your dmesg from command line:</p>
+<p><i>curl --data "$(dmesg)" "http://'"$HTTP_HOST"'/upload?<b>vendor=Apple&model=MacBook_Pro_2017_13&state=Bad</b>"</i></p>
+<p><a href="/beautylist">Beautiful list</a></p>
+'
+echo "</body></HTML>\n";