2016-07-31 01:32:37 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Hold the controller for chat related pages.
|
|
|
|
* @package Sakura
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Sakura\Controllers;
|
|
|
|
|
2016-08-10 16:10:57 +00:00
|
|
|
use Sakura\Chat\LinkInfo;
|
|
|
|
use Sakura\Chat\Settings;
|
|
|
|
use Sakura\Chat\URLResolver;
|
|
|
|
use Sakura\DB;
|
|
|
|
use Sakura\Session;
|
|
|
|
use Sakura\User;
|
|
|
|
|
2016-07-31 01:32:37 +00:00
|
|
|
/**
|
|
|
|
* Chat related controller.
|
|
|
|
* @package Sakura
|
|
|
|
* @author Julian van de Groep <me@flash.moe>
|
|
|
|
*/
|
|
|
|
class ChatController extends Controller
|
|
|
|
{
|
2016-08-10 16:10:57 +00:00
|
|
|
/**
|
|
|
|
* Middlewares!
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $middleware = [
|
|
|
|
'EnableCORS',
|
|
|
|
];
|
|
|
|
|
2016-08-05 02:35:37 +00:00
|
|
|
/**
|
|
|
|
* Redirects the user to the chat client.
|
|
|
|
*/
|
2016-12-04 16:33:52 +00:00
|
|
|
public function redirect(): string
|
2016-07-31 01:32:37 +00:00
|
|
|
{
|
2016-12-04 16:33:52 +00:00
|
|
|
return redirect(config('chat.webclient'));
|
2016-07-31 01:32:37 +00:00
|
|
|
}
|
|
|
|
|
2016-08-05 02:35:37 +00:00
|
|
|
/**
|
|
|
|
* Serves the settings for a Sakurako chat.
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-12-04 16:33:52 +00:00
|
|
|
public function settings(): string
|
2016-08-10 16:10:57 +00:00
|
|
|
{
|
|
|
|
$settings = new Settings;
|
|
|
|
$settings->loadStandard();
|
|
|
|
|
|
|
|
$emotes = DB::table('emoticons')
|
|
|
|
->get();
|
|
|
|
|
|
|
|
foreach ($emotes as $emote) {
|
|
|
|
$settings->addEmoticon([$emote->emote_string], $emote->emote_path, 1, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->json($settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolves urls.
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-12-04 16:33:52 +00:00
|
|
|
public function resolve(): string
|
2016-08-10 16:10:57 +00:00
|
|
|
{
|
|
|
|
$data = json_decode(file_get_contents('php://input'));
|
|
|
|
$info = new LinkInfo;
|
|
|
|
|
|
|
|
if (json_last_error() === JSON_ERROR_NONE) {
|
|
|
|
$info = URLResolver::resolve(
|
|
|
|
$data->Protocol ?? null,
|
|
|
|
$data->Slashes ?? null,
|
|
|
|
$data->Authority ?? null,
|
|
|
|
$data->Host ?? null,
|
|
|
|
$data->Port ?? null,
|
|
|
|
$data->Path ?? null,
|
|
|
|
$data->Query ?? null,
|
|
|
|
$data->Hash ?? null
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-09-10 14:10:26 +00:00
|
|
|
return $this->json($info);
|
2016-08-10 16:10:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles the authentication for a chat server.
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-12-04 16:33:52 +00:00
|
|
|
public function auth(): ?string
|
2016-07-31 01:32:37 +00:00
|
|
|
{
|
2016-12-04 16:33:52 +00:00
|
|
|
return null;
|
2016-07-31 01:32:37 +00:00
|
|
|
}
|
2016-08-10 16:10:57 +00:00
|
|
|
|
2016-09-10 14:10:26 +00:00
|
|
|
/**
|
|
|
|
* IRC page.
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-12-04 16:33:52 +00:00
|
|
|
public function irc(): ?string
|
2016-09-10 14:10:26 +00:00
|
|
|
{
|
2016-12-04 16:33:52 +00:00
|
|
|
return null;
|
2016-09-10 14:10:26 +00:00
|
|
|
}
|
|
|
|
|
2016-08-10 16:10:57 +00:00
|
|
|
/**
|
|
|
|
* Legacy auth, for SockLegacy. Remove when the old chat server finally dies.
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-12-04 16:33:52 +00:00
|
|
|
public function authLegacy(): string
|
2016-08-10 16:10:57 +00:00
|
|
|
{
|
|
|
|
$user = User::construct($_GET['arg1'] ?? null);
|
|
|
|
$session = new Session($_GET['arg2'] ?? null);
|
|
|
|
|
|
|
|
if ($session->validate($user->id)
|
2016-11-01 21:14:02 +00:00
|
|
|
&& !$user->activated
|
|
|
|
&& $user->verified
|
|
|
|
&& !$user->restricted) {
|
2016-08-10 16:10:57 +00:00
|
|
|
$hierarchy = $user->hierarchy();
|
2016-11-01 21:14:02 +00:00
|
|
|
$moderator = $user->perms->isMod || $user->perms->isAdmin ? 1 : 0;
|
|
|
|
$changeName = $user->perms->changeUsername ? 1 : 0;
|
|
|
|
$createChans = $user->perms->isAdmin ? 2 : (
|
|
|
|
$user->perms->isMod ? 1 : 0
|
2016-08-10 16:10:57 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// The single 0 in here is used to determine log access, which isn't supported by sakurako anymore since it
|
|
|
|
// required direct database access and the chat is databaseless now.
|
|
|
|
return "yes{$user->id}\n{$user->username}\n{$user->colour}\n{$hierarchy}\f{$moderator}\f0\f{$changeName}\f{$createChans}\f";
|
|
|
|
}
|
|
|
|
|
|
|
|
return "no";
|
|
|
|
}
|
2016-07-31 01:32:37 +00:00
|
|
|
}
|