Compare commits

..

No commits in common. "main" and "0d1c3e63d883897a4262f5483610583ec936529a" have entirely different histories.

6 changed files with 89 additions and 113 deletions

View File

@ -1,15 +0,0 @@
root = true
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = tab
[*.{toml,json,yml,yaml}]
indent_size = 4
indent_style = space
[*.nix]
indent_size = 2
indent_style = space

View File

@ -9,6 +9,9 @@ use ix\Container\Container;
use ix\Controller\Controller;
use ix\Application\Application;
/* Language initialization */
(new \i18n(IX_BASE . '/lang/{LANGUAGE}.ini', IX_BASE . '/cache/lang', 'en'))->init();
/* Container hooks */
HookMachine::add([Container::class, 'construct'], '\ix\Container\ContainerHooksHtmlRenderer::hookContainerHtmlRenderer');
HookMachine::add([Container::class, 'construct'], '\ix\Container\ContainerHooksSession::hookContainerSession');
@ -23,6 +26,7 @@ HookMachine::add([\NeotelApply\IndexController::class, 'sendAlert'], '\NeotelApp
/* Application routes */
HookMachine::add([Application::class, 'create_app', 'routeRegister'], (function ($key, $app) {
$app->any('/', \NeotelApply\IndexController::class);
$app->redirect('/', '/register', 301);
$app->any('/register', \NeotelApply\IndexController::class);
return $app;
}));

77
composer.lock generated
View File

@ -113,26 +113,31 @@
},
{
"name": "graham-campbell/result-type",
"version": "v1.0.2",
"version": "v1.0.1",
"source": {
"type": "git",
"url": "https://github.com/GrahamCampbell/Result-Type.git",
"reference": "84afea85c6841deeea872f36249a206e878a5de0"
"reference": "7e279d2cd5d7fbb156ce46daada972355cea27bb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/GrahamCampbell/Result-Type/zipball/84afea85c6841deeea872f36249a206e878a5de0",
"reference": "84afea85c6841deeea872f36249a206e878a5de0",
"url": "https://api.github.com/repos/GrahamCampbell/Result-Type/zipball/7e279d2cd5d7fbb156ce46daada972355cea27bb",
"reference": "7e279d2cd5d7fbb156ce46daada972355cea27bb",
"shasum": ""
},
"require": {
"php": "^7.0 || ^8.0",
"phpoption/phpoption": "^1.8"
"php": "^7.0|^8.0",
"phpoption/phpoption": "^1.7.3"
},
"require-dev": {
"phpunit/phpunit": "^6.5.14 || ^7.5.20 || ^8.5.19 || ^9.5.8"
"phpunit/phpunit": "^6.5|^7.5|^8.5|^9.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"autoload": {
"psr-4": {
"GrahamCampbell\\ResultType\\": "src/"
@ -145,7 +150,7 @@
"authors": [
{
"name": "Graham Campbell",
"email": "hello@gjcampbell.co.uk"
"email": "graham@alt-three.com"
}
],
"description": "An Implementation Of The Result Type",
@ -158,7 +163,7 @@
],
"support": {
"issues": "https://github.com/GrahamCampbell/Result-Type/issues",
"source": "https://github.com/GrahamCampbell/Result-Type/tree/v1.0.2"
"source": "https://github.com/GrahamCampbell/Result-Type/tree/v1.0.1"
},
"funding": [
{
@ -170,7 +175,7 @@
"type": "tidelift"
}
],
"time": "2021-08-28T21:34:50+00:00"
"time": "2020-04-13T13:17:36+00:00"
},
{
"name": "nikic/fast-route",
@ -503,29 +508,29 @@
},
{
"name": "phpoption/phpoption",
"version": "1.8.0",
"version": "1.7.5",
"source": {
"type": "git",
"url": "https://github.com/schmittjoh/php-option.git",
"reference": "5455cb38aed4523f99977c4a12ef19da4bfe2a28"
"reference": "994ecccd8f3283ecf5ac33254543eb0ac946d525"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/schmittjoh/php-option/zipball/5455cb38aed4523f99977c4a12ef19da4bfe2a28",
"reference": "5455cb38aed4523f99977c4a12ef19da4bfe2a28",
"url": "https://api.github.com/repos/schmittjoh/php-option/zipball/994ecccd8f3283ecf5ac33254543eb0ac946d525",
"reference": "994ecccd8f3283ecf5ac33254543eb0ac946d525",
"shasum": ""
},
"require": {
"php": "^7.0 || ^8.0"
"php": "^5.5.9 || ^7.0 || ^8.0"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.4.1",
"phpunit/phpunit": "^6.5.14 || ^7.0.20 || ^8.5.19 || ^9.5.8"
"phpunit/phpunit": "^4.8.35 || ^5.7.27 || ^6.5.6 || ^7.0 || ^8.0 || ^9.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.8-dev"
"dev-master": "1.7-dev"
}
},
"autoload": {
@ -544,7 +549,7 @@
},
{
"name": "Graham Campbell",
"email": "hello@gjcampbell.co.uk"
"email": "graham@alt-three.com"
}
],
"description": "Option Type for PHP",
@ -556,7 +561,7 @@
],
"support": {
"issues": "https://github.com/schmittjoh/php-option/issues",
"source": "https://github.com/schmittjoh/php-option/tree/1.8.0"
"source": "https://github.com/schmittjoh/php-option/tree/1.7.5"
},
"funding": [
{
@ -568,7 +573,7 @@
"type": "tidelift"
}
],
"time": "2021-08-28T21:27:29+00:00"
"time": "2020-07-20T17:29:33+00:00"
},
{
"name": "psr/container",
@ -1647,12 +1652,12 @@
"source": {
"type": "git",
"url": "https://github.com/u1f408/ix-framework.git",
"reference": "7200a81580f48ec2b97c3c0d6aa1f1f94e983df8"
"reference": "1f9c077bef1724dd3faec58c33a5c540df371187"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/u1f408/ix-framework/zipball/7200a81580f48ec2b97c3c0d6aa1f1f94e983df8",
"reference": "7200a81580f48ec2b97c3c0d6aa1f1f94e983df8",
"url": "https://api.github.com/repos/u1f408/ix-framework/zipball/1f9c077bef1724dd3faec58c33a5c540df371187",
"reference": "1f9c077bef1724dd3faec58c33a5c540df371187",
"shasum": ""
},
"require": {
@ -1694,7 +1699,7 @@
"source": "https://github.com/u1f408/ix-framework/tree/main",
"issues": "https://github.com/u1f408/ix-framework/issues"
},
"time": "2021-09-02T02:27:34+00:00"
"time": "2021-08-18T16:37:35+00:00"
},
{
"name": "u1f408/phphelpers",
@ -2344,16 +2349,16 @@
},
{
"name": "phpstan/phpstan",
"version": "0.12.97",
"version": "0.12.96",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan.git",
"reference": "a8867e63a00e606589faf8d3613164f20722c4ee"
"reference": "a98bdc51318f20fcae8c953d266f81a70254917f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/a8867e63a00e606589faf8d3613164f20722c4ee",
"reference": "a8867e63a00e606589faf8d3613164f20722c4ee",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/a98bdc51318f20fcae8c953d266f81a70254917f",
"reference": "a98bdc51318f20fcae8c953d266f81a70254917f",
"shasum": ""
},
"require": {
@ -2384,7 +2389,7 @@
"description": "PHPStan - PHP Static Analysis Tool",
"support": {
"issues": "https://github.com/phpstan/phpstan/issues",
"source": "https://github.com/phpstan/phpstan/tree/0.12.97"
"source": "https://github.com/phpstan/phpstan/tree/0.12.96"
},
"funding": [
{
@ -2404,7 +2409,7 @@
"type": "tidelift"
}
],
"time": "2021-09-01T10:51:52+00:00"
"time": "2021-08-21T11:55:13+00:00"
},
{
"name": "phpunit/php-code-coverage",
@ -2726,16 +2731,16 @@
},
{
"name": "phpunit/phpunit",
"version": "9.5.9",
"version": "9.5.8",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "ea8c2dfb1065eb35a79b3681eee6e6fb0a6f273b"
"reference": "191768ccd5c85513b4068bdbe99bb6390c7d54fb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/ea8c2dfb1065eb35a79b3681eee6e6fb0a6f273b",
"reference": "ea8c2dfb1065eb35a79b3681eee6e6fb0a6f273b",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/191768ccd5c85513b4068bdbe99bb6390c7d54fb",
"reference": "191768ccd5c85513b4068bdbe99bb6390c7d54fb",
"shasum": ""
},
"require": {
@ -2813,7 +2818,7 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
"source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.9"
"source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.8"
},
"funding": [
{
@ -2825,7 +2830,7 @@
"type": "github"
}
],
"time": "2021-08-31T06:47:40+00:00"
"time": "2021-07-31T15:17:34+00:00"
},
{
"name": "sebastian/cli-parser",

View File

@ -8,57 +8,46 @@ use Serhiy\Pushover\Api\Message\Message as PushoverMessage;
use Serhiy\Pushover\Api\Message\Notification as PushoverNotification;
final class ApplicationAlerters {
/**
* @param string[] $key Hook key (unused)
* @param mixed[] $params Array of [user, tilde, message]
* @return mixed[] Array of [user, tilde, message]
*/
public static function pushover(array $key, array $params): array {
list($user, $tilde, $message) = $params;
/**
* @param string[] $key Hook key (unused)
* @param mixed[] $params Array of [user, tilde, message]
* @return mixed[] Array of [user, tilde, message]
*/
public static function pushover(array $key, array $params): array {
list($user, $tilde, $message) = $params;
$application = new Pushover\Application($_ENV[IX_ENVBASE . '_PUSHOVER_API_TOKEN']);
$pushovermessage = new PushoverMessage(
"from {$user} @ {$tilde}\n---\n{$message}",
'new neotel application',
);
$application = new Pushover\Application($_ENV[IX_ENVBASE . '_PUSHOVER_API_TOKEN']);
$recipient = new Pushover\Recipient($_ENV[IX_ENVBASE . '_PUSHOVER_USER_KEY']);
$pushovermessage = new PushoverMessage(
"from {$user}@{$tilde}\n> {$message}",
'new neotel application',
);
$notification = new PushoverNotification($application, $recipient, $pushovermessage);
$response = $notification->push();
$pushoverusers = explode(',', $_ENV[IX_ENVBASE . '_PUSHOVER_USER_KEYS']);
foreach ($pushoverusers as $userkey) {
$recipient = new Pushover\Recipient($userkey);
$notification = new PushoverNotification($application, $recipient, $pushovermessage);
$response = $notification->push();
}
return [$user, $tilde, $message];
}
return [$user, $tilde, $message];
}
/**
* @param string[] $key Hook key (unused)
* @param mixed[] $params Array of [user, tilde, message]
* @return mixed[] Array of [user, tilde, message]
*/
public static function discord(array $key, array $params): array {
list($user, $tilde, $message) = $params;
/**
* @param string[] $key Hook key (unused)
* @param mixed[] $params Array of [user, tilde, message]
* @return mixed[] Array of [user, tilde, message]
*/
public static function discord(array $key, array $params): array {
list($user, $tilde, $message) = $params;
$data = json_encode([
"content" => "From `{$user}@{$tilde}` \n> {$message}",
]);
$repl_from = ['\\', '-', '#', '*', '+', '`', '.', '[', ']', '(', ')', '!', '&', '<', '>', '_', '{', '}'];
$repl_to = ['\\\\', '\-', '\#', '\*', '\+', '\`', '\.', '\[', '\]', '\(', '\)', '\!', '\&', '\<', '\>', '\_', '\{', '\}'];
$curl_opts = [
CURLOPT_HTTPHEADER => ["Content-Type: application/json"],
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $data,
];
$x_user = preg_replace('/\R/', ' ', str_replace($repl_from, $repl_to, $user));
$x_tilde = preg_replace('/\R/', ' ', str_replace($repl_from, $repl_to, $tilde));
$x_message = preg_replace('/\R/', ' ', str_replace($repl_from, $repl_to, $message));
$response = CurlHelpers::fetchUrl($_ENV[IX_ENVBASE . "_DISCORD_WEBHOOK_URL"], $curl_opts, true);
$data = json_encode([
"content" => "**User:**\n> {$x_user}\n**Tilde/Pubnix:**\n> {$x_tilde}\n**Message:**\n> {$x_message}",
]);
$curl_opts = [
CURLOPT_HTTPHEADER => ["Content-Type: application/json"],
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $data,
];
$response = CurlHelpers::fetchUrl($_ENV[IX_ENVBASE . "_DISCORD_WEBHOOK_URL"], $curl_opts, true);
return [$user, $tilde, $message];
}
return [$user, $tilde, $message];
}
}

View File

@ -38,14 +38,13 @@ class Configuration {
// Require an environment
$dotenv->required('APP_ENV')->allowedValues(['development', 'test', 'production']);
$dotenv->ifPresent('APP_BASE_PATH')->notEmpty();
// Require a session cookie
$dotenv->required(IX_ENVBASE . '_SESSIONCOOKIE')->notEmpty();
// Pushover application and user keys
$dotenv->required(IX_ENVBASE . '_PUSHOVER_API_TOKEN')->notEmpty();
$dotenv->required(IX_ENVBASE . '_PUSHOVER_USER_KEYS')->notEmpty();
$dotenv->required(IX_ENVBASE . '_PUSHOVER_USER_KEY')->notEmpty();
// Discord webhook URL
$dotenv->required(IX_ENVBASE . '_DISCORD_WEBHOOK_URL')->notEmpty();

View File

@ -84,20 +84,17 @@ class IndexController extends Controller {
return $response->withHeader('Location', '/register');
}
// Get the numbers from the session, and then reset them
$numbers = array_map((function($i) { return intval($i); }), explode(',', $session->session_data['numbers']));
unset($session->session_data['numbers']);
$form_values = (array) $request->getParsedBody();
$query_values = (array) $request->getParsedBody();
// Check CSRF
$csrf_token = null;
if (array_key_exists('_csrf', $form_values)) $csrf_token = trim($form_values['_csrf']);
$this->container->get('csrf')->check('csrf', $csrf_token);
if (array_key_exists('_csrf', $query_values)) $csrf_token = trim($query_values['_csrf']);
$this->container->get('csrf')->check('csrf', $csrf_token);
// Check the math question
$given_sum = null;
if (array_key_exists('verify', $form_values)) $given_sum = intval(trim($form_values['verify']));
if (array_key_exists('verify', $query_values)) $given_sum = intval(trim($query_values['verify']));
if ($given_sum != $numbers[0] + $numbers[1]) {
return $this->requestGET($request, $response, array_merge($args, [
'message' => 'The provided verification was incorrect.',
@ -106,14 +103,11 @@ class IndexController extends Controller {
// We're good, send the notifications
HookMachine::execute([self::class, 'sendAlert'], [
$form_values['username'],
$form_values['tilde'],
$form_values['message'] ?? '[no message provided]',
$query_values['username'],
$query_values['tilde'],
$query_values['message'] ?? '[no message provided]',
]);
// Destroy the session
$session->destroy();
// And return a success message
$html = $this->container->get('html');
$response->getBody()->write($html->renderDocument(