Initial import

This commit is contained in:
flash 2022-07-03 23:14:15 +00:00
commit 1448343a7d
6 changed files with 74 additions and 0 deletions

1
.gitattributes vendored Normal file
View file

@ -0,0 +1 @@
* text=auto

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
/.debug
/config/config.ini

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "lib/index"]
path = lib/index
url = https://github.com/flashwave/index.git

31
awaki.php Normal file
View file

@ -0,0 +1,31 @@
<?php
namespace Awaki;
use Index\Autoloader;
use Index\Environment;
use Index\Data\ConnectionFailedException;
use Index\Data\DbTools;
define('AWK_STARTUP', microtime(true));
define('AWK_ROOT', __DIR__);
define('AWK_DEBUG', is_file(AWK_ROOT . '/.debug'));
define('AWK_DIR_SRC', AWK_ROOT . '/src');
define('AWK_DIR_LIB', AWK_ROOT . '/lib');
define('AWK_DIR_PUB', AWK_ROOT . '/public');
define('AWK_DIR_CFG', AWK_ROOT . '/config');
require_once AWK_DIR_LIB . '/index/index.php';
Autoloader::addNamespace(__NAMESPACE__, AWK_DIR_SRC);
Environment::setDebug(AWK_DEBUG);
$config = parse_ini_file(AWK_DIR_CFG . '/config.ini');
if($config === false)
die('Config sux.');
try {
$db = DbTools::create($config['dsn']);
} catch(ConnectionFailedException $ex) {
echo '<h3>Unable to connect to database</h3>';
die($ex->getMessage());
}

1
lib/index Submodule

@ -0,0 +1 @@
Subproject commit 8a5423fea397e2f2adca0b9f46d1e5c21fd13c44

36
public/index.php Normal file
View file

@ -0,0 +1,36 @@
<?php
namespace Awaki;
use Index\StringBuilder;
use Index\Data\DbType;
use Index\Http\HttpFx;
require_once __DIR__ . '/../awaki.php';
$router = new HttpFx;
$router->use('/', function($response) {
$response->setPoweredBy('Awaki+Index');
});
$router->get('/', function() {
$body = '<!doctype html>';
$body .= '<title>Awaki</title>';
$body .= 'Redirect service - OK';
return $body;
});
$router->get('/:id', function($response, $request, $id) use ($db) {
$getInfo = $db->prepare('SELECT `redir_url` FROM `awk_redirects` WHERE `redir_id` = ? OR `redir_vanity` = ?');
$getInfo->addParameter(1, $id, DbType::INTEGER);
$getInfo->addParameter(2, $id, DbType::STRING);
$getInfo->execute();
$info = $getInfo->getResult();
if(!$info->next())
return 404;
$response->redirect($info->getString(0));
});
$router->dispatch();