smeserver-geneweb/root/usr/share/smanager/lib/SrvMngr/Controller/Geneweb.pm

187 lines
4.0 KiB
Perl
Raw Permalink Normal View History

package SrvMngr::Controller::Geneweb;
#----------------------------------------------------------------------
# heading : System
# description : Geneweb Admin
# navigation : 4000 600
#
# name : geneweb, method : get, url : /geneweb, ctlact : Geneweb#main
# name : genewebd, method : post, url : /geneweb, ctlact : Geneweb#do_update
# routes : end
#----------------------------------------------------------------------
use strict;
use warnings;
use Mojo::Base 'Mojolicious::Controller';
use Locale::gettext;
use SrvMngr::I18N;
use SrvMngr qw(theme_list init_session);
our $cdb = esmith::ConfigDB->open() || die "Couldn't open config db";
our $REGEXP_DOMAIN = qq([a-zA-Z0-9\-\.]+);
sub main {
my $c = shift;
$c->app->log->info($c->log_req);
$cdb->reload();
my $title = $c->l('gnw_FORM_TITLE');
$c->stash( title => $title );
$c->render('geneweb');
};
sub do_update {
my $c = shift;
$c->app->log->info($c->log_req);
my $res = '';
my $result = '';
my $n_gw_dbdir = $c->param("Dbdir_gnw") || '';
my $n_gw_st = $c->param("Status_gnw");
my $n_gw_ac = $c->param("Access_gnw");
my $n_gws_st = $c->param("Status_gws");
my $n_gws_ac = $c->param("Access_gws");
my $gw_dbdir = get_gnw_dbdir();
my $gw_st = get_gnw_st();
my $gw_ac = get_gnw_ac();
my $gws_st = get_gws_st();
my $gws_ac = get_gws_ac();
if ( ($n_gw_dbdir eq $gw_dbdir) && ($n_gw_st eq $gw_st)
&& ($n_gw_ac eq $gw_ac) && ($n_gws_st eq $gws_st) && ($n_gws_ac eq $gws_ac) ) {
$res = 'OK';
$result = $c->l('gnw_NO_CHANGE');
}
if ( ! $result && $n_gw_dbdir ) {
$res = dir_must_exist( $c, $n_gw_dbdir );
$result .= $res unless $res eq 'OK';
}
if ( ! $result ) {
$cdb->set_prop("geneweb", "DBDir", $n_gw_dbdir);
$cdb->set_prop("geneweb", "status", $n_gw_st);
$cdb->set_prop("geneweb", "access", $n_gw_ac);
$cdb->set_prop("gwsetup", "status", $n_gws_st);
$cdb->set_prop("gwsetup", "access", $n_gws_ac);
if ( system ( "/sbin/e-smith/signal-event", "geneweb-modify" ) ) {
$result = $c->error("gnw_ERROR_UPDATING");
} else {
$res = 'OK';
$result = $c->l('gnw_SUCCESS');
}
}
# common part
if ($res ne 'OK') {
my $title = $c->l('gnw_FORM_TITLE');
$c->stash( error => $result );
$c->stash( title => $title );
return $c->render( 'geneweb' );
}
my $message = "geneweb update DONE";
$c->app->log->info($message);
$c->flash( success => $result );
$c->redirect_to("/geneweb");
};
sub get_prop {
my ($item, $prop) = @_;
my $record = $cdb->get($item);
if ($record) {
return $record->prop($prop);
} else {
return '';
}
}
sub get_gnw_dbdir {
return get_prop("geneweb", "DBDir");
}
sub get_gnw_st {
return get_prop("geneweb", "status");
}
sub get_gnw_ac {
return get_prop("geneweb", "access");
}
sub get_gws_st {
return get_prop("gwsetup", "status");
}
sub get_gws_ac {
return get_prop("gwsetup", "access");
}
sub dir_must_exist {
my ($c, $gw_dbdir) = @_;
$gw_dbdir = $1 if ($gw_dbdir =~ /^($REGEXP_DOMAIN)$/);
return $c->l('gnw_ERR_DIR_NOT_EXIST') unless ($gw_dbdir);
if ($gw_dbdir) {
if ( ! -d "$gw_dbdir" ) {
return $c->l('gnw_ERR_DIR_NOT_EXIST');
}
}
return 'OK';
}
sub get_stat_gwd {
my $c = shift;
if ( get_gnw_st() eq 'enabled'
&& system ( "/bin/ps cax | /bin/grep 'gwd' > /dev/null") != 0 ) {
return $c->l('gnw_ERROR_STATUS_GENEWEB');
}
if ( get_gnw_st() eq 'disabled'
&& system ( "/bin/ps cax | /bin/grep 'gwd' > /dev/null") == 0 ) {
return $c->l('gnw_ERROR2_STATUS_GENEWEB');
}
return '';
}
sub get_stat_gws {
my $c = shift;
if ( get_gws_st() eq 'enabled'
&& system ( "/bin/ps cax | /bin/grep 'gwsetup' > /dev/null") != 0 ) {
return $c->l('gnw_ERROR_STATUS_GWSETUP');
}
if ( get_gws_st() eq 'disabled'
&& system ( "/bin/ps cax | /bin/grep 'gwsetup' > /dev/null") == 0 ) {
return $c->l('gnw_ERROR2_STATUS_GWSETUP');
}
return '';
}
1;