diff options
| author | 2026-08-01 19:50:10 -0600 | |
|---|---|---|
| committer | 2026-08-01 19:50:10 -0600 | |
| commit | ff553e872b973ac8af558e553833c987f42f2518 (patch) | |
| tree | f5586c0a926768429ae6c5d53eb9ab2a3df8308f | |
| parent | update .config.php.example (diff) | |
| download | hostfiles-ff553e872b973ac8af558e553833c987f42f2518.tar.gz hostfiles-ff553e872b973ac8af558e553833c987f42f2518.tar.bz2 hostfiles-ff553e872b973ac8af558e553833c987f42f2518.zip | |
add uploads db
| -rw-r--r-- | .config.php.example | 3 | ||||
| -rw-r--r-- | startup.sql | 15 | ||||
| -rw-r--r-- | upload.php | 22 |
3 files changed, 40 insertions, 0 deletions
diff --git a/.config.php.example b/.config.php.example index d016e75..7f2e5b3 100644 --- a/.config.php.example +++ b/.config.php.example @@ -10,3 +10,6 @@ define('KNOWN_CIDRS', [ '127.0.0.0/8' => 'wat⁉️ ❗❗❗', '::1' => 'wat⁉️ ❗❗❗', ]); + +$db = new SQLite3(UPLOAD_DIR . '/.uploads.db'); +$db->exec(file_get_contents(__DIR__ . '/startup.sql')); diff --git a/startup.sql b/startup.sql new file mode 100644 index 0000000..3e570fd --- /dev/null +++ b/startup.sql @@ -0,0 +1,15 @@ +PRAGMA journal_mode = WAL; +PRAGMA foreign_keys = ON; +PRAGMA synchronous = NORMAL; +PRAGMA mmap_size = 134217728; +PRAGMA journal_size_limit = 67108864; + +CREATE TABLE IF NOT EXISTS uploads ( + id INTEGER PRIMARY KEY, + ip TEXT, + time INTEGER, + digest BLOB, + content_type TEXT, + filename TEXT, + realname TEXT +); @@ -20,6 +20,8 @@ if ($c_t == 'application/x-www-form-urlencoded') { echo "Content-Type: application/x-www-form-urlencoded is not supported.\n"; send_notification("[hostfil.es] " . get_addr() . " tried to $_SERVER[REQUEST_METHOD] $c_t"); exit; + + } elseif ($c_t == 'multipart/form-data' || 0 === strpos($c_t, 'multipart/form-data;')) { $FILES = remap_files(); if (!isset($FILES['file'])) { @@ -47,9 +49,12 @@ if ($c_t == 'application/x-www-form-urlencoded') { if (!file_exists($filepath)) { symlink($real_filepath, $filepath); } + add_db($hash_str, $filename, $file['full_path'], $file['type']); echo UPLOAD_URL . $filename . "\n"; send_notification("[hostfil.es] " . get_addr() . " uploaded $file[full_path] $file[type] -> https://g.hostfil.es/$filename"); } + + } else { $in_fh = fopen('php://input', 'r'); $tmp_path = tempnam(UPLOAD_DIR, '.up-'); @@ -90,11 +95,28 @@ if ($c_t == 'application/x-www-form-urlencoded') { if (!file_exists($filepath)) { symlink($real_filepath, $filepath); } + add_db($hash_str, $filename, $_SERVER['PATH_INFO'], $c_t); echo UPLOAD_URL . $filename . "\n"; send_notification("[hostfil.es] " . get_addr() . " uploaded $_SERVER[PATH_INFO] $c_t -> https://g.hostfil.es/$filename"); } + + + +function add_db($digest, $filename, $realname, $content_type) { + global $db; + $s = $db->prepare('INSERT INTO uploads (time,digest,ip,filename,realname,content_type) VALUES (UNIXEPOCH(),UNHEX(:digest),:ip,:filename,:realname,:ct)'); + $s->bindValue(':digest', $digest); + $s->bindValue(':ip', get_addr()); + $s->bindValue(':filename', $filename); + $s->bindValue(':realname', $realname); + $s->bindValue(':ct', $content_type); + if (!$s->execute()) { + die_error('sqlite failed'); + } +} + function send_notification($note) { $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); socket_connect($sock, gethostbyname(NOTIFICATION_ADDRESS), NOTIFICATION_PORT); |
