Issues (762)

1
<?php
2
3
/**
4
 * Copyright (c) 2018 Justin Kuenzel (jukusoft.com)
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
$start_time = microtime(true);
20
21
//define root path
22
define('ROOT_PATH', dirname(__FILE__) . "/");
23
24
error_reporting(E_ALL);
25
26
require("system/core/init.php");
27
28
if (DEBUG_MODE) {
29
	@ini_set('display_errors', 1);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for ini_set(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

29
	/** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 1);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
30
}
31
32
//throw event
33
Events::throwEvent("start_session");
34
35
//use gzip compression
36
ob_start();
37
38
//initialize api oauth
39
ApiAuth::getInstance()->init();
40
41
$api_method = new ApiMethod();
42
$api_method->loadApiMethods();
43
44
$method = "";
45
46
if (isset($_REQUEST['method']) && !empty($_REQUEST['method'])) {
47
	$method = htmlentities($_REQUEST['method']);
48
}
49
50
//execute api method, if available
51
if (!empty($method)) {
52
	//load api method
53
	$res = $api_method->loadMethod($method);
54
55
	if (!$res) {
56
		//print error message
57
		header("Content-Type: application/json");
58
		echo "{\"error\": \"Api method '" . $method . "' doesnt exists\", \"status\": 400}";
59
	} else {
60
		$api_method->executeApiMethod();
61
	}
62
} else {
63
	//print error message
64
	header("Content-Type: application/json");
65
	echo "{\"error\": \"No api method in request, correct call: api.php?method=<API_METHOD>\", \"status\": 400}";
66
}
67
68
$end_time = microtime(true);
69
$exec_time = $end_time - $start_time;
70
71
//flush gzip cache
72
ob_end_flush();
73
74
//send logs to server
75
if (LOGGING_ENABLED) {
76
	Logger::send();
77
}
78
79
80
?>
0 ignored issues
show
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
81