Skip to content

Commit 48936dc

Browse files
Merge pull request #2 from JSON-ms/dev
Merge dev into master
2 parents 2f55ea8 + 21d6702 commit 48936dc

32 files changed

Lines changed: 501 additions & 281 deletions

.datatable.sql

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
-- MySQL dump 10.13 Distrib 8.0.41, for Win64 (x86_64)
2+
--
3+
-- Host: 127.0.0.1 Database: jsonms_local
4+
-- ------------------------------------------------------
5+
-- Server version 8.0.41
6+
7+
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
8+
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
9+
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
10+
/*!50503 SET NAMES utf8mb4 */;
11+
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
12+
/*!40103 SET TIME_ZONE='+00:00' */;
13+
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
14+
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
15+
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
16+
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
17+
18+
--
19+
-- Table structure for table `errors`
20+
--
21+
22+
DROP TABLE IF EXISTS `errors`;
23+
/*!40101 SET @saved_cs_client = @@character_set_client */;
24+
/*!50503 SET character_set_client = utf8mb4 */;
25+
CREATE TABLE `errors` (
26+
`id` int unsigned NOT NULL AUTO_INCREMENT,
27+
`key` varchar(255) NOT NULL,
28+
`message` text,
29+
`source` varchar(256) DEFAULT NULL,
30+
`line` smallint DEFAULT NULL,
31+
`column` smallint DEFAULT NULL,
32+
`stack` text,
33+
`occurred_on` datetime NOT NULL,
34+
`last_timestamp` bigint NOT NULL,
35+
`version` varchar(16) NOT NULL,
36+
`route` varchar(128) NOT NULL,
37+
`count` smallint NOT NULL DEFAULT '0',
38+
`user_agent` varchar(255) NOT NULL,
39+
`created_on` datetime DEFAULT (now()),
40+
`created_by` int unsigned NOT NULL,
41+
`updated_at` datetime DEFAULT CURRENT_TIMESTAMP,
42+
PRIMARY KEY (`id`),
43+
UNIQUE KEY `errors_pk` (`key`)
44+
) ENGINE=InnoDB AUTO_INCREMENT=88 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
45+
/*!40101 SET character_set_client = @saved_cs_client */;
46+
47+
--
48+
-- Table structure for table `history`
49+
--
50+
51+
DROP TABLE IF EXISTS `history`;
52+
/*!40101 SET @saved_cs_client = @@character_set_client */;
53+
/*!50503 SET character_set_client = utf8mb4 */;
54+
CREATE TABLE `history` (
55+
`id` int NOT NULL AUTO_INCREMENT,
56+
`uuid` char(36) COLLATE utf8mb4_unicode_ci NOT NULL,
57+
`content` text COLLATE utf8mb4_unicode_ci NOT NULL,
58+
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
59+
`created_by` int DEFAULT NULL,
60+
PRIMARY KEY (`id`),
61+
KEY `history_interfaces_uuid_fk` (`uuid`),
62+
KEY `history_users_id_fk` (`created_by`),
63+
CONSTRAINT `history_interfaces_uuid_fk` FOREIGN KEY (`uuid`) REFERENCES `structures` (`uuid`) ON DELETE CASCADE,
64+
CONSTRAINT `history_users_id_fk` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`)
65+
) ENGINE=InnoDB AUTO_INCREMENT=378 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
66+
/*!40101 SET character_set_client = @saved_cs_client */;
67+
68+
--
69+
-- Table structure for table `permissions`
70+
--
71+
72+
DROP TABLE IF EXISTS `permissions`;
73+
/*!40101 SET @saved_cs_client = @@character_set_client */;
74+
/*!50503 SET character_set_client = utf8mb4 */;
75+
CREATE TABLE `permissions` (
76+
`id` int NOT NULL AUTO_INCREMENT,
77+
`structure_uuid` char(36) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
78+
`type` enum('admin','interface') COLLATE utf8mb4_unicode_ci NOT NULL,
79+
`email` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
80+
PRIMARY KEY (`id`)
81+
) ENGINE=InnoDB AUTO_INCREMENT=57 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
82+
/*!40101 SET character_set_client = @saved_cs_client */;
83+
84+
--
85+
-- Table structure for table `structures`
86+
--
87+
88+
DROP TABLE IF EXISTS `structures`;
89+
/*!40101 SET @saved_cs_client = @@character_set_client */;
90+
/*!50503 SET character_set_client = utf8mb4 */;
91+
CREATE TABLE `structures` (
92+
`uuid` char(36) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT (uuid()),
93+
`hash` char(10) COLLATE utf8mb4_unicode_ci NOT NULL,
94+
`label` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
95+
`logo` varchar(1024) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
96+
`content` text COLLATE utf8mb4_unicode_ci NOT NULL,
97+
`webhook` char(36) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
98+
`created_by` int NOT NULL,
99+
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
100+
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
101+
PRIMARY KEY (`uuid`),
102+
KEY `interfaces_users_id_fk` (`created_by`),
103+
KEY `interfaces__hash_index` (`hash`),
104+
KEY `interfaces_webhooks_uuid_fk` (`webhook`),
105+
CONSTRAINT `interfaces_users_id_fk` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
106+
CONSTRAINT `interfaces_webhooks_uuid_fk` FOREIGN KEY (`webhook`) REFERENCES `webhooks` (`uuid`)
107+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
108+
/*!40101 SET character_set_client = @saved_cs_client */;
109+
110+
--
111+
-- Table structure for table `users`
112+
--
113+
114+
DROP TABLE IF EXISTS `users`;
115+
/*!40101 SET @saved_cs_client = @@character_set_client */;
116+
/*!50503 SET character_set_client = utf8mb4 */;
117+
CREATE TABLE `users` (
118+
`id` int NOT NULL AUTO_INCREMENT,
119+
`google_id` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
120+
`name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
121+
`email` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
122+
`avatar` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
123+
`created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
124+
PRIMARY KEY (`id`),
125+
UNIQUE KEY `google_id` (`google_id`)
126+
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
127+
/*!40101 SET character_set_client = @saved_cs_client */;
128+
129+
--
130+
-- Table structure for table `webhooks`
131+
--
132+
133+
DROP TABLE IF EXISTS `webhooks`;
134+
/*!40101 SET @saved_cs_client = @@character_set_client */;
135+
/*!50503 SET character_set_client = utf8mb4 */;
136+
CREATE TABLE `webhooks` (
137+
`uuid` char(36) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT (uuid()),
138+
`url` varchar(1024) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
139+
`secret` varchar(84) COLLATE utf8mb4_unicode_ci NOT NULL,
140+
`cypher` varchar(84) COLLATE utf8mb4_unicode_ci NOT NULL,
141+
`created_by` int NOT NULL,
142+
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
143+
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
144+
PRIMARY KEY (`uuid`),
145+
KEY `interfaces_webhooks_users_id_fk` (`created_by`),
146+
CONSTRAINT `interfaces_webhooks_users_id_fk` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`)
147+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
148+
/*!40101 SET character_set_client = @saved_cs_client */;
149+
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
150+
151+
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
152+
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
153+
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
154+
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
155+
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
156+
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
157+
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
158+
159+
-- Dump completed on 2025-04-26 18:13:45

