Maintenance (#719)

This commit is contained in:
n1rwana 2022-09-17 00:19:46 +03:00 committed by GitHub
parent ed7faa4a16
commit 753be2aaff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 155 additions and 18 deletions

View file

@ -6,7 +6,7 @@ use openvk\Web\Models\Repositories\Applications;
final class AppsPresenter extends OpenVKPresenter final class AppsPresenter extends OpenVKPresenter
{ {
private $apps; private $apps;
protected $presenterName = "apps";
function __construct(Applications $apps) function __construct(Applications $apps)
{ {
$this->apps = $apps; $this->apps = $apps;

View file

@ -6,6 +6,7 @@ use openvk\Web\Models\Repositories\{Comments, Clubs};
final class CommentPresenter extends OpenVKPresenter final class CommentPresenter extends OpenVKPresenter
{ {
protected $presenterName = "comment";
private $models = [ private $models = [
"posts" => "openvk\\Web\\Models\\Repositories\\Posts", "posts" => "openvk\\Web\\Models\\Repositories\\Posts",
"photos" => "openvk\\Web\\Models\\Repositories\\Photos", "photos" => "openvk\\Web\\Models\\Repositories\\Photos",

View file

@ -7,6 +7,7 @@ final class GiftsPresenter extends OpenVKPresenter
{ {
private $gifts; private $gifts;
private $users; private $users;
protected $presenterName = "gifts";
function __construct(Gifts $gifts, Users $users) function __construct(Gifts $gifts, Users $users)
{ {

View file

@ -8,7 +8,8 @@ use Chandler\Security\Authenticator;
final class GroupPresenter extends OpenVKPresenter final class GroupPresenter extends OpenVKPresenter
{ {
private $clubs; private $clubs;
protected $presenterName = "group";
function __construct(Clubs $clubs) function __construct(Clubs $clubs)
{ {
$this->clubs = $clubs; $this->clubs = $clubs;

View file

@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace openvk\Web\Presenters;
final class MaintenancePresenter extends OpenVKPresenter
{
protected $presenterName = "maintenance";
function renderSection(string $name): void
{
if(!OPENVK_ROOT_CONF["openvk"]["preferences"]["maintenanceMode"][$name])
$this->flashFail("err", tr("error"), tr("forbidden"));
$this->template->name = [
"photos" => tr("my_photos"),
"videos" => tr("my_videos"),
"messenger" => tr("my_messages"),
"user" => tr("users"),
"group" => tr("my_groups"),
"comment" => tr("comments"),
"gifts" => tr("gifts"),
"apps" => tr("apps"),
"notes" => tr("my_notes"),
"notification" => tr("my_feedback"),
"support" => tr("menu_support"),
"topics" => tr("topics")
][$name] ?? $name;
}
function renderAll(): void
{
}
}

View file

@ -9,11 +9,13 @@ final class MessengerPresenter extends OpenVKPresenter
{ {
private $messages; private $messages;
private $signaler; private $signaler;
protected $presenterName = "messenger";
function __construct(Messages $messages) function __construct(Messages $messages)
{ {
$this->messages = $messages; $this->messages = $messages;
$this->signaler = SignalManager::i(); $this->signaler = SignalManager::i();
parent::__construct(); parent::__construct();
} }
@ -30,7 +32,7 @@ final class MessengerPresenter extends OpenVKPresenter
function renderIndex(): void function renderIndex(): void
{ {
$this->assertUserLoggedIn(); $this->assertUserLoggedIn();
if(isset($_GET["sel"])) if(isset($_GET["sel"]))
$this->pass("openvk!Messenger->app", $_GET["sel"]); $this->pass("openvk!Messenger->app", $_GET["sel"]);

View file

@ -6,7 +6,8 @@ use openvk\Web\Models\Entities\Note;
final class NotesPresenter extends OpenVKPresenter final class NotesPresenter extends OpenVKPresenter
{ {
private $notes; private $notes;
protected $presenterName = "notes";
function __construct(Notes $notes) function __construct(Notes $notes)
{ {
$this->notes = $notes; $this->notes = $notes;

View file

@ -3,6 +3,8 @@ namespace openvk\Web\Presenters;
final class NotificationPresenter extends OpenVKPresenter final class NotificationPresenter extends OpenVKPresenter
{ {
protected $presenterName = "notification";
function renderFeed(): void function renderFeed(): void
{ {
$this->assertUserLoggedIn(); $this->assertUserLoggedIn();

View file

@ -17,7 +17,8 @@ abstract class OpenVKPresenter extends SimplePresenter
protected $deactivationTolerant = false; protected $deactivationTolerant = false;
protected $errorTemplate = "@error"; protected $errorTemplate = "@error";
protected $user = NULL; protected $user = NULL;
protected $presenterName;
private function calculateQueryString(array $data): string private function calculateQueryString(array $data): string
{ {
$rawUrl = "tcp+stratum://fakeurl.net$_SERVER[REQUEST_URI]"; #HTTP_HOST can be tainted $rawUrl = "tcp+stratum://fakeurl.net$_SERVER[REQUEST_URI]"; #HTTP_HOST can be tainted
@ -196,12 +197,13 @@ abstract class OpenVKPresenter extends SimplePresenter
function onStartup(): void function onStartup(): void
{ {
$user = Authenticator::i()->getUser(); $user = Authenticator::i()->getUser();
$this->template->isXmas = intval(date('d')) >= 1 && date('m') == 12 || intval(date('d')) <= 15 && date('m') == 1 ? true : false; $this->template->isXmas = intval(date('d')) >= 1 && date('m') == 12 || intval(date('d')) <= 15 && date('m') == 1 ? true : false;
$this->template->isTimezoned = Session::i()->get("_timezoneOffset"); $this->template->isTimezoned = Session::i()->get("_timezoneOffset");
$userValidated = 0; $userValidated = 0;
$cacheTime = OPENVK_ROOT_CONF["openvk"]["preferences"]["nginxCacheTime"] ?? 0; $cacheTime = OPENVK_ROOT_CONF["openvk"]["preferences"]["nginxCacheTime"] ?? 0;
if(!is_null($user)) { if(!is_null($user)) {
$this->user = (object) []; $this->user = (object) [];
$this->user->raw = $user; $this->user->raw = $user;
@ -226,7 +228,7 @@ abstract class OpenVKPresenter extends SimplePresenter
} }
exit; exit;
} }
if($this->user->identity->isBanned() && !$this->banTolerant) { if($this->user->identity->isBanned() && !$this->banTolerant) {
header("HTTP/1.1 403 Forbidden"); header("HTTP/1.1 403 Forbidden");
$this->getTemplatingEngine()->render(__DIR__ . "/templates/@banned.xml", [ $this->getTemplatingEngine()->render(__DIR__ . "/templates/@banned.xml", [
@ -247,23 +249,33 @@ abstract class OpenVKPresenter extends SimplePresenter
]); ]);
exit; exit;
} }
$userValidated = 1; $userValidated = 1;
$cacheTime = 0; # Force no cache $cacheTime = 0; # Force no cache
if($this->user->identity->onlineStatus() == 0 && !($this->user->identity->isDeleted() || $this->user->identity->isBanned())) { if($this->user->identity->onlineStatus() == 0 && !($this->user->identity->isDeleted() || $this->user->identity->isBanned())) {
$this->user->identity->setOnline(time()); $this->user->identity->setOnline(time());
$this->user->identity->save(); $this->user->identity->save();
} }
$this->template->ticketAnsweredCount = (new Tickets)->getTicketsCountByUserId($this->user->id, 1); $this->template->ticketAnsweredCount = (new Tickets)->getTicketsCountByUserId($this->user->id, 1);
if($user->can("write")->model("openvk\Web\Models\Entities\TicketReply")->whichBelongsTo(0)) if($user->can("write")->model("openvk\Web\Models\Entities\TicketReply")->whichBelongsTo(0))
$this->template->helpdeskTicketNotAnsweredCount = (new Tickets)->getTicketCount(0); $this->template->helpdeskTicketNotAnsweredCount = (new Tickets)->getTicketCount(0);
} }
header("X-OpenVK-User-Validated: $userValidated"); header("X-OpenVK-User-Validated: $userValidated");
header("X-Accel-Expires: $cacheTime"); header("X-Accel-Expires: $cacheTime");
setlocale(LC_TIME, ...(explode(";", tr("__locale")))); setlocale(LC_TIME, ...(explode(";", tr("__locale"))));
if (!OPENVK_ROOT_CONF["openvk"]["preferences"]["maintenanceMode"]["all"]) {
if (OPENVK_ROOT_CONF["openvk"]["preferences"]["maintenanceMode"][$this->presenterName]) {
$this->pass("openvk!Maintenance->section", $this->presenterName);
}
} else {
if ($this->presenterName != "maintenance") {
$this->redirect("/maintenances/");
}
}
parent::onStartup(); parent::onStartup();
} }

View file

@ -9,7 +9,8 @@ final class PhotosPresenter extends OpenVKPresenter
private $users; private $users;
private $photos; private $photos;
private $albums; private $albums;
protected $presenterName = "photos";
function __construct(Photos $photos, Albums $albums, Users $users) function __construct(Photos $photos, Albums $albums, Users $users)
{ {
$this->users = $users; $this->users = $users;

View file

@ -11,6 +11,7 @@ final class SupportPresenter extends OpenVKPresenter
{ {
protected $banTolerant = true; protected $banTolerant = true;
protected $deactivationTolerant = true; protected $deactivationTolerant = true;
protected $presenterName = "support";
private $tickets; private $tickets;
private $comments; private $comments;

View file

@ -7,7 +7,8 @@ final class TopicsPresenter extends OpenVKPresenter
{ {
private $topics; private $topics;
private $clubs; private $clubs;
protected $presenterName = "topics";
function __construct(Topics $topics, Clubs $clubs) function __construct(Topics $topics, Clubs $clubs)
{ {
$this->topics = $topics; $this->topics = $topics;

View file

@ -15,12 +15,13 @@ use Nette\Database\UniqueConstraintViolationException;
final class UserPresenter extends OpenVKPresenter final class UserPresenter extends OpenVKPresenter
{ {
private $users; private $users;
public $deactivationTolerant = false; public $deactivationTolerant = false;
protected $presenterName = "user";
function __construct(Users $users) function __construct(Users $users)
{ {
$this->users = $users; $this->users = $users;
parent::__construct(); parent::__construct();
} }

View file

@ -8,7 +8,8 @@ final class VideosPresenter extends OpenVKPresenter
{ {
private $videos; private $videos;
private $users; private $users;
protected $presenterName = "videos";
function __construct(Videos $videos, Users $users) function __construct(Videos $videos, Users $users)
{ {
$this->videos = $videos; $this->videos = $videos;

View file

@ -0,0 +1,20 @@
{extends "../@layout.xml"}
{block title}
{_global_maintenance}
{/block}
{block header}
{_global_maintenance}
{/block}
{block content}
<div class="container_gray">
<center style="background: white;border: #DEDEDE solid 1px;">
<img src="/assets/packages/static/openvk/img/oof.apng" style="width: 20%;" />
<span style="color: #707070;margin: 10px 0;display: block;">
{_undergoing_global_maintenance}
</span>
</center>
</div>
{/block}

View file

@ -0,0 +1,20 @@
{extends "../@layout.xml"}
{block title}
{_section_maintenance}
{/block}
{block header}
{_section_maintenance}
{/block}
{block content}
<div class="container_gray">
<center style="background: white;border: #DEDEDE solid 1px;">
<img src="/assets/packages/static/openvk/img/oof.apng" style="width: 20%;" />
<span style="color: #707070;margin: 10px 0;display: block;">
{tr("undergoing_section_maintenance", $name)|noescape}
</span>
</center>
</div>
{/block}

View file

@ -44,3 +44,4 @@ services:
- openvk\Web\Models\Repositories\Applications - openvk\Web\Models\Repositories\Applications
- openvk\Web\Models\Repositories\ContentSearchRepository - openvk\Web\Models\Repositories\ContentSearchRepository
- openvk\Web\Models\Repositories\BannedLinks - openvk\Web\Models\Repositories\BannedLinks
- openvk\Web\Presenters\MaintenancePresenter

View file

@ -331,3 +331,7 @@ routes:
handler: "UnknownTextRouteStrategy->delegate" handler: "UnknownTextRouteStrategy->delegate"
placeholders: placeholders:
shortCode: "[a-z][a-z0-9\\@\\.\\_]{0,30}[a-z0-9]" shortCode: "[a-z][a-z0-9\\@\\.\\_]{0,30}[a-z0-9]"
- url: "/maintenance/{text}"
handler: "Maintenance->section"
- url: "/maintenances/"
handler: "Maintenance->all"

View file

@ -1147,3 +1147,12 @@
"url_is_banned_default_reason" = "The link you are trying to open may lead you to a site that was created for the purpose of deceiving users with the intention of gaining profit."; "url_is_banned_default_reason" = "The link you are trying to open may lead you to a site that was created for the purpose of deceiving users with the intention of gaining profit.";
"url_is_banned_title" = "Link to a suspicious site"; "url_is_banned_title" = "Link to a suspicious site";
"url_is_banned_proceed" = "Follow the link"; "url_is_banned_proceed" = "Follow the link";
/* Maintenance */
"global_maintenance" = "Undergoing maintenance";
"section_maintenance" = "The section is not available";
"undergoing_global_maintenance" = "Unfortunately, the instance is now closed for technical work. We are already working on troubleshooting. Please try to come back later.";
"undergoing_section_maintenance" = "Unfortunately, the <b>$1</b> section is temporarily unavailable. We are already working on troubleshooting. Please try to come back later.";
"topics" = "Topics";

View file

@ -1208,3 +1208,12 @@
"url_is_banned_default_reason" = "Ссылка, по которой вы попытались перейти, может вести на сайт, который был создан с целью обмана пользователей и получения за счёт этого прибыли."; "url_is_banned_default_reason" = "Ссылка, по которой вы попытались перейти, может вести на сайт, который был создан с целью обмана пользователей и получения за счёт этого прибыли.";
"url_is_banned_title" = "Ссылка на подозрительный сайт"; "url_is_banned_title" = "Ссылка на подозрительный сайт";
"url_is_banned_proceed" = "Перейти по ссылке"; "url_is_banned_proceed" = "Перейти по ссылке";
/* Maintenance */
"global_maintenance" = "Технические работы";
"section_maintenance" = "Раздел недоступен";
"undergoing_global_maintenance" = "К сожалению, сейчас инстанс закрыт на технические работы. Мы уже работаем над устранением неисправностей. Пожалуйста, попробуйте зайти позже.";
"undergoing_section_maintenance" = "К сожалению, раздел <b>$1</b> временно недоступен. Мы уже работаем над устранением неисправностей. Пожалуйста, попробуйте зайти позже.";
"topics" = "Темы";

View file

@ -58,6 +58,20 @@ openvk:
susLinks: susLinks:
warnings: true warnings: true
showReason: true showReason: true
maintenanceMode:
all: false
photos: false
videos: false
messenger: false
user: false
group: false
comment: false
gifts: false
apps: false
notes: false
notification: false
support: false
topics: false
ton: ton:
enabled: false enabled: false
address: "🅿" address: "🅿"