#!/usr/local/bin/tclsh8.6 package require sqlite3 set dbfile ./paste.db set maxpaste 32768 set maxfile 10485760 set url http://paste.wooledge.org proc die {msg} { puts $msg exit 1 } after 30000 die "timeout" fconfigure stdin -translation binary -blocking 0 fconfigure stdout -translation binary if {[file exists $dbfile] && [file size $dbfile] > $maxfile} { die "too many pastes already" } set value "" while 1 { after 250 set chunk [read stdin] if {[string length $chunk] == 0} break append value $chunk if {[string length $value] > $maxpaste} break } if {[string length $value] == 0} { die "0 bytes received, no paste created" } if {[string length $value] > $maxpaste} { die "value too large" } if {[file exists $dbfile]} { sqlite3 db $dbfile } else { sqlite3 db $dbfile db eval {create table paste(ip text, expire int, value blob)} } set ip $env(TCPREMOTEIP) set expire [expr {[clock seconds] + 7*86400}] ;# 1 week db eval {insert into paste(ip, expire, value) values (:ip, :expire, :value)} db eval {select last_insert_rowid() as last} v {} puts $url/$v(last)