summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSavetheinternet <savetheinternet@tinyboard.org>2011-05-20 22:44:35 +1000
committerSavetheinternet <savetheinternet@tinyboard.org>2011-05-20 22:44:35 +1000
commit9654c9d9e738d04e83dcb0ef43cbb7546e51e7e5 (patch)
tree15bfddff0060f834d0a2b3d21372aa9fadc23274
parent65c5e91af235fbc8d348c0d15998fd797944e952 (diff)
experimental SCP writing (for using Tinyboard over multiple servers)
-rw-r--r--inc/config.php3
-rw-r--r--inc/functions.php16
2 files changed, 18 insertions, 1 deletions
diff --git a/inc/config.php b/inc/config.php
index 0e2205cc..800996c5 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -221,6 +221,9 @@
// Display the aspect ratio in a post's file info
$config['show_ratio'] = true;
+ // Directory where temporary files will be created. Not really used much yet except for some experimental stuff.
+ $config['tmp'] = '/tmp';
+
// The root directory, including the trailing slash, for Tinyboard.
// examples: '/', 'http://boards.chan.org/', '/chan/'
$config['root'] = (str_replace('\\', '/', dirname($_SERVER['REQUEST_URI'])) == '/' ? '/' : str_replace('\\', '/', dirname($_SERVER['REQUEST_URI'])) . '/');
diff --git a/inc/functions.php b/inc/functions.php
index 65705766..ec6166ef 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -212,9 +212,23 @@
}
function file_write($path, $data) {
+ global $config;
+ if(preg_match('/^scp:\/\/(.+)$/', $path, $m)) {
+ // Experimental: secure copy...
+ $file = tempnam($config['tmp'], 'tinyboard-scp');
+ // Write to temp file
+ file_write($file, $data);
+ // Call `scp` (yes, this is horrible)
+ $command = 'scp ' . escapeshellarg($file) . ' ' . escapeshellarg($m[1]);
+ system($command);
+ // Delete temporary file
+ unlink($file);
+ exit;
+ }
+
if(!$fp = fopen($path, 'c'))
error('Unable to open file for writing: ' . $path);
-
+
// File locking
if(!flock($fp, LOCK_EX)) {
error('Unable to lock file: ' . $path);