Newer
Older
<?php
namespace SmartData\Config
{
// CAUTION: Pay attention to changing these parameters
require_once( __DIR__ . '/SmartData.php');
use \SmartData\SmartData;
class Config_Common
{
const MYSQL_SEVERNAME = 'localhost';
const MYSQL_PORT = 3306;
Roberto Milton Scheffel
committed
const MYSQL_USERNAME = 'smartdata';
Roberto Milton Scheffel
committed
const MYSQL_SUPERUSER = 'smartdata_admin';
const CASSANDRA_SERVERNAME = 'localhost';
const CASSANDRA_PORT = 9042;
Roberto Milton Scheffel
committed
const CASSANDRA_SUPERUSER = 'cassandra';
const CASSANDRA_MAX_ROW_SIZE = 2000000000; // (Two billion - The max is 2^31)
Roberto Milton Scheffel
committed
const POINTS_LIMIT = 2000; // 84600 to 200000
Roberto Milton Scheffel
committed
// maximum amount of points to retrieval
// 86400 corresponds to a half day with resolution of one second
const ADMIN_EMAIL = array('root@lisha.ufsc.br');
const PUBLIC_DOMAIN = 'public'; // default domain (public series)
const DEFAULT_USERNAME = 'public'; // cassandra default user (PUBLIC)
const DEFAULT_PASSWORD = ''; // cassandra default user's password
const TIMEZONE = 'America/Sao_Paulo';
const HYSTERICALLY_DEBUGGED = false;
const DEBUGGED = array(
'SmartData\Backend' => self::HYSTERICALLY_DEBUGGED || false,
'SmartData\Credentials' => self::HYSTERICALLY_DEBUGGED || false,
'SmartData\SmartData' => self::HYSTERICALLY_DEBUGGED || false,
'SmartData\Series' => self::HYSTERICALLY_DEBUGGED || false,
'SmartData\Unpackable' => self::HYSTERICALLY_DEBUGGED || false,
'SmartData\Logger' => false,
);
const LOG_FILE = '/smartdata/log/api.log';
Roberto Milton Scheffel
committed
const TEMP_DIR = "/smartdata/bin/tmp";
const FATAL_ERROR_REPORT = true;
const FATAL_ERROR_DIR = __DIR__.'/fatal_error/';
const ACCESSIBLE_WITHOUT_SSL = array(
self::PUBLIC_DOMAIN
,'hydro'
,'tutorial'
);
/*---------------------------------------------------------------------------------------------------------------+
| V.1.0: This was the first version after we atopped using KairosDB as a platform |
| V.1.1: This version has the same API of version 1.0, however the structure and |
| the DataBase design are totally different. The dev number works fine in this version |
+---------------------------------------------------------------------------------------------------------------*/
public const VERSION_1_0 = (1 << 4) | (0 << 0);
public const VERSION_1_1 = (1 << 4) | (1 << 0);
public const DEFAULT_VERSION = self::VERSION_1_1;
public const DEVELOPMENT = PHP_INT_MAX;
private const _VERSIONS = array (
self::VERSION_1_0 => '/api/v1_0/',
self::VERSION_1_1 => '/api/v1_1/'
);
Roberto Milton Scheffel
committed
private const _CERT_GW_LISHA = 'A7B64D415BD3E97B';
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
public static function api_version() {
global $__FORCE_VERSION;
if(isset($__FORCE_VERSION))
return $__FORCE_VERSION;
//switch (REQUEST_CERT) {
// case self::_CERT_GW_LISHA:
// return self::VERSION_1_1;
// default: break;
//}
foreach (self::_VERSIONS as $version => $url_pattern) {
if(self::check_version($url_pattern))
return $version;
}
return self::DEFAULT_VERSION; //default version
}
private static function check_version(string $version) {
global $FORCE_VERSION;
return (strpos($_SERVER['REQUEST_URI']??$FORCE_VERSION??'', $version) !== false);
}
public static function pre_init() {
define('REQUEST_HTTPS' , (($_SERVER['HTTPS'] ?? false) == 'on'));
define('REQUEST_CERT' , (REQUEST_HTTPS and ($_SERVER['SSL_CLIENT_VERIFY'] ?? false) == 'SUCCESS'));
define('REQUEST_SERIAL', (REQUEST_CERT) ? @$_SERVER['SSL_CLIENT_M_SERIAL'] : '');
define('REQUEST_URI' , isset($_SERVER["REQUEST_URI"])?strtok(basename($_SERVER["REQUEST_URI"]),'?'):'{local}');
define('REQUEST_DBG' , ('HTTP'.((REQUEST_HTTPS)?'S':'').':'.REQUEST_URI.' crt:{'.REQUEST_SERIAL.'}'));
}
public static function init() {
date_default_timezone_set(Config_Common::TIMEZONE);
}
}
Config_Common::pre_init();
## Configuration of API version 1.0 ###############################################
class Config_V1_0 extends Config_Common
{
//const HYSTERICALLY_DEBUGGED = true;
const MYSQL_DBNAME = 'smartdata';
const CASSANDRA_KEYSPACE = 'smartdata_1';
const CONFIDENCE_ASSIGNER = __DIR__ . '/confidence_assigner/assigner0';
protected const _MYSQL_TABLE = array (
SmartData::STATIC_VERSION => 'series',
SmartData::MOBILE_VERSION => 'series'
);
}
## Configuration of API version 1.1 ###############################################
class Config_V1_1 extends Config_Common
{
const HYSTERICALLY_DEBUGGED = true;
const MYSQL_DBNAME = 'smartdata_v1';
const CASSANDRA_KEYSPACE = 'smartdata_v1';
protected const _MYSQL_TABLE = array (
SmartData::STATIC_VERSION => 'series',
SmartData::MOBILE_VERSION => 'trackers'
);
}
###################################################################################
switch (Config_Common::api_version()) {
case Config_Common::VERSION_1_0: class MetaConfig extends Config_V1_0 {} break;
case Config_Common::VERSION_1_1: class MetaConfig extends Config_V1_1 {} break;
default:
die ("Bad API version!\n");
}
trait ConfigGetters
{
public function MySQL_Table($version) : string {
if(isset(self::_MYSQL_TABLE[$version]))
return self::MYSQL_DBNAME.'.'.self::_MYSQL_TABLE[$version];
else
die ("Unable to select mysql table\n");
}
}
Config_Common::init();
}
namespace SmartData
{
class Config_Common extends Config\Config_Common {};
class Config {
public static function config(){
switch (Config_Common::api_version()) {
case Config_Common::VERSION_1_0:
return new class() extends Config\Config_V1_0 {
use Config\ConfigGetters;
};
break;
case Config_Common::VERSION_1_1:
return new class() extends Config\Config_V1_1 {
use Config\ConfigGetters;
};
break;
default:
die ("Bad API version!\n");
}
}
};
}