From 19723c932cad1d7f29db90316d63bcb87564d876 Mon Sep 17 00:00:00 2001
From: Joe Robinson
Date: Fri, 11 Dec 2015 16:30:41 +0000
Subject: Add option to send notification to a URL when a file is uploaded
---
config.php.example | 6 ++++++
upload_file.php | 18 ++++++++++++++++++
2 files changed, 24 insertions(+)
diff --git a/config.php.example b/config.php.example
index e45ff35..43303a2 100644
--- a/config.php.example
+++ b/config.php.example
@@ -18,4 +18,10 @@
# An array of filenames to omit from the index
$indexignore = array(".htaccess", "config.php", "index.php", "upload_file.php", "upload.html");
+
+ # An URL to send a POST to when an upload is successful
+ $nofificationurl = "http://tghost.co.uk/blaupload"
+
+ #The IRC channel notified by uploads when using the notification URL
+ $notificationchannel = "theblueroom"
?>
diff --git a/upload_file.php b/upload_file.php
index 890078a..3f35524 100644
--- a/upload_file.php
+++ b/upload_file.php
@@ -51,8 +51,26 @@ if ($_FILES["file"]["error"] > 0) {
$fileurl = "$url" . $_FILES["file"]["name"];
echo "URL: $fileurl
";
echo "Size: " . size_readable($_FILES["file"]["size"], null, "bi");
+ if (isset($notificationurl)) {
+ send_upload_notification($fileurl);
+ }
}
}
+
+function send_upload_notification($fileurl) {
+ $data = array('url' => $fileurl, 'channel' => $notificationchannel);
+
+ $options = array(
+ 'http' => array(
+ 'header' => "Content-type: application/x-www-form-urlencoded\r\n" .
+ "X-Blaears-Event: blaupload",
+ 'method' => 'POST',
+ 'content' => http_build_query($data),
+ ),
+ );
+ $context = stream_context_create($options);
+ file_get_contents($url, false, $context);
+}
?>
--
cgit v1.2.3
From 33dabcecd0e9c127ee8b417810e3e0d6f3da5230 Mon Sep 17 00:00:00 2001
From: Joe Robinson
Date: Fri, 11 Dec 2015 16:34:52 +0000
Subject: Fix syntax errors
---
config.php.example | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/config.php.example b/config.php.example
index 43303a2..0a0c8b1 100644
--- a/config.php.example
+++ b/config.php.example
@@ -20,8 +20,8 @@
$indexignore = array(".htaccess", "config.php", "index.php", "upload_file.php", "upload.html");
# An URL to send a POST to when an upload is successful
- $nofificationurl = "http://tghost.co.uk/blaupload"
+ $nofificationurl = "http://tghost.co.uk/blaupload";
#The IRC channel notified by uploads when using the notification URL
- $notificationchannel = "theblueroom"
+ $notificationchannel = "theblueroom";
?>
--
cgit v1.2.3
From 56c10325923bc297cd910c81754c8a906f613bd1 Mon Sep 17 00:00:00 2001
From: Joe Robinson
Date: Fri, 11 Dec 2015 17:02:06 +0000
Subject: Give the POST config variables shorter names
---
config.php.example | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/config.php.example b/config.php.example
index 0a0c8b1..79880d2 100644
--- a/config.php.example
+++ b/config.php.example
@@ -20,8 +20,8 @@
$indexignore = array(".htaccess", "config.php", "index.php", "upload_file.php", "upload.html");
# An URL to send a POST to when an upload is successful
- $nofificationurl = "http://tghost.co.uk/blaupload";
+ $posturl = "http://tghost.co.uk/blaupload";
#The IRC channel notified by uploads when using the notification URL
- $notificationchannel = "theblueroom";
+ $postchannel = "theblueroom";
?>
--
cgit v1.2.3
From 07e0c2aa0b5b1866815b8b0f24b0dd3c71d05634 Mon Sep 17 00:00:00 2001
From: Joe Robinson
Date: Fri, 11 Dec 2015 17:02:37 +0000
Subject: Fix upload function by passing config values
---
upload_file.php | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
mode change 100644 => 100755 upload_file.php
diff --git a/upload_file.php b/upload_file.php
old mode 100644
new mode 100755
index 3f35524..500c4b2
--- a/upload_file.php
+++ b/upload_file.php
@@ -51,14 +51,14 @@ if ($_FILES["file"]["error"] > 0) {
$fileurl = "$url" . $_FILES["file"]["name"];
echo "URL: $fileurl
";
echo "Size: " . size_readable($_FILES["file"]["size"], null, "bi");
- if (isset($notificationurl)) {
- send_upload_notification($fileurl);
+ if (isset($posturl)) {
+ send_upload_notification($fileurl, $posturl, $postchannel);
}
}
}
-function send_upload_notification($fileurl) {
- $data = array('url' => $fileurl, 'channel' => $notificationchannel);
+function send_upload_notification($fileurl, $posturl, $channel) {
+ $data = array('url' => $fileurl, 'channel' => $channel);
$options = array(
'http' => array(
@@ -69,7 +69,7 @@ function send_upload_notification($fileurl) {
),
);
$context = stream_context_create($options);
- file_get_contents($url, false, $context);
+ file_get_contents($posturl, false, $context);
}
?>
--
cgit v1.2.3
From 6035422dc0a8376ca1da17a99b4508dbbc5cd89d Mon Sep 17 00:00:00 2001
From: Joe Robinson
Date: Fri, 11 Dec 2015 17:05:52 +0000
Subject: Add .gitignore so we don't commit live config
---
.gitignore | 1 +
1 file changed, 1 insertion(+)
create mode 100644 .gitignore
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..4f4773f
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+config.php
--
cgit v1.2.3
From 8d08598fa17ec47a5efb55f4f428358480b9159c Mon Sep 17 00:00:00 2001
From: Joe Robinson
Date: Fri, 11 Dec 2015 17:18:30 +0000
Subject: Add newline to end of header
---
upload_file.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/upload_file.php b/upload_file.php
index 500c4b2..f1ed597 100755
--- a/upload_file.php
+++ b/upload_file.php
@@ -63,7 +63,7 @@ function send_upload_notification($fileurl, $posturl, $channel) {
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n" .
- "X-Blaears-Event: blaupload",
+ "X-Blaears-Event: blaupload\r\n",
'method' => 'POST',
'content' => http_build_query($data),
),
--
cgit v1.2.3
From 615164ec271a64dbd3007270470fb32880191b0e Mon Sep 17 00:00:00 2001
From: Joe Robinson
Date: Sat, 12 Dec 2015 14:28:58 +0000
Subject: Make example config for notifications more generic
---
config.php.example | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/config.php.example b/config.php.example
index 79880d2..b31e440 100644
--- a/config.php.example
+++ b/config.php.example
@@ -20,8 +20,8 @@
$indexignore = array(".htaccess", "config.php", "index.php", "upload_file.php", "upload.html");
# An URL to send a POST to when an upload is successful
- $posturl = "http://tghost.co.uk/blaupload";
+ $posturl = "http://url.to/post/to";
#The IRC channel notified by uploads when using the notification URL
- $postchannel = "theblueroom";
+ $postchannel = "ircchannel";
?>
--
cgit v1.2.3