Skip to content

Commit

Permalink
Change to http POST
Browse files Browse the repository at this point in the history
  • Loading branch information
Offerel committed Jan 2, 2021
1 parent 95fc87a commit 134fc84
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 35 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### v2.2.4
- Change to http POST

### v2.2.3
- Added preloading animation

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"role": "Developer"
}
],
"version": "2.2.3",
"version": "2.2.4",
"repositories": [
{
"type": "composer",
Expand Down
7 changes: 6 additions & 1 deletion syncmarks.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions syncmarks.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 36 additions & 31 deletions syncmarks.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Roundcube Bookmarks Plugin
*
* @version 2.2.3
* @version 2.2.4
* @author Offerel
* @copyright Copyright (c) 2020, Offerel
* @license GNU General Public License, version 3
Expand Down Expand Up @@ -90,19 +90,19 @@ function get_notifications() {
$path = $rcmail->config->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);
}
}
Expand All @@ -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);
}
Expand All @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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);
}
}
Expand Down

0 comments on commit 134fc84

Please sign in to comment.