add architecture to submissions

This commit is contained in:
Cadey Ratio 2018-04-25 02:21:14 +00:00
parent fce3a5ef2f
commit 7266ba9698
3 changed files with 19 additions and 8 deletions

View File

@ -7,6 +7,7 @@ sqlite3 db register.db
# clients will submit at 9 AM their time.
db eval {CREATE TABLE hits
( ip_address_hash TEXT NOT NULL
, arch TEXT NOT NULL
, date TEXT NOT NULL
)}
@ -16,6 +17,7 @@ db eval {CREATE UNIQUE INDEX hits_unique_daily ON hits(ip_address_hash, date)}
# table, but databases have indexes for a reason.
db eval {CREATE TABLE package_installs
( package_name TEXT NOT NULL
, arch TEXT NOT NULL
, date TEXT NOT NULL
)}

View File

@ -22,10 +22,16 @@ proc wapp-default {} {
}
proc wapp-page-submit {} {
wapp-allow-xorigin-params
set systemTime [clock seconds]
set iphash [md5::md5 [wapp-param REMOTE_ADDR]]
set method [wapp-param REQUEST_METHOD]
set arch [wapp-param arch]
set body [wapp-param CONTENT "<INVALID>"]
wapp-set-param TODAY $systemTime
wapp-set-param IPHASH $iphash
if {[string match {POST} $method] == 0} {
# bad method
@ -38,11 +44,6 @@ proc wapp-page-submit {} {
return
}
wapp-set-param TODAY $systemTime
wapp-set-param IPHASH $iphash
set body [wapp-param CONTENT "<INVALID>"]
if {[string match {<INVALID>} $body] == 1} {
# bad request
wapp-reply-code 400
@ -55,11 +56,13 @@ proc wapp-page-submit {} {
}
db eval {BEGIN}
db eval {INSERT INTO hits(ip_address_hash, date) VALUES ($iphash, date($systemTime, 'unixepoch'))}
db eval {INSERT INTO hits(ip_address_hash, arch, date) VALUES ($iphash, $arch, date($systemTime, 'unixepoch'))}
set pkgs [split $body "\n"]
foreach pkg $pkgs {
db eval {INSERT INTO package_installs(package_name, date) VALUES ($pkg, date($systemTime, 'unixepoch'))}
if {[string length $pkg] != 0} {
db eval {INSERT INTO package_installs(package_name, arch, date) VALUES ($pkg, $arch, date($systemTime, 'unixepoch'))}
}
}
db eval {COMMIT}

6
submit.sh Executable file
View File

@ -0,0 +1,6 @@
#!/bin/sh
SUBMISSION_URL=http://127.0.0.1:8080/submit
arch="$(uname -m)"
cat /etc/apk/world | grep -v '><' | grep -v '@' | curl --data-binary @- "$SUBMISSION_URL"'?arch='"$arch"