Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 34 additions & 39 deletions inc/common.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
require_once "languages.php";
if (ini_get('output_buffering') == true) {
ini_set('output_buffering', 'off');
}
Expand All @@ -10,12 +11,8 @@ function check_requirements()
{
if (version_compare(PHP_VERSION, '8.0.0', '<'))
{
die("This webserver is using PHP version ".PHP_VERSION." but we require at least PHP 8.0.0.<br>".
"If you already installed PHP8 but are still seeing this error, then it means ".
"apache/nginx/.. is loading an older PHP version. Eg. on Debian/Ubuntu you need ".
"<code>apt-get install libapache2-mod-php8.2</code> (or a similar version) and ".
"<code>apt-get remove libapache2-mod-php7.4</code> (or a similar version). ".
"You may also need to choose again the PHP module to load in apache via <code>a2enmod php8.2</code>");
die(sprintf(__('requirements_php_version'), PHP_VERSION));

}

$loaded_extensions = get_loaded_extensions();
Expand All @@ -27,17 +24,15 @@ function check_requirements()

if (count($missing_extensions) > 0)
{
$text = "<html>The following PHP module(s) need to be loaded:<br>\n<ul>\n";
$text = "<html>" . __('requirements_extensions_missing_title') . "<br>\n<ul>\n";
$cmd = 'apt-get install';
foreach($missing_extensions as $mod)
{
$text .= "<li>$mod</li>\n";
$cmd .= " php-$mod";
}
$text .= "</ul>\n";
$text .= "You need to install/enable these PHP packages and restart the webserver.<br>".
"If you are on Debian/Ubuntu then run <code>$cmd</code> ".
"and restart your webserver (eg: <code>systemctl restart apache2</code> for apache).";
$text .= sprintf(__('requirements_extensions_missing_cmd'), $cmd);
die($text);
}
}
Expand Down Expand Up @@ -192,24 +187,24 @@ function write_config_file()
$tmpfile = UPATH.'/config/config.tmp.'.bin2hex(random_bytes(8)).'.php';
$fd = fopen($tmpfile, "w");
if (!$fd)
die("Could not write to temporary config file $tmpfile.<br>We need write permissions on the config/ directory!<br>");
die(sprintf(__('config_write_error'), htmlspecialchars($tmpfile)));

$str = var_export($file_settings, true);
if ($str === null)
die("Error while running write_config_file() -- weird!");
die(__('requirements_write_config_weird'));
if (!fwrite($fd, "<?php\n".
"/* This config file is written automatically by the UnrealIRCd webpanel.\n".
" * You are not really supposed to edit it manually.\n".
"/* " . __('requirements_config_file_notice_1') . "\n".
" * " . __('requirements_config_file_notice_2') . "\n".
" */\n".
'$config = '.$str.";\n"))
{
die("Error writing to config file $tmpfile (on fwrite).<br>");
die(sprintf(__('requirements_write_config_fwrite'), htmlspecialchars($tmpfile)));
}
if (!fclose($fd))
die("Error writing to config file $tmpfile (on close).<br>");
die(sprintf(__('requirements_write_config_fclose'), htmlspecialchars($tmpfile)));
/* Now atomically rename the file */
if (!rename($tmpfile, $cfg_filename))
die("Could not write (rename) to file ".$cfg_filename."<br>");
die(sprintf(__('requirements_write_config_rename_error'), htmlspecialchars($cfg_filename)));
if (function_exists('opcache_invalidate'))
opcache_invalidate($cfg_filename);

Expand Down Expand Up @@ -453,7 +448,7 @@ function panel_start_session($user = false)

require_once UPATH . "/Classes/class-hook.php";
if (!is_dir(UPATH . "/vendor"))
die("The vendor/ directory is missing. Most likely the admin forgot to run 'composer install'\n");
die(__('die_vendor'));
require_once UPATH . '/vendor/autoload.php';
require_once UPATH . "/Classes/class-cmodes.php";
require_once UPATH . "/inc/defines.php";
Expand Down Expand Up @@ -481,27 +476,27 @@ function panel_start_session($user = false)

