mirror of
https://github.com/kevachat/npsapp.git
synced 2025-01-29 16:24:17 +00:00
implement sessions
This commit is contained in:
parent
17d677ba06
commit
99d539bbf4
@ -19,6 +19,29 @@
|
|||||||
"size":3072,
|
"size":3072,
|
||||||
"line":1024
|
"line":1024
|
||||||
},
|
},
|
||||||
|
"session":
|
||||||
|
{
|
||||||
|
"captcha":
|
||||||
|
{
|
||||||
|
"length":3,
|
||||||
|
"chars":"1234567890",
|
||||||
|
"dimensions":
|
||||||
|
{
|
||||||
|
"width":100,
|
||||||
|
"height":40
|
||||||
|
},
|
||||||
|
"background":
|
||||||
|
{
|
||||||
|
"r":0,
|
||||||
|
"g":0,
|
||||||
|
"b":0
|
||||||
|
},
|
||||||
|
"ascii":
|
||||||
|
{
|
||||||
|
"width": 50
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"action":
|
"action":
|
||||||
{
|
{
|
||||||
"welcome":
|
"welcome":
|
||||||
@ -72,27 +95,6 @@
|
|||||||
"template":"[{time}] handler {host}:{port} captcha: {code} sent: {sent} length: {size} bytes {data}"
|
"template":"[{time}] handler {host}:{port} captcha: {code} sent: {sent} length: {size} bytes {data}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"captcha":
|
|
||||||
{
|
|
||||||
"enabled":true,
|
|
||||||
"length":3,
|
|
||||||
"chars":"1234567890",
|
|
||||||
"dimensions":
|
|
||||||
{
|
|
||||||
"width":100,
|
|
||||||
"height":40
|
|
||||||
},
|
|
||||||
"background":
|
|
||||||
{
|
|
||||||
"r":0,
|
|
||||||
"g":0,
|
|
||||||
"b":0
|
|
||||||
},
|
|
||||||
"ascii":
|
|
||||||
{
|
|
||||||
"width": 50
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -15,8 +15,8 @@ $config = json_decode(
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Init session code
|
// Init session
|
||||||
$code = null;
|
$session = [];
|
||||||
|
|
||||||
// Init server
|
// Init server
|
||||||
$server = new \Yggverse\Nps\Server(
|
$server = new \Yggverse\Nps\Server(
|
||||||
@ -33,47 +33,43 @@ $server->setWelcome(
|
|||||||
): ?string
|
): ?string
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
global $code;
|
global $session;
|
||||||
|
|
||||||
// Build captcha on enabled
|
// Init session
|
||||||
if ($config->nps->captcha->enabled)
|
$session[$connect] =
|
||||||
{
|
[
|
||||||
$captcha = new \Gregwar\Captcha\CaptchaBuilder(
|
'time' => time(),
|
||||||
null,
|
'code' => null
|
||||||
new \Gregwar\Captcha\PhraseBuilder(
|
];
|
||||||
$config->nps->captcha->length,
|
|
||||||
$config->nps->captcha->chars
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$captcha->setBackgroundColor(
|
// Build captcha
|
||||||
$config->nps->captcha->background->r,
|
$captcha = new \Gregwar\Captcha\CaptchaBuilder(
|
||||||
$config->nps->captcha->background->g,
|
null,
|
||||||
$config->nps->captcha->background->b
|
new \Gregwar\Captcha\PhraseBuilder(
|
||||||
);
|
$config->nps->session->captcha->length,
|
||||||
|
$config->nps->session->captcha->chars
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
$captcha->build(
|
$captcha->setBackgroundColor(
|
||||||
$config->nps->captcha->dimensions->width,
|
$config->nps->session->captcha->background->r,
|
||||||
$config->nps->captcha->dimensions->height
|
$config->nps->session->captcha->background->g,
|
||||||
);
|
$config->nps->session->captcha->background->b
|
||||||
|
);
|
||||||
|
|
||||||
// Set captcha value to the session code
|
$captcha->build(
|
||||||
$code = $captcha->getPhrase();
|
$config->nps->session->captcha->dimensions->width,
|
||||||
|
$config->nps->session->captcha->dimensions->height
|
||||||
|
);
|
||||||
|
|
||||||
// Create ASCII confirmation code
|
// Set captcha value to the session code
|
||||||
$image = new \Ixnode\PhpCliImage\CliImage(
|
$session[$connect]['captcha'] = $captcha->getPhrase();
|
||||||
$captcha->get(),
|
|
||||||
$config->nps->captcha->ascii->width
|
|
||||||
);
|
|
||||||
|
|
||||||
$confirmation = PHP_EOL . $image->getAsciiString() . PHP_EOL;
|
// Create ASCII confirmation code
|
||||||
}
|
$image = new \Ixnode\PhpCliImage\CliImage(
|
||||||
|
$captcha->get(),
|
||||||
else
|
$config->nps->session->captcha->ascii->width
|
||||||
{
|
);
|
||||||
$confirmation = null;
|
|
||||||
$code = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Debug request on enabled
|
// Debug request on enabled
|
||||||
if ($config->nps->action->welcome->debug->enabled)
|
if ($config->nps->action->welcome->debug->enabled)
|
||||||
@ -97,7 +93,7 @@ $server->setWelcome(
|
|||||||
(string) date('c'),
|
(string) date('c'),
|
||||||
(string) parse_url($url, PHP_URL_HOST),
|
(string) parse_url($url, PHP_URL_HOST),
|
||||||
(string) parse_url($url, PHP_URL_PORT),
|
(string) parse_url($url, PHP_URL_PORT),
|
||||||
(string) is_null($code) ? '[off]' : $code
|
(string) $session[$connect]['captcha']
|
||||||
],
|
],
|
||||||
$config->nps->action->welcome->debug->template
|
$config->nps->action->welcome->debug->template
|
||||||
) . PHP_EOL
|
) . PHP_EOL
|
||||||
@ -108,7 +104,7 @@ $server->setWelcome(
|
|||||||
implode(
|
implode(
|
||||||
PHP_EOL,
|
PHP_EOL,
|
||||||
$config->nps->action->welcome->message
|
$config->nps->action->welcome->message
|
||||||
) . PHP_EOL . $confirmation
|
) . PHP_EOL . $image->getAsciiString() . PHP_EOL
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -121,7 +117,7 @@ $server->setPending(
|
|||||||
): ?string
|
): ?string
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
global $code;
|
global $session;
|
||||||
|
|
||||||
// Filter request
|
// Filter request
|
||||||
$request = trim(
|
$request = trim(
|
||||||
@ -152,15 +148,15 @@ $server->setPending(
|
|||||||
(string) parse_url($url, PHP_URL_HOST),
|
(string) parse_url($url, PHP_URL_HOST),
|
||||||
(string) parse_url($url, PHP_URL_PORT),
|
(string) parse_url($url, PHP_URL_PORT),
|
||||||
(string) $request,
|
(string) $request,
|
||||||
(string) is_null($code) ? '[off]' : $code
|
(string) $session[$connect]['captcha']
|
||||||
],
|
],
|
||||||
$config->nps->action->pending->debug->template
|
$config->nps->action->pending->debug->template
|
||||||
) . PHP_EOL
|
) . PHP_EOL
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return is_null($code) || $code == $request ? implode(PHP_EOL, $config->nps->action->pending->message->success) . PHP_EOL
|
return $session[$connect]['captcha'] == $request ? implode(PHP_EOL, $config->nps->action->pending->message->success) . PHP_EOL
|
||||||
: implode(PHP_EOL, $config->nps->action->pending->message->failure) . PHP_EOL;
|
: implode(PHP_EOL, $config->nps->action->pending->message->failure) . PHP_EOL;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -174,13 +170,18 @@ $server->setHandler(
|
|||||||
): ?string
|
): ?string
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
global $code;
|
global $session;
|
||||||
|
|
||||||
// Filter request
|
// Filter request
|
||||||
$request = trim(
|
$request = trim(
|
||||||
$request
|
$request
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Filter content
|
||||||
|
$content = trim(
|
||||||
|
$content
|
||||||
|
);
|
||||||
|
|
||||||
// @TODO save content in blockchain with kevacoin-php
|
// @TODO save content in blockchain with kevacoin-php
|
||||||
|
|
||||||
// Debug request on enabled
|
// Debug request on enabled
|
||||||
@ -209,17 +210,17 @@ $server->setHandler(
|
|||||||
(string) parse_url($url, PHP_URL_HOST),
|
(string) parse_url($url, PHP_URL_HOST),
|
||||||
(string) parse_url($url, PHP_URL_PORT),
|
(string) parse_url($url, PHP_URL_PORT),
|
||||||
(string) str_replace('%', '%%', $request),
|
(string) str_replace('%', '%%', $request),
|
||||||
(string) is_null($code) ? '[off]' : $code,
|
(string) $session[$connect]['captcha'],
|
||||||
(string) mb_strlen($content),
|
(string) mb_strlen($content),
|
||||||
(string) $content,
|
(string) PHP_EOL . $content,
|
||||||
],
|
],
|
||||||
$config->nps->action->handler->debug->template
|
$config->nps->action->handler->debug->template
|
||||||
) . PHP_EOL
|
) . PHP_EOL
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return is_null($code) || $code == $request ? implode(PHP_EOL, $config->nps->action->handler->message->success) . PHP_EOL
|
return $session[$connect]['captcha'] == $request ? implode(PHP_EOL, $config->nps->action->handler->message->success) . PHP_EOL
|
||||||
: implode(PHP_EOL, $config->nps->action->handler->message->failure) . PHP_EOL;
|
: implode(PHP_EOL, $config->nps->action->handler->message->failure) . PHP_EOL;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user