This repository has been archived on 2024-06-26. You can view files and clone it, but cannot push or open issues or pull requests.
sakura/app/Controllers/ChatController.php

122 lines
3.1 KiB
PHP
Raw Normal View History

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\Perms;
use Sakura\Perms\Manage;
use Sakura\Perms\Site;
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-07-31 01:32:37 +00:00
public function redirect()
{
2016-08-10 16:10:57 +00:00
header('Location: ' . 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-07-31 01:32:37 +00:00
public function settings()
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
*/
public function resolve()
{
$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
);
}
return $info;
}
/**
* Handles the authentication for a chat server.
* @return string
*/
public function auth()
2016-07-31 01:32:37 +00:00
{
return;
}
2016-08-10 16:10:57 +00:00
/**
* Legacy auth, for SockLegacy. Remove when the old chat server finally dies.
* @return string
*/
public function authLegacy()
{
$user = User::construct($_GET['arg1'] ?? null);
$session = new Session($_GET['arg2'] ?? null);
if ($session->validate($user->id)
&& !$user->permission(Site::DEACTIVATED)
&& !$user->permission(Site::RESTRICTED)) {
$hierarchy = $user->hierarchy();
$moderator = $user->permission(Manage::USE_MANAGE, Perms::MANAGE) ? 1 : 0;
$changeName = $user->permission(Site::CHANGE_USERNAME) ? 1 : 0;
$createChans = $user->permission(Site::MULTIPLE_GROUPS) ? 2 : (
$user->permission(Site::CREATE_GROUP) ? 1 : 0
);
// 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
}