/* And a check... */
if (!get_config("base_url"))
die("The base_url was not found in your config. Setup went wrong?");
die(__('other_base_url'));
}

$pages = [
"Overview" => ["script"=>""],
"Users" => ["script"=>"users/index.php"],
"Channels" => ["script"=>"channels/index.php"],
"Servers" => ["script"=>"servers/index.php"],
"Server Bans" => [
"Server Bans" => ["script" => "server-bans/index.php"],
"Name Bans" => ["script" => "server-bans/name-bans.php"],
"Ban Exceptions" => ["script" => "server-bans/ban-exceptions.php"],
__('menu_overview') => ["script" => ""],
__('menu_users') => ["script"=>"users/index.php"],
__('menu_channels') => ["script"=>"channels/index.php"],
__('menu_servers') => ["script"=>"servers/index.php"],
__('a_menu_servers_bans') => [
__('menu_server_ban') => ["script" => "server-bans/index.php"],
__('menu_name_bans') => ["script" => "server-bans/name-bans.php"],
__('menu_ban_exceptions') => ["script" => "server-bans/ban-exceptions.php"],
],
"Spamfilter" => ["script" => "server-bans/spamfilter.php"],
"Logs" => ["script" => "logs/index.php"],
"Tools" => [
"IP WHOIS" => ["script" => "tools/ip-whois.php","no_irc_server_required"=>true],
__('menu_spamfilter') => ["script" => "server-bans/spamfilter.php"],
__('menu_logs') => ["script" => "logs/index.php"],
__('a_menu_tools') => [
__('menu_ip_whois') => ["script" => "tools/ip-whois.php","no_irc_server_required"=>true],
],
"Settings" => [
"General Settings" => ["script" => "settings/general.php"],
"RPC Servers" => ["script" => "settings/rpc-servers.php","no_irc_server_required"=>true],
__('a_menu_settings') => [
__('menu_general_settings') => ["script" => "settings/general.php"],
__('menu_rpc_servers') => ["script" => "settings/rpc-servers.php","no_irc_server_required"=>true],
],
];

Expand All @@ -511,32 +506,32 @@ function panel_start_session($user = false)
if (!page_requires_no_login())
{
if (!is_auth_provided())
die("No authentication plugin loaded. You must load either sql_db, file_db, or a similar auth plugin!");
die(__('other_auth_provided'));
$current_page = $_SERVER['REQUEST_URI'];
header("Location: ".get_config("base_url")."login/?redirect=".urlencode($current_page));
die;
}
} else {
$pages["Settings"]["Accounts"] = [
$pages[__('menu_settings')][__('menu_accounts')] = [
"script" => "settings/index.php",
"no_irc_server_required"=>true
];
if (current_user_can(PERMISSION_MANAGE_USERS))
{
$pages["Settings"]["Role Editor"] = [
$pages[__('menu_settings')][__('menu_role_editor')] = [
"script"=>"settings/user-role-edit.php",
"no_irc_server_required"=>true
];
}
if (current_user_can(PERMISSION_MANAGE_PLUGINS))
{
$pages["Settings"]["Plugins"] = ["script" => "settings/plugins.php"];
$pages[__('menu_settings')][__('menu_plugins')] = ["script" => "settings/plugins.php"];
}
$user = unreal_get_current_user();
if ($user)
{
/* Add logout page, if logged in */
$pages["Logout"] = [
$pages[__('menu_logout')] = [
"script"=>"login/?logout=true",
"no_irc_server_required"=>true
];
Expand Down
16 changes: 8 additions & 8 deletions inc/connection.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

if (!defined('UPATH'))
die("Access denied");
die(__('access_denied'));

function connect_to_ircd()
{
Expand All @@ -19,7 +19,7 @@ function connect_to_ircd()
{
if ($is_api_page)
return;
Message::Fail("No RPC server configured. Go to Settings - RPC Servers.");
Message::Fail(__('rpc_serverconfigured_fail'));
die;
}
$host = $config["unrealircd"][$server]["host"];
Expand All @@ -35,15 +35,14 @@ function connect_to_ircd()
{
if ($is_api_page)
return;
die("RPC Server is missing credentials");
die(__('rpc_serverconfigured_credentials'));
}

if ($rpc_password === null)
{
if ($is_api_page)
return;
Message::Fail("Your RPC password in the DB was encrypted with a different key than config/config.php contains.<br>\n".
"Either restore your previous config/config.php or start with a fresh database.<br>\n");
Message::Fail(__('rpc_serverconfigured_config'));
die;
}

Expand All @@ -67,9 +66,10 @@ function connect_to_ircd()
{
if ($is_api_page)
return;
Message::Fail("Unable to connect to UnrealIRCd: ".$e->getMessage() . "<br>".
"Verify that the connection details from Settings - RPC Servers match the ones in UnrealIRCd ".
"and that UnrealIRCd is up and running");
Message::Fail(sprintf(
__('rpc_serverconfigured_nounrealircd'),
htmlspecialchars($e->getMessage())
));
throw $e;
}
}
Expand Down
2 changes: 1 addition & 1 deletion inc/defines.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Default reason for a quick-ban from the channel
* details page.
*/
define('DEFAULT_CHAN_DETAIL_QUICK_BAN_REASON', "You have been removed from this channel.");
define('DEFAULT_CHAN_DETAIL_QUICK_BAN_REASON', __('dcdq_ban_reason'));
/**
* The version of our webpanel
*/
Expand Down
42 changes: 42 additions & 0 deletions inc/languages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
if (session_status() === PHP_SESSION_NONE) {
session_start();
}

if (isset($_GET['lang'])) {
$lang = trim($_GET['lang']);

if (preg_match('/^[a-zA-Z0-9\-_]+$/', $lang)) {
$_SESSION['lang'] = $lang;
}
}

$lang = $_SESSION['lang'] ?? 'en-US';

$lang_file = __DIR__ . '/../lang/' . $lang . '.php';

if (file_exists($lang_file)) {
$translations = include($lang_file);
} else {
$translations = include(__DIR__ . '/../lang/en-US.php');
}

function __($key) {
global $translations;
return $translations[$key] ?? $key;
}

function get_available_languages(): array {
$langs = [];
$lang_dir = __DIR__ . '/../lang/';
foreach (glob($lang_dir . '*.php') as $file) {
$code = basename($file, '.php');
$data = include($file);
if (isset($data['language_name'])) {
$langs[$code] = $data['language_name'];
} else {
$langs[$code] = $code;
}
}
return $langs;
}
36 changes: 20 additions & 16 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

?>
<div class="row ml-0">
<h2>Network Overview</h2>
<span class="badge bg-danger text-light ml-4 pl-2 pr-2 rounded-pill" style="height:fit-content">LIVE</span>
<h2><?php echo __('unrealircd_network_overview'); ?></h2>
<span class="badge bg-danger text-light ml-4 pl-2 pr-2 rounded-pill" style="height:fit-content"><?php echo __('unrealircd_network_overview_live'); ?></span>
<?php checkup_widget(); ?>
</div>
<?php
Expand All @@ -32,8 +32,12 @@
if (isset($current_user->user_meta['hibp']))
{
$num = $current_user->user_meta['hibp'];
Message::Fail("<h6><strong>Urgent</strong></h6>","Your password was found in a data breach $num time(s).",
"Please <strong><a href=\"".get_config("base_url")."settings/user-edit.php\">update your password</a></strong> immediately");
Message::Fail(
__('unrealircd_password_breach_title'),
sprintf(__('unrealircd_password_breach_message'), $num),
sprintf(__('unrealircd_password_breach_action'), get_config("base_url"))
);

}
?>
<style>
Expand Down Expand Up @@ -128,7 +132,7 @@
</div>
<div class="col">
<h5 id="stats_user_total" class="display-4 numberDisplay"></h5>
<h5 class="display-5">Users Online</h5>
<h5 class="display-5"><?php echo __('unrealircd_network_users_online'); ?></h5>
</div>
</div>
</div>
Expand All @@ -145,7 +149,7 @@
</div>
<div class="col">
<h5 id="stats_channel_total" class="display-4 numberDisplay"></h5>
<h5 class="display-5">Channels</h5>
<h5 class="display-5"><?php echo __('unrealircd_network_channels'); ?></h5>
</div>
</div>
</div>
Expand All @@ -162,8 +166,8 @@
</div>
<div class="col">
<h5 id="stats_oper_total" class="display-4 numberDisplay"></h5>
<h5 class="display-5" style="margin-top: -3px">Operators</h5>
<h5 style="font-size: 10px; margin-top:-12px">View in Users ></h5>
<h5 class="display-5" style="margin-top: -3px"><?php echo __('unrealircd_network_operators'); ?></h5>
<h5 style="font-size: 10px; margin-top:-12px"><?php echo __('unrealircd_network_view_in_users'); ?></h5>
</div>
</div>
</div>
Expand All @@ -180,7 +184,7 @@
</div>
<div class="col">
<h5 id="stats_server_total" class="display-4 numberDisplay"></h5>
<h5 class="display-5">Servers</h5>
<h5 class="display-5"><?php echo __('unrealircd_network_servers'); ?></h5>
</div>
</div>
</div>
Expand All @@ -202,7 +206,7 @@
</div>
<div class="col">
<h5 id="num_server_bans" class="display-4 numberDisplay"></h5>
<h5 class="display-5">Server Bans</h5>
<h5 class="display-5"><?php echo __('unrealircd_network_servers_bans'); ?></h5>
</div>
</div>
</div>
Expand All @@ -219,7 +223,7 @@
</div>
<div class="col">
<h5 id="num_spamfilter_entries" class="display-4 numberDisplay"></h5>
<h5 class="display-5">Spamfilter</h5>
<h5 class="display-5"><?php echo __('unrealircd_network_spamfilter'); ?></h5>
</div>
</div>
</div>
Expand All @@ -236,7 +240,7 @@
</div>
<div class="col">
<h5 id="num_ban_exceptions" class="display-4 numberDisplay"></h5>
<h5 class="display-5">Server Ban Exceptions</h5>
<h5 class="display-5"><?php echo __('unrealircd_network_server_ban_exceptions'); ?></h5>
</div>
</div>
</div>
Expand All @@ -253,8 +257,8 @@
</div>
<div class="col">
<h5 id="stats_uline_total" class="display-4 numberDisplay"></h5>
<h5 class="display-5" style="margin-top: -3px">Services Online</h5>
<h5 style="font-size: 10px; margin-top:-12px">View in Servers ></h5>
<h5 class="display-5" style="margin-top: -3px"><?php echo __('unrealircd_network_services_online'); ?></h5>
<h5 style="font-size: 10px; margin-top:-12px"><?php echo __('unrealircd_network_services_view'); ?></h5>
</div>
</div>
</div>
Expand Down Expand Up @@ -342,7 +346,7 @@ function initStats()
</div>
<div class="col">
<h5 class="display-4 numberDisplay"><?php echo $num_of_panel_admins; ?></h5>
<h5 class="display-5">Panel Accounts</h5>
<h5 class="display-5"><?php echo __('unrealircd_network_panel_accounts'); ?></h5>
</div>
</div>
</div>
Expand All @@ -359,7 +363,7 @@ function initStats()
</div>
<div class="col">
<h5 class="display-4 numberDisplay"><?php echo count(Plugins::$list); ?></h5>
<h5 class="display-5">Plugins</h5>
<h5 class="display-5"><?php echo __('unrealircd_network_panel_plugins'); ?></h5>
</div>
</div>
</div>
Expand Down
Loading