From 134fc84b21aba33b83ce383c94d97e905282fc7b Mon Sep 17 00:00:00 2001 From: Offerel <14041522+Offerel@users.noreply.github.com> Date: Sat, 2 Jan 2021 20:47:52 +0100 Subject: [PATCH] Change to http POST --- CHANGELOG.md | 3 +++ composer.json | 2 +- syncmarks.js | 7 ++++- syncmarks.min.js | 4 +-- syncmarks.php | 67 ++++++++++++++++++++++++++---------------------- 5 files changed, 48 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 765c673..32b674e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +### v2.2.4 +- Change to http POST + ### v2.2.3 - Added preloading animation diff --git a/composer.json b/composer.json index 22d35e5..f9d2a67 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "role": "Developer" } ], - "version": "2.2.3", + "version": "2.2.4", "repositories": [ { "type": "composer", diff --git a/syncmarks.js b/syncmarks.js index 7484a92..d744967 100644 --- a/syncmarks.js +++ b/syncmarks.js @@ -1,7 +1,7 @@ /** * Roundcube Bookmarks Plugin * - * @version 2.2.2 + * @version 2.2.4 * @author Offerel * @copyright Copyright (c) 2020, Offerel * @license GNU General Public License, version 3 @@ -35,6 +35,11 @@ function add_url(format) { 0 < t.length && (t.startsWith("http") || t.startsWith("ftp")) && rcmail.http_post("syncmarks/add_url", "_url=" + t + "&_format=" + format) } +function url_removed(response) { + console.log(response.message); + document.getElementById("bookmarkpane").style.width = "0"; +} + function urladded(t) { console.log(t.message), 0 < t.data.length && $("#bookmarkpane").html(t.data) } diff --git a/syncmarks.min.js b/syncmarks.min.js index 803ed9d..baa9d1f 100644 --- a/syncmarks.min.js +++ b/syncmarks.min.js @@ -1,9 +1,9 @@ /** * Roundcube Bookmarks Plugin * - * @version 2.2.2 + * @version 2.2.4 * @author Offerel * @copyright Copyright (c) 2020, Offerel * @license GNU General Public License, version 3 */ -function h_del(t,o,format){t.preventDefault();var e=rcmail.gettext("bookmarks_del","syncmarks").replace("%b%",o.innerHTML);if(1==confirm(e)){let r=encodeURIComponent(o.href),i=o.attributes.bid.value;rcmail.http_post("syncmarks/del_url","_url="+r+"&_format="+format+"&_bid="+i)}}function bookmarks_cmd(){if("300"!=document.getElementById("bookmarkpane").clientWidth){let dv=document.createElement("div");dv.classList.add("db-spinner"),dv.id="db-spinner",document.getElementById("layout").parentNode.appendChild(dv),rcmail.http_post("syncmarks/get_bookmarks","_url=2")}else document.getElementById("bookmarkpane").style.width="0"}function add_url(format){var t=encodeURIComponent(prompt(rcmail.gettext("bookmarks_url","syncmarks")));console.log(format),0config->get('bookmarks_path', false); $filename = $rcmail->config->get('bookmarks_filename', false); - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $path.$filename.'?gurls=1'); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']); - curl_setopt($ch, CURLOPT_VERBOSE, TRUE); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); - curl_setopt($ch, CURLOPT_MAXREDIRS, 4); - curl_setopt($ch, CURLOPT_HTTPGET, TRUE); + $data = array( + 'caction' => 'gurls' + ); + + $ch=curl_init(); + curl_setopt($ch, CURLOPT_URL, $path.$filename); curl_setopt($ch, CURLOPT_USERPWD, $rcmail->user->get_username().":".$rcmail->get_user_password()); - $data = curl_exec($ch); - $rcmail->output->command('plugin.sendNotifications', $data); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $data); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + $response = curl_exec($ch); curl_close($ch); + $rcmail->output->command('plugin.sendNotifications', $response); rcube_utils::setcookie('sycmarks_n', '1', 0); } } @@ -112,17 +112,18 @@ function del_not() { $this->load_config(); $path = $rcmail->config->get('bookmarks_path', false); $filename = $rcmail->config->get('bookmarks_filename', false); + + $sdata = array( + 'caction' => 'durl', + 'durl' => rcube_utils::get_input_value('_nkey', rcube_utils::INPUT_GPC) + ); $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $path.$filename.'?durl='.rcube_utils::get_input_value('_nkey', rcube_utils::INPUT_GPC)); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']); - curl_setopt($ch, CURLOPT_VERBOSE, TRUE); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); - curl_setopt($ch, CURLOPT_MAXREDIRS, 4); - curl_setopt($ch, CURLOPT_HTTPGET, TRUE); + curl_setopt($ch, CURLOPT_URL, $path.$filename); curl_setopt($ch, CURLOPT_USERPWD, $rcmail->user->get_username().":".$rcmail->get_user_password()); + curl_setopt($ch, CURLOPT_HTTPPOST, TRUE); + curl_setopt($ch, CURLOPT_POSTFIELDS, $sdata); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($ch); curl_close($ch); } @@ -136,15 +137,14 @@ function get_bookmarks() { $password = $rcmail->get_user_password(); $ext = pathinfo($filename, PATHINFO_EXTENSION); $remote_url = $path."/".$filename; - $opts = array('http'=>array( - 'method'=>"GET", - 'header' => "Authorization: Basic ".base64_encode("$username:$password") - ) - ); - - $context = stream_context_create($opts); if($ext === "json") { + $opts = array('http'=>array( + 'method'=>"GET", + 'header' => "Authorization: Basic ".base64_encode("$username:$password") + ) + ); + $context = stream_context_create($opts); $bms = file_get_contents($remote_url, false, $context); foreach ($http_response_header as &$value) { if (strpos($value, 'ast-Modified') != 0) { @@ -162,7 +162,10 @@ function get_bookmarks() { } } elseif($ext === "php") { - $sdata = array('export' => 'html'); + $sdata = array( + 'caction' => 'fexport', + 'type' => 'html' + ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $path.$filename); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); @@ -250,7 +253,7 @@ function del_url() { $rcmail->output->command('syncmarks/urladded', array('message' => "Bookmark deleted", 'data' => $cmarks)); } elseif($format == "php") { - $ddata = array('mdel' => true, 'id' => $bid, 'rc' => true); + $ddata = array('caction' => 'mdel', 'id' => $bid, 'rc' => true); $path = $rcmail->config->get('bookmarks_path', false); $filename = $rcmail->config->get('bookmarks_filename', false); $username = $rcmail->user->get_username(); @@ -267,13 +270,14 @@ function del_url() { curl_setopt($ch, CURLOPT_POSTFIELDS, $ddata); curl_setopt($ch, CURLOPT_USERPWD, $username.":".$password); $rdata = curl_exec($ch); + $rcmail->output->command('syncmarks/url_removed', array('message' => "URL removed")); curl_close($ch); } } function get_title($url) { $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $new_url); + curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']); curl_setopt($ch, CURLOPT_VERBOSE, TRUE); @@ -370,7 +374,7 @@ function add_url() { $rcmail->output->command('syncmarks/urladded', array('message' => 'URL is added.','data' => $cmarks)); } elseif($format == 'php') { - $ddata = array('madd' => true, 'url' => $new_url, 'rc' => true, 'folder' => 'unfiled_____'); + $ddata = array('caction' => 'madd', 'url' => $new_url, 'rc' => true, 'folder' => 'unfiled_____'); $path = $rcmail->config->get('bookmarks_path', false); $filename = $rcmail->config->get('bookmarks_filename', false); $username = $rcmail->user->get_username(); @@ -387,6 +391,7 @@ function add_url() { curl_setopt($ch, CURLOPT_POSTFIELDS, $ddata); curl_setopt($ch, CURLOPT_USERPWD, $username.":".$password); $rdata = curl_exec($ch); + $rcmail->output->command('syncmarks/url_removed', array('message' => "URL added")); curl_close($ch); } }