diff --git a/data/conf/nginx/site.conf b/data/conf/nginx/site.conf index 181a802b..685e1fc7 100644 --- a/data/conf/nginx/site.conf +++ b/data/conf/nginx/site.conf @@ -18,10 +18,9 @@ server { access_log /var/log/nginx/access.log; root /web; - location /api/v1/ { - try_files $uri $uri/ /json_api.php?$args; + location ~ ^/api/v1/(.*)$ { + try_files $uri $uri/ /json_api.php?query=$1; } - rewrite ^/api/v1/([^/]+)/([^/]+)/([^/]+)/?$ /json_api.php?action=$1&cat=$2&object=$3? last; location ^~ /.well-known/acme-challenge/ { allow all; @@ -167,10 +166,9 @@ server { access_log /var/log/nginx/access.log; root /web; - location /api/v1/ { - try_files $uri $uri/ /json_api.php?$args; + location ~ ^/api/v1/(.*)$ { + try_files $uri $uri/ /json_api.php?query=$1; } - rewrite ^/api/v1/([^/]+)/([^/]+)/([^/]+)/?$ /json_api.php?action=$1&cat=$2&object=$3? last; location ^~ /.well-known/acme-challenge/ { allow all; diff --git a/data/web/js/mailbox.js b/data/web/js/mailbox.js index 9e1da2ac..0f0b4098 100644 --- a/data/web/js/mailbox.js +++ b/data/web/js/mailbox.js @@ -306,7 +306,7 @@ $(document).ready(function() { type: "POST", dataType: "json", data: { "address": JSON.stringify(selected_aliases), "active": "1" }, - url: '/api/v1/edit/alias/post', + url: '/api/v1/edit/alias', jsonp: false, complete: function (data) { location.reload(); @@ -322,7 +322,7 @@ $(document).ready(function() { type: "POST", dataType: "json", data: { "address": JSON.stringify(selected_aliases), "active": "0" }, - url: '/api/v1/edit/alias/post', + url: '/api/v1/edit/alias', jsonp: false, complete: function (data) { location.reload(); @@ -349,7 +349,7 @@ $(document).ready(function() { type: "POST", dataType: "json", data: { "address": JSON.stringify(selected_aliases) }, - url: '/api/v1/delete/alias/post', + url: '/api/v1/delete/alias', jsonp: false, complete: function (data) { location.reload(); diff --git a/data/web/json_api.php b/data/web/json_api.php index b09caa67..44e7d934 100644 --- a/data/web/json_api.php +++ b/data/web/json_api.php @@ -1,14 +1,27 @@ POST data: + { + address: {a, b, c}, (where a, b, c represent alias addresses) + active: 1 (0 or 1) + } + +delete/alias => POST data: + { + address: {a, b, c}, (where a, b, c represent alias addresses) + } + +*/ +header('Content-Type: application/json'); require_once 'inc/prerequisites.inc.php'; error_reporting(E_ALL); if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_username'])) { - if (isset($_GET['action']) && isset($_GET['cat'])) { - $category = filter_input(INPUT_GET, 'cat', FILTER_SANITIZE_STRING); - $action = filter_input(INPUT_GET, 'action', FILTER_SANITIZE_STRING); - - if (isset($_GET['object'])) { - $object = filter_input(INPUT_GET, 'object', FILTER_SANITIZE_STRING); - } + if (isset($_GET['query'])) { + + $query = explode('/', $_GET['query']); + $action = (isset($query[0])) ? $query[0] : null; + $category = (isset($query[1])) ? $query[1] : null; + $object = (isset($query[2])) ? $query[2] : null; switch ($action) { case "get":