ONO::Cron::CronSync::ToolBox

package ONO::Cron::CronSync::ToolBox;
################################################################################
# COPYRIGHT / LICENSE #
################################################################################
#
# This file is part of the ONO Software Project.
#
# Copyright (C) 2000-2025 Jos KIRPS [ www.kirps.com | jos_AT_kirps_DOT_com ]
# and The Joopita Project [ www.joopita.org | contact_AT_joopita_DOT_com ]
#
# This file, as well as other parts of the ONO Software Project or related
# elements, are FREE SOFTWARE available under the ARTISTIC LICENSE 2.0.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# For the full license, see /ono/osr/license/LICENSE.txt, or write to
# jos_AT_kirps_DOT_com or contact_AT_joopita_DOT_com.
#
################################################################################
# END OF COPYRIGHT / LICENSE, HERE COMES THE CODE ... #
################################################################################


use strict;

use ONO::IO;
use ONO::DB;
use ONO::Lib::DateTime::ToolBox;
use ONO::ToolBox::ONO;
use ONO::Core::HostIO;

###############################################################################
# ONO
###############################################################################

#: ONO's CronSync ToolBox.

sub dir {

my (
$self,
$switches,
$script_path,
) = @_;

#: Default cronsync directory, or custom directory?
#:
#: Switches:
#:
#: -c cronsync run mode, requires $script_path
#: -i also return info

my $CRON_DIR = "var/ono/data/cronsync";
my $CRON_INFO;
if (ONO::IO->exists("etc/cronsync.conf")) {
my %cronsync_conf = ONO::IO->confread("etc/cronsync.conf");
if ($cronsync_conf{'cronsyncdir'}) {
$CRON_DIR = $cronsync_conf{'cronsyncdir'};
$CRON_INFO = "Using a custom cronsync dir, as defined in /etc/cronsync.conf: $CRON_DIR";
}
}
if (ONO::Core::HostIO->exists("/etc/ono/cronsync")) {

# detect platform in UI mode

$ENV{'DOCUMENT_ROOT'} =~ m~/var/www/(.*?)/~;
my $www = $1;

# detect platform in CronSync RUN mode

if (!$www && $switches =~ /c/ && $script_path =~ m~/var/www/(.*?)/html/ono/cron/cronsync\.pl~) {
$www = $1;
}

# detect platform in DEV mode

if (ONO::IO->devstation) {
$www = "dev";
}

# check...

if (ONO::Core::HostIO->exists("/etc/ono/cronsync/$www.conf")) {
foreach my $line (ONO::Core::HostIO->list("/etc/ono/cronsync/$www.conf")) {
$line =~ s~(\n|\r|\t)~~g;
if ($line =~ /^CronSyncDir (.*?)$/i) {
$CRON_DIR = $1;
$CRON_INFO = "Using a custom cronsync dir, as defined on the OS level (/etc/ono/cronsync): $CRON_DIR";
}
}
}
}
if ($switches =~ /i/) {
return ($CRON_DIR,$CRON_INFO);
} else {
return $CRON_DIR;
}

}

sub connect {

#: Connect to the default ONO database.

my $db;
if (ONO::IO->exists("etc/sql/ono.conf")) {
$db = ONO::DB->connect("ono");
}

return $db;

}

sub print {

#: Print log message.

my ($self,$msg,$switches) = @_;

if ($switches =~ /v/) {
print " + $msg\n";
}

return "$msg\n";

}

sub timestamp {

#: Get a human readable timestamp.

my (
$sec,$min,$hour,
$mday,$mon,$year,
$wday,$yday,$timestamp,
) = ONO::Lib::DateTime::ToolBox->get;

return "$hour:$min:$sec $mday.$mon.$year";

}

sub get_site {

#: Get site information.

my %site = ONO::ToolBox::ONO->get();

my $domain = $site{'domain'};
$domain =~ s~^(.*)\.(.*?)\.(.*?)$~$2\.$3~;

return ($site{'site'},$domain,$site{'domain'});

}

sub types {

#: Array of available CronSync jobs.

my ($self,$website,$users,$database,$backup,$fileserver) = @_;

# "bot_profiler:bot: update profiles and rankings",

return (
"ono_cronjobs:ONO: run local cronjobs",
"ono_cronkill:ONO: kill hanging cronjobs",
"-",
"bot_microblog:bot: community microblog",
"bot_mailer:bot: mailer (send info mails to users)",
"bot_mailnews:bot: news mailer (and inc daysonline info)",
"bot_media:bot: media optimizer (images, audio, videos, ...)",
"bot_signupreminder:bot: signup reminder",
"bot_update_stats:bot: update community statistics",
"bot_custom_cron:bot: run custom cron.pl",
"-",
"web_analytics:$website: analytics processsor",
"web_import:$website: import",
"web_export:$website: export",
"-",
"user_import:$users: import",
"user_export:$users: export",
"user_rmexp:$users: remove expired",
"user_htaccess:$users: make .htaccess",
"-",
"dbms_import:$database: import",
"dbms_export:$database: export",
"dbms_copy:$database: copy",
"dbms_merge:$database: merge",
"dbms_timestamp:$database: timestamp generator",
"-",
"bak_local:$backup: local (ONO)",
"bak_local_os:$backup: local (OS)",
"bak_remote:$backup: remote (ONO)",
"bak_server:$backup: remote: server (OS & all data)",
"bak_mail:$backup: remote: mail (mailboxes & config)",
"bak_restore_live:$backup: restore local live backups (ONO & SQL)",
"-",
"svr_control:$fileserver: start, restart or stop",
"svr_info_import:$fileserver: import info",
"svr_info_export:$fileserver: export info",
"svr_update_users:$fileserver: update accounts",
"svr_update_dirs:$fileserver: update structure",
"svr_update_stats:$fileserver: update statistics",
"svr_update_access:$fileserver: update permissions",
"svr_backup_make:$fileserver: backup",
"svr_backup_access:$fileserver: backup permissions",
"-",
"monitor:monitoring: monitor other devices",
"monitor_syslog:monitoring: run local monitor (syslog)",
"monitor_export:monitoring: export report to HTML",
"monitor_backups:monitoring: backups",
"-",
"apache_control:webserver: start, restart or stop",
"-",
"os_control:OS: restart or shutdown",
"os_monitor:OS: test and monitor services",
"os_diskfree:OS: check disk space",
"os_readconf:OS: read configuration",
"os_checkconf:OS: check configuration",
"os_logfile:OS: logfile dispatcher",
"os_log_analyzer:OS: logfile analyzer (security)",
"os_firewall:OS: firewall",
"os_manage:OS: server management",
"os_chmod:OS: access rights (chmod)",
"os_security:OS: security features",
)

}

###############################################################################
# end of script
###############################################################################

1;

__END__