.env.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# General
22
INTERFACE_EDITOR_URL=http://localhost:3000
33
ACCESS_CONTROL_ALLOW_ORIGIN=http://localhost:3000
4-
JSONMS_CYPHER_KEY=urjMdK071cL935eKdczjEQ==
4+
JSONMS_CYPHER_KEY=
55

66
# Database
77
DATABASE_HOST=localhost
88
DATABASE_DBNAME=
9-
DATABASE_USERNAME=root
9+
DATABASE_USERNAME=
1010
DATABASE_PASSWORD=
1111

1212
# Google OAuth

README.md

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,53 @@
11
# @jsonms/server
22

3-
The server to use with your instance of [jsonms-www](https://github.com/JSON-ms/www).
3+
Welcome to the **@jsonms/server** project!
4+
This package provides the server-side foundation for managing MySQL schemas and environment configurations for the JSONMS system.
5+
6+
## Requirements
7+
- PHP 8.x
8+
- MySQL server
9+
10+
## Getting Started
11+
12+
Follow these steps to set up and run the project locally:
13+
14+
### 1. Prepare the MySQL Database
15+
16+
A `.datatable.sql` file is included in the project.
17+
It contains the necessary schema definitions required to run the application.
18+
19+
To set up your database:
20+
21+
```bash
22+
mysql -u your_user -p your_database_name < .datatable.sql
23+
```
24+
25+
Replace your_user and your_database_name with your MySQL username and target database name.
26+
27+
Make sure your MySQL server is running and accessible.
28+
29+
### 2. Set Up Environment Variables
30+
The project uses environment variables for configuration.
31+
A sample file `.env.example` is provided.
32+
33+
To create your local `.env` file:
34+
35+
```bash
36+
cp .env.example .env
37+
```
38+
39+
Edit `.env` to match your environment settings, such as database connection credentials, ports, and other options.
40+
41+
### 3. Running the Server
42+
43+
You can define your own virtual host with Apache or Nginx but the fastest way to run the server is with a built-in PHP server.
44+
45+
```bash
46+
php -S localhost:9001 index.php
47+
```
48+
49+
## Contributing
50+
Contributions are welcome! Please feel free to submit a pull request or open an issue.
51+
52+
## License
53+
This project is licensed under the BSD-3-Clause License. See the LICENSE file for details.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "1.0.8",
2+
"version": "1.0.12",
33
"name": "jsonms/server",
44
"description": "The JSON.ms Request Handler Server is a robust backend solution designed to manage and process all incoming requests from the main JSON.ms website.",
55
"license": "BSD-3-Clause",
Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,29 @@
22

33
use JSONms\Controllers\RestfulController;
44

5-
class WebhookController extends RestfulController {
5+
class EndpointController extends RestfulController {
66

7-
public function saveAction($webhooks) {
8-
foreach($webhooks as $webhook) {
9-
if (isset($webhook->uuid)) {
10-
$this->query('update-webhook-by-uuid', [
11-
'uuid' => $webhook->uuid,
12-
'url' => $webhook->url,
7+
public function saveAction($endpoints) {
8+
foreach($endpoints as $endpoint) {
9+
if (isset($endpoint->uuid)) {
10+
$this->query('update-endpoint-by-uuid', [
11+
'uuid' => $endpoint->uuid,
12+
'url' => $endpoint->url,
1313
'userId' => $this->getCurrentUserId(),
1414
]);
1515
} else {
1616
$cypherKey = $this->getHash(24);
1717
$serverSecret = $this->encrypt($this->getHash(24), $cypherKey);
1818
$encryptedCypherKey = $this->encrypt($cypherKey, $_ENV['JSONMS_CYPHER_KEY']);
19-
$this->query('insert-webhook', [
20-
'url' => $webhook->url,
19+
$this->query('insert-endpoint', [
20+
'url' => $endpoint->url,
2121
'secret' => $serverSecret,
2222
'cypher' => $encryptedCypherKey,
2323
'created_by' => $this->getCurrentUserId(),
2424
]);
2525
}
2626
}
27-
$stmt = $this->query('get-all-webhooks', [
27+
$stmt = $this->query('get-all-endpoints', [
2828
'userId' => $this->getCurrentUserId(),
2929
]);
3030

@@ -34,7 +34,7 @@ public function saveAction($webhooks) {
3434
}
3535

3636
public function deleteAction($id) {
37-
$stmt = $this->query('delete-webhook-by-uuid', [
37+
$stmt = $this->query('delete-endpoint-by-uuid', [
3838
'uuid' => $id,
3939
'userId' => $this->getCurrentUserId(),
4040
]);
@@ -44,28 +44,28 @@ public function deleteAction($id) {
4444
}
4545

4646
public function secretKeyAction($uuid) {
47-
$webhook = $this->getWebhook($uuid);
48-
$decryptedCypherKey = $this->decrypt($webhook->cypher, $_ENV['JSONMS_CYPHER_KEY']);
49-
$decryptedServerKey = $this->decrypt($webhook->secret, $decryptedCypherKey);
47+
$endpoint = $this->getEndpoint($uuid);
48+
$decryptedCypherKey = $this->decrypt($endpoint->cypher, $_ENV['JSONMS_CYPHER_KEY']);
49+
$decryptedServerKey = $this->decrypt($endpoint->secret, $decryptedCypherKey);
5050
$this->responseJson($decryptedServerKey);
5151
}
5252

5353
public function cypherKeyAction($uuid) {
54-
$webhook = $this->getWebhook($uuid);
55-
$decryptedCypherKey = $this->decrypt($webhook->cypher, $_ENV['JSONMS_CYPHER_KEY']);
54+
$endpoint = $this->getEndpoint($uuid);
55+
$decryptedCypherKey = $this->decrypt($endpoint->cypher, $_ENV['JSONMS_CYPHER_KEY']);
5656
$this->responseJson($decryptedCypherKey);
5757
}
5858

59-
private function getWebhook($uuid, $showError = true): false | stdClass {
60-
$stmt = $this->query('get-webhook-by-uuid', [
59+
private function getEndpoint($uuid, $showError = true): false | stdClass {
60+
$stmt = $this->query('get-endpoint-by-uuid', [
6161
'uuid' => $uuid,
6262
'userId' => $this->getCurrentUserId(),
6363
]);
6464
if ($stmt->rowCount() > 0) {
6565
return $stmt->fetch(PDO::FETCH_OBJ);
6666
}
6767
if ($showError) {
68-
throwError(403, 'You don\'t have permission to access this webhook');
68+
throwError(403, 'You don\'t have permission to access this endpoint');
6969
}
7070
return false;
7171
}

0 commit comments

Comments
 (0)