Added core command REHASH.
This commit is contained in:
1 parent
f2585f85b8
commit
6dbc11a404
4 files changed
+185
No files matched your search
+162
@@ -5,6 +5,9 @@ package Lib::Auto;
|
||||
use strict;
|
||||
use warnings;
|
||||
use English qw(-no_match_vars);
|
||||
use Sys::Hostname;
|
||||
use feature qw(switch);
|
||||
use API::Std qw(conf_get err);
|
||||
use API::Log qw(println dbug alog);
|
||||
our $VERSION = 3.000000;
|
||||
|
||||
@@ -41,6 +44,165 @@ sub checkver
|
||||
}
|
||||
}
|
||||
|
||||
sub rehash
|
||||
{
|
||||
# Parse configuration file.
|
||||
my %newsettings = $Auto::CONF->parse or err(2, 'Failed to parse configuration file!', 0) and return;
|
||||
|
||||
# Check for required configuration values.
|
||||
my @REQCVALS = qw(locale expire_logs server fantasy_pf);
|
||||
foreach my $REQCVAL (@REQCVALS) {
|
||||
if (!defined $newsettings{$REQCVAL}) {
|
||||
err(2, "Missing required configuration value: $REQCVAL", 0) and return;
|
||||
}
|
||||
}
|
||||
undef @REQCVALS;
|
||||
|
||||
# Set new configuration.
|
||||
%Auto::SETTINGS = %newsettings;
|
||||
|
||||
# Expire old logs.
|
||||
API::Log::expire_logs();
|
||||
|
||||
# Parse privileges.
|
||||
my %PRIVILEGES;
|
||||
# If there are any privsets.
|
||||
if (conf_get('privset')) {
|
||||
# Get them.
|
||||
my %tcprivs = conf_get('privset');
|
||||
|
||||
foreach my $tckpriv (keys %tcprivs) {
|
||||
# For each privset, get the inner values.
|
||||
my %mcprivs = conf_get("privset:$tckpriv");
|
||||
|
||||
# Iterate through them.
|
||||
foreach my $mckpriv (keys %mcprivs) {
|
||||
# Switch statement for the values.
|
||||
given ($mckpriv) {
|
||||
# If it's 'priv', save it as a privilege.
|
||||
when ('priv') {
|
||||
if (defined $PRIVILEGES{$tckpriv}) {
|
||||
# If this privset exists, push to it.
|
||||
push @{ $PRIVILEGES{$tckpriv} }, ($mcprivs{$mckpriv})[0][0];
|
||||
}
|
||||
else {
|
||||
# Otherwise, create it.
|
||||
@{ $PRIVILEGES{$tckpriv} } = (($mcprivs{$mckpriv})[0][0]);
|
||||
}
|
||||
}
|
||||
# If it's 'inherit', inherit the privileges of another privset.
|
||||
when ('inherit') {
|
||||
# If the privset we're inheriting exists, continue.
|
||||
if (defined $PRIVILEGES{($mcprivs{$mckpriv})[0][0]}) {
|
||||
# Iterate through each privilege.
|
||||
foreach (@{ $PRIVILEGES{($mcprivs{$mckpriv})[0][0]} }) {
|
||||
# And save them to the privset inheriting them
|
||||
if (defined $PRIVILEGES{$tckpriv}) {
|
||||
# If this privset exists, push to it.
|
||||
push @{ $PRIVILEGES{$tckpriv} }, $_;
|
||||
}
|
||||
else {
|
||||
# Otherwise, create it.
|
||||
@{ $PRIVILEGES{$tckpriv} } = ($_);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
%Auto::PRIVILEGES = %PRIVILEGES;
|
||||
|
||||
# Load modules.
|
||||
if (conf_get('module')) {
|
||||
alog '* Loading modules...';
|
||||
foreach (@{ (conf_get('module'))[0] }) {
|
||||
if (!API::Std::mod_exists($_)) { Auto::mod_load($_); }
|
||||
}
|
||||
}
|
||||
|
||||
## Create sockets.
|
||||
alog '* Connecting to servers...';
|
||||
# Get servers from config.
|
||||
my %cservers = conf_get('server');
|
||||
# Iterate through each configured server.
|
||||
foreach my $cskey (keys %cservers) {
|
||||
if (!defined $Auto::SOCKET{$cskey}) {
|
||||
# Prepare socket data.
|
||||
my %conndata = (
|
||||
Proto => 'tcp',
|
||||
LocalAddr => $cservers{$cskey}{'bind'}[0],
|
||||
PeerAddr => $cservers{$cskey}{'host'}[0],
|
||||
PeerPort => $cservers{$cskey}{'port'}[0],
|
||||
Timeout => 20,
|
||||
);
|
||||
# Set IPv6/SSL data.
|
||||
my $use6 = 0;
|
||||
my $usessl = 0;
|
||||
if (defined $cservers{$cskey}{'ipv6'}[0]) { $use6 = $cservers{$cskey}{'ipv6'}[0]; }
|
||||
if (defined $cservers{$cskey}{'ssl'}[0]) { $usessl = $cservers{$cskey}{'ssl'}[0]; }
|
||||
|
||||
# CertFP.
|
||||
if ($usessl) {
|
||||
if (defined $cservers{$cskey}{'certfp'}[0]) {
|
||||
if ($cservers{$cskey}{'certfp'}[0] eq 1) {
|
||||
$conndata{'SSL_use_cert'} = 1;
|
||||
if (defined $cservers{$cskey}{'certfp_cert'}[0]) {
|
||||
$conndata{'SSL_cert_file'} = "$Auto::Bin/../etc/certs/".$cservers{$cskey}{'certfp_cert'}[0];
|
||||
}
|
||||
if (defined $cservers{$cskey}{'certfp_key'}[0]) {
|
||||
$conndata{'SSL_key_file'} = "$Auto::Bin/../etc/certs/".$cservers{$cskey}{'certfp_key'}[0];
|
||||
}
|
||||
if (defined $cservers{$cskey}{'certfp_pass'}[0]) {
|
||||
$conndata{'SSL_passwd_cb'} = sub { return $cservers{$cskey}{'certfp_pass'}[0]; };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Create the socket.
|
||||
if ($use6) {
|
||||
$Auto::SOCKET{$cskey} = IO::Socket::INET6->new(%conndata) or # Or error.
|
||||
err(2, 'Failed to connect to server ('.$ERRNO.'): '.$cskey.' ['.$cservers{$cskey}{'host'}[0].q{:}.$cservers{$cskey}{'port'}[0].']', 0)
|
||||
and delete $Auto::SOCKET{$cskey} and next;
|
||||
}
|
||||
else {
|
||||
if ($usessl) {
|
||||
$Auto::SOCKET{$cskey} = IO::Socket::SSL->new(%conndata) or # Or error.
|
||||
err(2, 'Failed to connect to server ('.$ERRNO.'): '.$cskey.' ['.$cservers{$cskey}{'host'}[0].q{:}.$cservers{$cskey}{'port'}[0].']', 0)
|
||||
and delete $Auto::SOCKET{$cskey} and next;
|
||||
}
|
||||
else {
|
||||
$Auto::SOCKET{$cskey} = IO::Socket::INET->new(%conndata) or # Or error.
|
||||
err(2, 'Failed to connect to server ('.$ERRNO.'): '.$cskey.' ['.$cservers{$cskey}{'host'}[0].q{:}.$cservers{$cskey}{'port'}[0].']', 0)
|
||||
and delete $Auto::SOCKET{$cskey} and next;
|
||||
}
|
||||
}
|
||||
|
||||
# Send PASS if we have one.
|
||||
if (defined $cservers{$cskey}{'pass'}[0]) {
|
||||
Auto::socksnd($cskey, 'PASS :'.$cservers{$cskey}{'pass'}[0]) or
|
||||
err(2, 'Failed to connect to server: '.$cskey.' ['.$cservers{$cskey}{'host'}[0].q{:}.$cservers{$cskey}{'port'}[0].']', 0)
|
||||
and next;
|
||||
}
|
||||
API::Std::event_run('on_preconnect', $cskey);
|
||||
# Send NICK/USER.
|
||||
API::IRC::nick($cskey, $cservers{$cskey}{'nick'}[0]);
|
||||
Auto::socksnd($cskey, 'USER '.$cservers{$cskey}{'ident'}[0].q{ }.hostname.q{ }.$cservers{$cskey}{'host'}[0].' :'.$cservers{$cskey}{'realname'}[0]) or
|
||||
err(2, 'Failed to connect to server: '.$cskey.' ['.$cservers{$cskey}{'host'}[0].q{:}.$cservers{$cskey}{'port'}[0].']', 0)
|
||||
and next;
|
||||
# Add to select.
|
||||
$Auto::SELECT->add($Auto::SOCKET{$cskey});
|
||||
# Success!
|
||||
alog '** Successfully connected to server: '.$cskey;
|
||||
dbug '** Successfully connected to server: '.$cskey;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
###################
|
||||
# Signal handlers #
|
||||
###################
|
||||
|
||||
Reference in new issue
Block a user