GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 2c70cc...15bbb1 )
by mike
02:51
created

api.php ➔ output()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 9
rs 9.6666
1
<?php
2
class_exists('Setup', false) or include('classes/Setup.class.php');
3
class_exists('Utilities', false) or include('classes/Utilities.class.php');
4
class_exists('_MySQL', false) or include('classes/_MySQL.class.php');
5
class_exists('_FileCache', false) or include('classes/_FileCache.class.php');
6
7
$username = array_key_exists('username', $_POST) ? trim($_POST['username']) : '';
8
$passwd = array_key_exists('passwd', $_POST) ? trim($_POST['passwd']) : '';
9
$apiKey = array_key_exists('apiKey', $_POST) ? trim($_POST['apiKey']) : '';
10
$type = array_key_exists('type', $_POST) ? trim($_POST['type']) : '';
11
$data = array_key_exists('data', $_POST) ? trim($_POST['data']) : '';
12
$groupName = array_key_exists('groupName', $_POST) ? trim($_POST['groupName']) : '';
13
14
15
$result = array(
16
	'status'=>'',
17
	'result'=>array(),
18
);
19
20
$id = Utilities::validateLogin($username, $passwd, true, $apiKey);
21
if($id == 0) {
22
	$result['status'] = 'invalid login';
23
	output();
24
}
25
26
switch($type){
27 View Code Duplication
	case 'updateDomains':
28
		if($groupName=='') {
29
			$result['status'] = 'groupName is required';
30
			break;
31
		}
32
		$id = Utilities::ensureGroupExists($groupName);
33
		Utilities::updateDomains($data, $id);
34
		$result['status'] = 'success';
35
		break;
36
37 View Code Duplication
	case 'updateIPs':
38
		if($groupName=='') {
39
			$result['status'] = 'groupName is required';
40
			break;
41
		}
42
		$id = Utilities::ensureGroupExists($groupName);
43
		Utilities::updateIPs($data, $id);
44
		$result['status'] = 'success';
45
		break;
46
47
	case 'checkHostStatus':
48
		$result['status'] = 'success';
49
		Utilities::setBlockLists();
50
		$result['result'] = Utilities::checkBlacklists($data);
51
		break;
52
53
	case 'clearAllHostAndGroupData':
54
		$mysql = new _MySQL();
55
		$mysql->connect(Setup::$connectionArray);
56
		$mysql->runQuery("truncate table monitors");
57
		$mysql->runQuery("truncate table monitorGroup");
58
		$result['status'] = 'success';
59
		break;
60
61
	case 'blacklistStatus':
62
		$localCache = new _FileCache('blacklistmonitor-api', 90);
63
		$cacheKey = md5("$username|$passwd|$apiKey|$type|$data");
64
		$cacheData = $localCache->get($cacheKey);
65
		if ($cacheData !== false) {
66
			output($cacheData);
67
		}
68
		$mysql = new _MySQL();
69
		$mysql->connect(Setup::$connectionArray);
70
		$searchSQL = '';
71
		switch($data){
72
			case 'changed':
73
				$searchSQL .= " and lastStatusChanged = 1 ";
74
				break;
75
			case 'blocked':
76
				$searchSQL .= " and isBlocked = 1 ";
77
				break;
78
			case 'clean': $searchSQL .= " and isBlocked = 0 ";
79
				break;
80
			case 'all':
81
			default:
82
		}
83
84
		$rs = $mysql->runQuery("
85
			select ipDomain,isBlocked,rDNS,status,lastStatusChangeTime,lastUpdate
86
			from monitors
87
			where 1=1 $searchSQL");
88
		$result['status'] = 'success';
89
		$result['result'] = array();
90
		while($row = mysqli_fetch_array($rs, MYSQL_ASSOC)){
91
			$result['result'][] = array(
92
				'host'=>$row['ipDomain'],
93
				'isBlocked'=>$row['isBlocked'],
94
				'dns'=>$row['rDNS'],
95
				'status'=>unserialize($row['status']),
96
				'lastChanged'=>$row['lastStatusChangeTime'],
97
				'lastChecked'=>$row['lastUpdate'],
98
				);
99
		}
100
		$mysql->close();
101
		$localCache->set($cacheKey, $result);
102
		break;
103
104
	default:
105
		$result['status'] = 'no such method';
106
}
107
108
output();
109
110
function output($data = false){
111
	global $result;
112
	if($data!==false){
113
		echo(json_encode($data));
114
	}else{
115
		echo(json_encode($result));
116
	}
117
	exit();
118
}