Rewrite API (#825)

he /world/Topic() API has been rewritten.

General function:

The API is initialized upon roundstart and generates a list of possible api requests from /code/datums/api.dm
Once a request is made the following checks are performed:
If a query parameter is set (the function that should be called)
If the ip is ratelimited (or rate-limit-whitelisted)
The query is authenticated against the db using ip, function and key
If these checks pass, it is validated that the api command exists
Then the api command is called, all supplied params are passed through
Each API function returns 1 no matter if it failed or succeded
Additional info is provided in the statuscode, response and data vars
The statuscode, response and data are send back to the caller (through list2params)
The data var is json encoded before sending it back
This is not backward compatible to the current API
Current API Clients need to be updated
This commit is contained in:
Werner
2016-09-04 21:41:44 +02:00
committed by skull132
parent 2118078422
commit fb25382405
10 changed files with 911 additions and 437 deletions

View File

@@ -19,6 +19,41 @@ CREATE TABLE `ss13_admin_log` (
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `ss13_api_functions` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`function` VARCHAR(50) NULL DEFAULT '' COLLATE 'utf8_bin',
`description` VARCHAR(255) NULL DEFAULT NULL COLLATE 'utf8_bin',
PRIMARY KEY (`id`)
)
COLLATE='utf8_bin'
ENGINE=InnoDB;
CREATE TABLE `ss13_api_tokens` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`token` VARCHAR(100) NOT NULL COLLATE 'utf8_bin',
`ip` VARCHAR(16) NULL DEFAULT NULL COLLATE 'utf8_bin',
`creator` VARCHAR(50) NOT NULL COLLATE 'utf8_bin',
`description` VARCHAR(100) NOT NULL COLLATE 'utf8_bin',
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`deleted_at` DATETIME NULL DEFAULT NULL,
PRIMARY KEY (`id`)
)
COLLATE='utf8_bin'
ENGINE=InnoDB;
CREATE TABLE `ss13_api_token_function` (
`function_id` INT(11) NOT NULL,
`token_id` INT(11) NOT NULL,
PRIMARY KEY (`function_id`, `token_id`),
INDEX `token_id` (`token_id`),
CONSTRAINT `function_id` FOREIGN KEY (`function_id`) REFERENCES `ss13_api_functions` (`id`) ON UPDATE CASCADE ON DELETE CASCADE,
CONSTRAINT `token_id` FOREIGN KEY (`token_id`) REFERENCES `ss13_api_tokens` (`id`) ON UPDATE CASCADE ON DELETE CASCADE
)
COLLATE='utf8_bin'
ENGINE=InnoDB;
CREATE TABLE `ss13_ban` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`bantime` datetime NOT NULL,