<commit_before><?php

/* Start Sessions */
session_start();

/* define root uri */

$ROOT_URI = explode('/', $_SERVER['PHP_SELF']);
array_pop($ROOT_URI);
$ROOT_URI = implode('/', $ROOT_URI);
define('ROOT_URI', $ROOT_URI);

/* define DS */

define('DS', DIRECTORY_SEPARATOR);

/* require external files */

if(!file_exists('vendor' . DS . 'autoload.php'))
	die('Run composer update first. View https://github.com/zulfajuniadi/PHP-REST-Server for more info');
require_once('vendor' . DS . 'autoload.php');

if(!file_exists('config.php'))
	die('config.php not found. Have you renamed the config.php.default to config.php?');

/* Require Config File */

$config = array();
require_once('config.php');

$default_config = array();
$default_config['debug'] = true;
$default_config['session_expiry'] = 60 * 60 * 4;
$default_config['username'] = 'admin';
$default_config['password'] = '<PASSWORD>';
$default_config['timezone'] = 'UTC';
$default_config['db_conn'] = 'sqlite:db/database.sqlite3';
$default_config['db_user'] = null;
$default_config['db_pass'] = null;
$default_config['default_sql_limit'] = array(0, 25);
$default_config['rate_limit'] = 100;
$config = array_merge($default_config, $config);

if(file_exists('config.php.default') && $config['debug'] === false)
	die('Please remove the config.php.default.');

require_once('utils.php');

/* make sure admin pass has changed */

if($config['password'] === '<PASSWORD>')
	die('Change the password in config.php');

/* setup database */

use RedBean_Facade as R;
R::setup($config['db_conn'], $config['db_user'], $config['db_pass']);
R::$writer->setUseCache(false);
RedBean_OODBBean::setFlagBeautifulColumnNames(false);

/* app start */

if($config['debug'] === false) {
	ini_set('display_errors', '0');
}

$app = new \Slim\Slim(array(
	'debug' => $config['debug'],
	'templates.path' => 'templates'
));

/* Middlewares */

$r = new Util($app);

/* load hooks */

$r->loadHooks();

function API(){
	$app = \Slim\Slim::getInstance();
	$app->view(new \JsonApiView());
	$app->add(new \JsonApiMiddleware());
	$app->response->headers->set('Content-Type', 'application/json');
	$app->response->headers->set('Access-Control-Allow-Methods', 'GET,HEAD,POST,PUT,DELETE,OPTIONS');
	$app->response->headers->set('Access-Control-Allow-Headers', 'Auth-Token,Content-Type');
	$app->response->headers->set('Access-Control-Allow-Origin', '*');
}

function RATELIMITER() {
	$app = \Slim\Slim::getInstance();
	$uri = array_values(array_filter(explode('/', $app->request->getResourceUri())));
	$r = new Util($app);

	if($uri[0] === 'manage' && $uri[1] === 'packages') {
		return true;
	}
	if($r->checkLimit($uri[0]) === false) {
		return $r->respond(503, 'LIMIT EXCEEDED', false);
	}
}

function CHECKTOKEN() {
	$app = \Slim\Slim::getInstance();
	$uri = array_values(array_filter(explode('/', $app->request->getResourceUri())));
	$r = new Util($app);
	$token = $app->request->headers->get('Auth-Token');
	if($uri[0] === 'manage' && $uri[1] === 'packages') {<commit_msg>added cors headers to slim<commit_after><?php

/* Start Sessions */
session_start();

/* define root uri */

$ROOT_URI = explode('/', $_SERVER['PHP_SELF']);
array_pop($ROOT_URI);
$ROOT_URI = implode('/', $ROOT_URI);
define('ROOT_URI', $ROOT_URI);

/* define DS */

define('DS', DIRECTORY_SEPARATOR);

/* require external files */

if(!file_exists('vendor' . DS . 'autoload.php'))
	die('Run composer update first. View https://github.com/zulfajuniadi/PHP-REST-Server for more info');
require_once('vendor' . DS . 'autoload.php');

if(!file_exists('config.php'))
	die('config.php not found. Have you renamed the config.php.default to config.php?');

/* Require Config File */

$config = array();
require_once('config.php');

$default_config = array();
$default_config['debug'] = true;
$default_config['session_expiry'] = 60 * 60 * 4;
$default_config['username'] = 'admin';
$default_config['password'] = '<PASSWORD>';
$default_config['timezone'] = 'UTC';
$default_config['db_conn'] = 'sqlite:db/database.sqlite3';
$default_config['db_user'] = null;
$default_config['db_pass'] = null;
$default_config['default_sql_limit'] = array(0, 25);
$default_config['rate_limit'] = 100;
$config = array_merge($default_config, $config);

if(file_exists('config.php.default') && $config['debug'] === false)
	die('Please remove the config.php.default.');

require_once('utils.php');

/* make sure admin pass has changed */

if($config['password'] === '<PASSWORD>')
	die('Change the password in config.php');

/* setup database */

use RedBean_Facade as R;
R::setup($config['db_conn'], $config['db_user'], $config['db_pass']);
R::$writer->setUseCache(false);
RedBean_OODBBean::setFlagBeautifulColumnNames(false);

/* app start */

if($config['debug'] === false) {
	ini_set('display_errors', '0');
}

$app = new \Slim\Slim(array(
	'debug' => $config['debug'],
	'templates.path' => 'templates'
));

/* Middlewares */

$r = new Util($app);

/* load hooks */

$r->loadHooks();

function API(){
	$app = \Slim\Slim::getInstance();
	$app->view(new \JsonApiView());
	$app->add(new \JsonApiMiddleware());
	$app->response->headers->set('Content-Type', 'application/json');
	$app->response->headers->set('Access-Control-Allow-Methods', 'GET,HEAD,POST,PUT,DELETE,OPTIONS');
	$app->response->headers->set('Access-Control-Allow-Headers', 'Auth-Token,Content-Type');
	$app->response->headers->set('Access-Control-Allow-Origin', '*');
	$app->response->headers->set('Access-Control-Allow-Credentials', 'true');
}

function RATELIMITER() {
	$app = \Slim\Slim::getInstance();
	$uri = array_values(array_filter(explode('/', $app->request->getResourceUri())));
	$r = new Util($app);

	if($uri[0] === 'manage' && $uri[1] === 'packages') {
		return true;
	}
	if($r->checkLimit($uri[0]) === false) {
		return $r->respond(503, 'LIMIT EXCEEDED', false);
	}
}

function CHECKTOKEN() {
	$app = \Slim\Slim::getInstance();
	$uri = array_values(array_filter(explode('/', $app->request->getResourceUri())));
	$r = new Util($app);
	$token = $app->request->headers->get('Auth-Token');
	if($uri[0] === 'manage' && $uri[1] === 'packages') {
{'fraction_non_alphanumeric': 0.22467105263157894, 'fraction_numerical': 0.006907894736842105, 'mean_word_length': 6.005760368663594, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 64, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6659874', 'n_tokens_mistral': 2166, 'n_tokens_neox': 2134, 'n_words': 384}