--- /dev/null
+<?php
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
+ *
+ * You should have received a copy of the
+ * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
+ * along with this program. If not, see http://www.sun.com/cddl/cddl.html
+ *
+ * 2019 - 2020 https://://www.bananas-playground.net/projekt/selfpaste
+ */
+
+/**
+ * this is the config file for the webclient
+ */
+
+/* please provide a unique username for this installation */
+define('FRONTEND_USERNAME','some');
+/* please provide a unique password for this installation */
+define('FRONTEND_PASSWORD', 'admin');
+/* please provide a unique secret for this installation and add this to the allowed ones*/
+define('THE_SECRET','your super duper secret');
+/* the selfpaste installation endpoint url. Absolute or relative */
+define('THE_ENDPOINT','http://www.some.tld/path/to/selfpaste/index.php');
*/
/**
- * This is a simple web client which can be hosted whereevery you want.
+ * This is a simple web client which can be hosted where you want.
* copy the config.default.php file to config.php and update its settings
*/
exit;
}
-exit("dosmoe");
-if(isset($_POST['dl']) && !empty($_POST['dl'])
- && isset($_FILES['pasty']) && !empty($_FILES['pasty'])
- && isset(SELFPASTE_UPLOAD_SECRET[$_POST['dl']])) {
- $_create = true;
+$statusMessage = "";
+if(isset($_POST['doSome'])) {
+ $_text = trim($_POST['asText']);
+ $_file = $_FILES['uploadFile'];
+
+ if(!empty($_text) && !empty($_file['tmp_name'])) {
+ $statusMessage = "One option. Not both at the same time.";
+ }
+ elseif (!empty($_text)) {
+ $_tmpfile = tmpfile();
+ fwrite($_tmpfile, $_text);
+ $data['pasty'] = curl_file_create(stream_get_meta_data($_tmpfile)['uri']);
+ }
+ elseif(!empty($_file['tmp_name'])) {
+
+ if($_file['error'] === UPLOAD_ERR_OK) {
+ $data['pasty'] = curl_file_create($_file['tmp_name']);
+ }
+ else {
+ $statusMessage = "Upload of selected file failed.";
+ }
+ }
+
+ if(empty($statusMessage)) {
+ $data['dl'] = THE_SECRET;
+ $call = curlPostUploadCall(THE_ENDPOINT,$data);
+
+ $statusMessage = "Something went wrong. ".var_export($call,true);
+ $json = json_decode($call,true);
+ if(!empty($call) && $json != NULL) {
+ if (isset($json['message']) && $json['status'] == "200") {
+ $statusMessage = $json['message'];
+ }
+ }
+ }
}
?>
<title>selfpaste - add a new one</title>
</head>
<body>
-<form method="post" enctype="multipart/form-data" action="<?php echo THE_ENDPOINT; ?>">
- <input type="hidden" name="dl" value="<?php echo THE_SECRET; ?>">
+<?php if(!empty($statusMessage)) { ?>
+<p><?php echo $statusMessage; ?></p>
+<?php } ?>
+<form method="post" enctype="multipart/form-data" action="">
<p>
- <textarea name="" cols="100" rows="10"></textarea>
+ <textarea name="asText" cols="100" rows="20"></textarea>
</p>
- <p><input type="file" name="pasty"></p>
+ <p><input type="file" name="uploadFile"></p>
<p><input type="submit" value="send" name="doSome"></p>
</form>
</body>
</html>
+<?php
+/**
+ * functions start here
+ */
+/**
+ * execute a curl call to the given $url
+ * @param string $url The request url
+ * @param bool $port
+ * @return bool|mixed
+ */
+function curlPostUploadCall($url,$data,$port=false) {
+ $ret = false;
+
+ $ch = curl_init();
+
+ curl_setopt($ch, CURLOPT_URL, $url);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
+ curl_setopt($ch, CURLOPT_TIMEOUT, 30);
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
+ curl_setopt($ch, CURLOPT_MAXREDIRS, 2);
+
+ curl_setopt($ch, CURLOPT_POST,1);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
+
+ if(!empty($port)) {
+ curl_setopt($ch, CURLOPT_PORT, $port);
+ }
+
+ $do = curl_exec($ch);
+
+ if(is_string($do) === true) {
+ $ret = $do;
+ }
+ else {
+ error_log(var_export(curl_error($ch),true));
+ }
+
+ curl_close($ch);
+
+ return $ret;
+}