diff --git a/LICENSE.md b/LICENSE.md
index 63a11e3..56351c0 100644
--- a/LICENSE.md
+++ b/LICENSE.md
@@ -1,19 +1,7 @@
-Copyright (c) 2018 Netsyms Technologies.
+Copyright (c) 2017-2019 Netsyms Technologies. Some rights reserved.
-If you modify and redistribute this project, you must replace the branding
-assets with your own.
-
-The branding assets include:
- * the application icon
- * the Netsyms N punchcard logo
- * the Netsyms for Business graph logo
-
-If you are unsure if your usage is allowed, please contact us:
-https://netsyms.com/contact
-legal@netsyms.com
-
-All other portions of this application,
-unless otherwise noted (in comments, headers, etc), are licensed as follows:
+Licensed under the Mozilla Public License Version 2.0. Files without MPL header
+comments, including third party code, may be under a different license.
Mozilla Public License Version 2.0
==================================
diff --git a/action.php b/action.php
index e282a7c..0c0fd90 100644
--- a/action.php
+++ b/action.php
@@ -36,7 +36,7 @@ if ($VARS['action'] != "signout" && !(new User($_SESSION['uid']))->hasPermission
switch ($VARS['action']) {
case "edititem":
$insert = true;
- if (is_empty($VARS['itemid'])) {
+ if (empty($VARS['itemid'])) {
$insert = true;
} else {
if ($database->has('items', ['itemid' => $VARS['itemid']])) {
@@ -45,42 +45,42 @@ switch ($VARS['action']) {
returnToSender("invalid_itemid");
}
}
- if (is_empty($VARS['name'])) {
+ if (empty($VARS['name'])) {
returnToSender('missing_name');
}
- if (!is_empty($VARS['catstr']) && is_empty($VARS['cat'])) {
+ if (!empty($VARS['catstr']) && empty($VARS['cat'])) {
if ($database->count("categories", ["catname" => $VARS['catstr']]) == 1) {
$VARS['cat'] = $database->get("categories", 'catid', ["catname" => $VARS['catstr']]);
} else {
returnToSender('use_the_drop_luke');
}
}
- if (!is_empty($VARS['locstr']) && is_empty($VARS['loc'])) {
+ if (!empty($VARS['locstr']) && empty($VARS['loc'])) {
if ($database->count("locations", ["locname" => $VARS['locstr']]) == 1) {
$VARS['loc'] = $database->get("locations", 'locid', ["locname" => $VARS['locstr']]);
} else {
returnToSender('use_the_drop_luke');
}
}
- if (is_empty($VARS['cat']) || is_empty($VARS['loc'])) {
+ if (empty($VARS['cat']) || empty($VARS['loc'])) {
returnToSender('invalid_parameters');
}
- if (is_empty($VARS['qty'])) {
+ if (empty($VARS['qty'])) {
$VARS['qty'] = 1;
} else if (!is_numeric($VARS['qty'])) {
returnToSender('field_nan');
}
- if (is_empty($VARS['want'])) {
+ if (empty($VARS['want'])) {
$VARS['want'] = 0;
} else if (!is_numeric($VARS['want'])) {
returnToSender('field_nan');
}
- if (is_empty($VARS['cost'])) {
+ if (empty($VARS['cost'])) {
$VARS['cost'] = null;
} else if (!is_numeric($VARS['cost'])) {
returnToSender('field_nan');
}
- if (is_empty($VARS['price'])) {
+ if (empty($VARS['price'])) {
$VARS['price'] = null;
} else if (!is_numeric($VARS['price'])) {
returnToSender('field_nan');
@@ -128,7 +128,7 @@ switch ($VARS['action']) {
returnToSender("item_saved");
case "editcat":
$insert = true;
- if (is_empty($VARS['catid'])) {
+ if (empty($VARS['catid'])) {
$insert = true;
} else {
if ($database->has('categories', ['catid' => $VARS['catid']])) {
@@ -137,7 +137,7 @@ switch ($VARS['action']) {
returnToSender("invalid_catid");
}
}
- if (is_empty($VARS['name'])) {
+ if (empty($VARS['name'])) {
returnToSender('invalid_parameters');
}
@@ -154,7 +154,7 @@ switch ($VARS['action']) {
returnToSender("category_saved");
case "editloc":
$insert = true;
- if (is_empty($VARS['locid'])) {
+ if (empty($VARS['locid'])) {
$insert = true;
} else {
if ($database->has('locations', ['locid' => $VARS['locid']])) {
@@ -163,7 +163,7 @@ switch ($VARS['action']) {
returnToSender("invalid_locid");
}
}
- if (is_empty($VARS['name'])) {
+ if (empty($VARS['name'])) {
returnToSender('invalid_parameters');
}
@@ -217,9 +217,9 @@ switch ($VARS['action']) {
$client = new GuzzleHttp\Client();
$response = $client
- ->request('POST', PORTAL_API, [
+ ->request('POST', $SETTINGS['accounthub']['api'], [
'form_params' => [
- 'key' => PORTAL_KEY,
+ 'key' => $SETTINGS['accounthub']['key'],
'action' => "usersearch",
'search' => $VARS['q']
]
@@ -237,7 +237,7 @@ switch ($VARS['action']) {
}
break;
case "imageupload":
- $destpath = FILE_UPLOAD_PATH;
+ $destpath = $SETTINGS['file_upload_path'];
if (!is_writable($destpath)) {
returnToSender("unwritable_folder", "&id=$VARS[itemid]");
}
@@ -274,7 +274,7 @@ switch ($VARS['action']) {
default:
$err = "could not be uploaded.";
}
- $errors[] = htmlspecialchars($f['name']) . " $err";
+ $errors[] = htmlentities($f['name']) . " $err";
continue;
}
@@ -296,7 +296,7 @@ switch ($VARS['action']) {
}
if (!$imagevalid) {
- $errors[] = htmlspecialchars($f['name']) . " is not a supported image type (JPEG, GIF, PNG, WEBP).";
+ $errors[] = htmlentities($f['name']) . " is not a supported image type (JPEG, GIF, PNG, WEBP).";
continue;
}
@@ -319,7 +319,7 @@ switch ($VARS['action']) {
}
$database->insert('images', ['itemid' => $VARS['itemid'], 'imagename' => $filename, 'primary' => $primary]);
} else {
- $errors[] = htmlspecialchars($f['name']) . " could not be uploaded.";
+ $errors[] = htmlentities($f['name']) . " could not be uploaded.";
}
}
@@ -350,7 +350,7 @@ switch ($VARS['action']) {
$imagename = $database->get('images', 'imagename', ['imageid' => $VARS['imageid']]);
if ($database->count('images', ['imagename' => $imagename]) <= 1) {
- unlink(FILE_UPLOAD_PATH . "/" . $imagename);
+ unlink($SETTINGS['file_upload_path'] . "/" . $imagename);
}
$database->delete('images', ['AND' => ['itemid' => $VARS['itemid'], 'imageid' => $VARS['imageid']]]);
@@ -361,6 +361,6 @@ switch ($VARS['action']) {
returnToSender("image_deleted", "&id=$VARS[itemid]");
case "signout":
session_destroy();
- header('Location: index.php');
+ header('Location: index.php?logout=1');
die("Logged out.");
}
diff --git a/api.php b/api.php
index 931929f..870c44f 100644
--- a/api.php
+++ b/api.php
@@ -4,35 +4,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-/**
- * Simple JSON API to allow other apps to access data from this app.
- *
- * Requests can be sent via either GET or POST requests. POST is recommended
- * as it has a lower chance of being logged on the server, exposing unencrypted
- * user passwords.
- */
-require __DIR__ . '/required.php';
-header("Content-Type: application/json");
-$username = $VARS['username'];
-$password = $VARS['password'];
-$user = User::byUsername($username);
-if ($user->exists() !== true || Login::auth($username, $password) !== Login::LOGIN_OK) {
- header("HTTP/1.1 403 Unauthorized");
- die("\"403 Unauthorized\"");
-}
-
-// query max results
-$max = 20;
-if (preg_match("/^[0-9]+$/", $VARS['max']) === 1 && $VARS['max'] <= 1000) {
- $max = (int) $VARS['max'];
-}
-
-switch ($VARS['action']) {
- case "ping":
- $out = ["status" => "OK", "maxresults" => $max, "pong" => true];
- exit(json_encode($out));
- default:
- header("HTTP/1.1 400 Bad Request");
- die("\"400 Bad Request\"");
-}
+// Load in new API from legacy location (a.k.a. here)
+require __DIR__ . "/api/index.php";
diff --git a/api/.htaccess b/api/.htaccess
new file mode 100644
index 0000000..9a4efe4
--- /dev/null
+++ b/api/.htaccess
@@ -0,0 +1,5 @@
+# Rewrite for Nextcloud Notes API
+