Browse Source

Changes to api path

andryyy 8 years ago
parent
commit
8f213e8df9
3 changed files with 27 additions and 16 deletions
  1. 4 6
      data/conf/nginx/site.conf
  2. 3 3
      data/web/js/mailbox.js
  3. 20 7
      data/web/json_api.php

+ 4 - 6
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;

+ 3 - 3
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();

+ 20 - 7
data/web/json_api.php

@@ -1,14 +1,27 @@
 <?php
+/*
+edit/alias => 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":