ONO::Apps::Admin::Screen::Info::Info

package ONO::Apps::Admin::Screen::Info::Info;
################################################################################
# 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::Lib::DateTime::ToolBox;
use ONO::Lib::UI::Tabs;
use ONO::Lib::Web::Domain;

use ONO::Render::Simple;

use ONO::Core::HostOS;
use ONO::Core::Version;

use ONO::Apps::Admin::Screen::Users::Users;

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

sub screen {

my (
$self,
$db,
$community,
$lang,
$BLK_ref,
$vars_ref,
$sql_ref,
$ono_ref,
) = @_;

#: The ONO Admin welcome screen, offering some basic info about the system.

my %BLK = %$BLK_ref;
my %vars = %$vars_ref;

my ($TITLE,$SUBTITLE,$SCREEN,$LEFT,$RIGHT,$TOOLS);

my ($ver,$rev,$build) = ONO::Core::Version->ver;

$TITLE = "Welcome to ONO";
$SUBTITLE = qq~Version $ver, build $build~;

# always make sure that /backups, /bak, /etc, and /var are .htaccess protected...

foreach my $dir ('backups','bak','etc','var') {
if (ONO::IO->exists($dir)) {
ONO::IO->htaccess($dir,":");
}
}

foreach my $dir (
'var',
'var/ono',
) {
if (ONO::IO->exists($dir)) {
ONO::IO->chmod($dir,"777");
}
}

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

if (!$db) {

$SCREEN = qq~<div class="box_red">
<h3 class="red">CAN'T CONNECT TO THE SQL DATABASE</h3>
<div class="box_paper">
<p>Please add an SQL connection named "[i]ono[/i]".</p>
<div class="inline"><a href="/ono/admin/?/db/" class="button button_small">DBMS</a></div>
</div>
</div>
~;

} else {

$RIGHT = ONO::Apps::Admin::Screen::Users::Users->create_root_account($db,$community,$timestamp);

my $BASE = ONO::Render::Simple->render_base;

my ($PERL_MODULES,$PM1,$PM2);

#($PERL_MODULES,$PM1,$PM2) = ONO::Core::HostOS->cpan("H");

if ($PM1) {
$SCREEN .= qq~<div class="box_red">
<h3 class="red">REQUIRED PERL MODULES ARE MISSING</h3>
<div class="box_paper">
<p>Please install all missing modules (red) right away.</p>
<p>You may also consider installing all recommended modules (yellow).</p>
$PERL_MODULES
</div>
</div>
~;
}

unless (ONO::IO->exists("var/community/ono")) {
ONO::IO->mkdir("var/community/ono");
}

if ($BASE) {

my $BUTTON = qq~[<a href="/cgi-bin/ono/admin.pl?fix_file_base_definitions">fix now</a>]~;
my $err;

foreach my $file (
'ono/index.shtml',
'ono/admin/.htaccess',
'ono/desk/.htaccess',
'ono/file/.htaccess',
) {
my $DATA;
foreach my $line (ONO::IO->list($file)) {
if ($line =~ m~cgi="/cgi-bin/~) {
$err++;
}
if ($line =~ m~ /cgi-bin/~) {
$err++;
}
if ($ENV{'REQUEST_URI'} =~ /fix_file_base_definitions/) {
$BUTTON = qq~[<a href="/cgi-bin/ono/admin.pl">fix completed</a>]~;
$line =~ s~cgi="/cgi-bin/~cgi="$BASE/cgi-bin/~;
$line =~ s~ /cgi-bin/~ $BASE/cgi-bin/~;
$DATA .= $line;
}
}
if ($ENV{'REQUEST_URI'} =~ /fix_file_base_definitions/) {
ONO::IO->store($file,$DATA);
}

}

if ($err) {

$SCREEN .= qq~<div class="box_red">Some file definitions are not correct ($err bad files). $BUTTON</div>~;

}

}

my $BOXES1;
foreach my $box (
"web:filesystems/network:Web:::0px 5px 0px 0px",
"users:kdm/group:$BLK{'Users'} & $BLK{'Groups'}:::0px 5px 0px 5px",
"db:filesystems/database:$BLK{'Databases'}:::0px 5px 0px 5px",
"network:devices/fileshare:$BLK{'Network'} & Servers::0px 0px 0px 5px",
) {

my @bp = split(/:/,$box);

$BOXES1 .= ONO::Lib::UI::Tabs->icon($box,"/ono/admin/?/$bp[0]/");

}

my ($DOMS) = ONO::Lib::Web::Domain->read_apache_config($year,$mon,$mday);

$SCREEN .= qq~<div class="box_fabric mb10">
<h3>ONO $BLK{'Administration'}</h3>
<table class="wide_table mb10">
<tr class="vtop">
$BOXES1
</tr>
</table>
$DOMS
</div>
~;

}

return ($TITLE,$SUBTITLE,$SCREEN,$LEFT,$RIGHT,$TOOLS);

}

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

1;

__END__