#!/usr/bin/perl
# index.cgi
# Display a list of links for various types of global configuration
# Rev 1.0 8/8/2001

require './tarantella-lib.pl';

&header($text{'index_title'}, "", undef, 1, 1, undef, &restart_button()."<br>"."");
# check for the base directory
if (!(-d $config{'tta_dir'})) {
	&header($text{'index_title'}, "", undef, 1, 1);
	print "<hr><p>\n";
	print &text('index_eroot', "<tt>$config{'tta_dir'}</tt>",
		    "/config.cgi?$module_name"),"<p>\n";
	print "<hr>\n";
	&footer("/", $text{'index'});
	exit;
	}

# check for the executable
if (!-x $config{'tta_daemon'} || -d $config{'tta_daemon'}) {
	&header($text{'index_title'}, "", undef, 1, 1);
	print "<hr><p>\n";
	print &text('index_eserver', "<tt>$config{'tta_daemon'}</tt>",
		    "/config.cgi?$module_name"),"<p>\n";
	print "<hr>\n";
	&footer("/", $text{'index'});
	exit;
	}
print "<hr><table width=100% cellpading=5 border=1 ><tr>\n";
if ( $access{'monitor'} && $config{'is_masterHost'} eq "true"  && $config{'has_monitor'} eq "true" ) {
    print "<td valign=top align=Center><h3>$text{'index_monitor'}</h3></center>\n";
    @olinks = ("tta_selusr.cgi","cache_selobj.cgi?form=tree");
    @otitles = ("$text{'ldapusrs_title'}", "$text{'ldapcache_title'}",);
    @oicons = ("images/ldaptitle.gif","images/ldapcache.gif");
    &icons_table(\@olinks, \@otitles, \@oicons);
}
print "<td valign=top align=Center><h3>$text{'index_ldap'}</h3></center>\n";
    if ( $access{'passwd'} && $config{'is_ldapcache'} eq "true" ) {
       @olinks = ("tta_selusr.cgi","cache_selobj.cgi?form=tree");
       @otitles = ("$text{'ldapusrs_title'}", "$text{'ldapcache_title'}",);
       @oicons = ("images/ldaptitle.gif","images/ldapcache.gif");
    } else {
       @olinks = ("tta_selusr.cgi");
       @otitles = ("$text{'ldapusrs_title'}");
       @oicons = ("images/ldaptitle.gif");
    }
&icons_table(\@olinks, \@otitles, \@oicons);
if ( $access{'passwd'} && $config{'is_masterHost'} eq "true" ) {
    print "<td valign=top align=Center><h3>$text{'index_passwd'}</h3></center>\n";
    if ( $config{'is_ldapcache'} eq "true" ) {
        @olinks = ("tta_passwd.cgi");
    } else {
        @olinks = ("tta_passwd.cgi", "tta_updatecache.cgi");
    }
    @otitles = map { /^tta_(\S+).cgi/; $text{$1."_title"} } @olinks;
    @oicons = map { /^tta_(\S+).cgi/; "images/$1.gif"; } @olinks;
    &icons_table(\@olinks, \@otitles, \@oicons);

    if ( $config{'is_ldapcache'} eq "true" ) {
	print "<td valign=top align=Center><h3>$text{'index_ldapcache'}</h3></center>\n";
        @olinks = ("cache_addobj.cgi", "cache_modobj.cgi","cache_delobj.cgi");
        @otitles = map { /^cache_(\S+).cgi/; $text{$1."_title"} } @olinks;
        @oicons = map { /^cache_(\S+).cgi/; "images/$1.gif"; } @olinks;
        &icons_table(\@olinks, \@otitles, \@oicons);
    }
}
if ( $access{'passwd'} && $config{'is_masterHost'} eq "true" ) {
    if ( $config{'is_ldapcache'} eq "true" ) {
    } else {
	print "<td valign=top align=Center><h3>$text{'index_profilecache'}</h3></center>\n";
        @olinks = ("tta_addprofcache.cgi", "tta_delprofcache.cgi");
        @otitles = map { /^tta_(\S+).cgi/; $text{$1."_title"} } @olinks;
        @oicons = map { /^tta_(\S+).cgi/; "images/$1.gif"; } @olinks;
        &icons_table(\@olinks, \@otitles, \@oicons);
    }
}
if ($config{'is_masterHost'} ne "true" ) {
        print "<td valign=top align=Center><h3>".&hlink("<b>$text{'masterHost_msg'}","masterHost")."</h3></center>\n";
        print "<table width=100% cellpadding=5> <tr>\n";
        print "<tr>\n";
        print "<td width=25% align=center valign=top>\n";
        print "<table border><tr><td>\n";
        print "<a href=$config{'masterHostURL'}> <img src=images/mastericon.gif alt='' border=0></a></td></tr></table>\n";
        print "<a href=$config{'masterHostURL'}>$config{'masterHost'}</a>\n";
        print "</td>\n";
        print "</table><p>\n";
}
if ($access{'addusr'} && $config{'is_masterHost'} eq "true" ) {
	print "<td valign=top align=Center><h3>$text{'index_users'}</h3>\n";
        @olinks = ("tta_addusr.cgi","tta_modusr.cgi","tta_delusr.cgi","tta_loadusrs.cgi");
        @otitles = map { /^tta_(\S+).cgi/; $text{$1."_title"} } @olinks;
        @oicons = map { /^tta_(\S+).cgi/; "images/$1.gif"; } @olinks;
        &icons_table(\@olinks, \@otitles, \@oicons);
}
print "</td></tr></table>\n";
print "<hr><table width=100% cellpading=5 border=1 ><tr>\n";
if ($access{'addou'} && $config{'is_masterHost'} eq "true" ) {
	print "<td valign=top align=Center><h3>$text{'index_ou'}</h3></center>\n";
        @olinks = ("tta_addou.cgi", "tta_modou.cgi", "tta_delou.cgi");
        @otitles = map { /^tta_(\S+).cgi/; $text{$1."_title"} } @olinks;
        @oicons = map { /^tta_(\S+).cgi/; "images/$1.gif"; } @olinks;
        &icons_table(\@olinks, \@otitles, \@oicons);
}
if ( $access{'addhostsuser'} && $config{'is_masterHost'} eq "true" ) {
    if ( $config{'is_ldapcache'} eq "true" ) {
	print "<td valign=top align=Center><h3>$text{'index_apps'}</h3>\n";
        @olinks = ("cache_addapps.cgi","cache_delapps.cgi");
        @otitles = map { /^cache_(\S+).cgi/; $text{$1."_title"} } @olinks;
        @oicons = map { /^cache_(\S+).cgi/; "images/$1.gif"; } @olinks;
        &icons_table(\@olinks, \@otitles, \@oicons);
	print "<td valign=top align=Center><h3>$text{'index_grpapps'}</h3></center>\n";
        @olinks = ("cache_addgrpapps.cgi", "cache_delgrpapps.cgi");
        @otitles = map { /^cache_(\S+).cgi/; $text{$1."_title"} } @olinks;
        @oicons = map { /^cache_(\S+).cgi/; "images/$1.gif"; } @olinks;
        &icons_table(\@olinks, \@otitles, \@oicons);
       
    } else {
	print "<td valign=top align=Center><h3>$text{'index_hostsuser'}</h3></center>\n";
        @olinks = ("tta_addhostsuser.cgi", "tta_delhostsuser.cgi");
        @otitles = map { /^tta_(\S+).cgi/; $text{$1."_title"} } @olinks;
        @oicons = map { /^tta_(\S+).cgi/; "images/$1.gif"; } @olinks;
        &icons_table(\@olinks, \@otitles, \@oicons);
    }
}
if ($access{'addhosts'} && $config{'is_masterHost'} eq "true" ) {
	print "<td valign=top align=Center><h3>$text{'index_hosts'}</h3>\n";
        @olinks = ("tta_addhosts.cgi","tta_delhosts.cgi");
        @otitles = map { /^tta_(\S+).cgi/; $text{$1."_title"} } @olinks;
        @oicons = map { /^tta_(\S+).cgi/; "images/$1.gif"; } @olinks;
        &icons_table(\@olinks, \@otitles, \@oicons);
}
if ($access{'addgrphosts'} && $config{'is_masterHost'} eq "true" ) {
	print "<td valign=top align=Center><h3>$text{'index_grphosts'}</h3></center>\n";
        @olinks = ("tta_addgrphosts.cgi", "tta_delgrphosts.cgi");
        @otitles = map { /^tta_(\S+).cgi/; $text{$1."_title"} } @olinks;
        @oicons = map { /^tta_(\S+).cgi/; "images/$1.gif"; } @olinks;
        &icons_table(\@olinks, \@otitles, \@oicons);
}
if ( $access{'addhostsuser'} && $config{'is_masterHost'} eq "true" ) {
    if ( $config{'is_ldapcache'} eq "true" ) {
	print "<td valign=top align=Center><h3>$text{'index_domains'}</h3></center>\n";
        @olinks = ("cache_adddomains.cgi", "cache_deldomains.cgi");
        @otitles = map { /^cache_(\S+).cgi/; $text{$1."_title"} } @olinks;
        @oicons = map { /^cache_(\S+).cgi/; "images/$1.gif"; } @olinks;
        &icons_table(\@olinks, \@otitles, \@oicons);
    }
}
print "</td></tr></table>\n";



# global config options
#	&help_search_link("", "man", "docs", "tarantella"));
        print "<hr><table width=100% cellpading=5 border=1><tr>\n";
if ($access{'global'}) {
	if ($access{'global'} == 1) {
	        print "<td align=center><h3>$text{'index_globaltta'}</h3>\n";
	        if ($access{'sessions'} == 1) {
	   	    $ses_icon = { "icon" => "images/ttasess.gif",
		   	          "name" => $text{'ttasess_title'},
			          "link" => "tta_sess.cgi" };
                }
		$df_icon = { "icon" => "images/ttastatus.gif",
			     "name" => $text{'ttastatus_title'},
			     "link" => "tta_status.cgi" };
		$pstta_icon = { "icon" => "images/psicon.gif",
			     "name" => $text{'ttaps_title'},
			     "link" => "/proc/index_search.cgi?user=&mode=1&match=ttaauxserv&cpu=&fs=%2F&files=" };
	        if ($access{'sessions'} == 1) {
	            &config_icons("global", "tta_global.cgi?",
	                 $ses_icon, $df_icon, $pstta_icon );
                } else {
	            &config_icons("global", "tta_global.cgi?",
	                 $df_icon, $pstta_icon );
                }
                print "</td><td valign=top>\n";
	        print "<td align=center><h3>$text{'index_globalldap'}</h3>\n";
		$psldap_icon = { "icon" => "images/psldap.gif",
			     "name" => $text{'ldapps_title'},
			     "link" => "/proc/index_search.cgi?user=&mode=1&match=slapd&cpu=&fs=%2F&files=" };
		$ldapreplica_icon = { "icon" => "images/replica.gif",
			     "name" => $text{'replica_title'},
			     "link" => "ldap_replica.cgi" };
		$ldapbrw_icon = { "icon" => "images/ldapbrowser.gif",
			     "name" => $text{'ldapbrw_title'},
			     "link" => "/ldap_browser/index.cgi?level=ou=usuarios,o=gestion.rima.telefonica.es,dc=ttaldap,dc=gestion,dc=rima,dc=telefonica,dc=es" };
                if ( $config{'is_ldapcache'} eq "true" ) {
		   $ldapbrw2_icon = { "icon" => "images/ldapbrowser.gif",
		        "name" => $text{'ldapcachebrw_title'},
		     	"link" => "/ldap_browser2/index.cgi?level=o=gestion.rima.telefonica.es" };
	           &config_icons("global", "tta_global.cgi?",
	                 $psldap_icon, $ldapbrw_icon, $ldapreplica_icon, $ldapbrw2_icon );
                } else {
	           &config_icons("global", "tta_global.cgi?",
	                 $psldap_icon, $ldapbrw_icon, $ldapreplica_icon );
                }
                print "</td></tr></table>\n";
	}
	else {
		&icons_table([ "tta-info.cgi" ],
			     [ $text{'ttainfo_title'} ],
			     [ "images/ttastatus.gif" ]);
		}
	}

print "</td></tr></table>\n";

if ($access{'global'} == 1) {
    print "<hr><table width=100% cellpading=5 border=1><tr>\n";
	        print "<td align=center><h3>$text{'index_backuptta'}</h3>\n";
		$ttaensbk_icon = { "icon" => "images/tta_ensbk.gif",
			     "name" => $text{'tta_ensbk'},
			     "link" => "tta_ensbk.cgi" };
		$ttabk_icon = { "icon" => "images/tta_backup.gif",
			     "name" => $text{'tta_backup'},
			     "link" => "tta_backup.cgi" };
		$ttaar_icon = { "icon" => "images/tta_archive.gif",
			     "name" => $text{'tta_archive'},
			     "link" => "tta_archive.cgi" };
		&config_icons("backup", "backup.cgi?",
		   $ttaensbk_icon, $ttabk_icon, $ttaar_icon );
                print "</td><td valign=top>\n";
	        print "<td align=center><h3>$text{'index_backupldap'}</h3>\n";
		$ldapbk_icon = { "icon" => "images/ldap_backup.gif",
			     "name" => $text{'ldap_backup'},
			     "link" => "ldap_backup.cgi" };
		$ldapldif_icon = { "icon" => "images/ldap_ldif.gif",
			     "name" => $text{'ldap_ldif'},
			     "link" => "ldap_ldif.cgi" };
		&config_icons("backup", "backup.cgi?", $ldapbk_icon,$ldapldif_icon );
                if ( $config{'is_ldapcache'} eq "true" ) {
                     print "</td><td valign=top>\n";
	             print "<td align=center><h3>$text{'index_backupldapcache'}</h3>\n";
		     $ldapbk_icon = { "icon" => "images/ldapcache_backup.gif",
			          "name" => $text{'ldapcache_backup'},
			          "link" => "ldapcache_backup.cgi" };
		     $ldapldif_icon = { "icon" => "images/ldapcache_ldif.gif",
			          "name" => $text{'ldapcache_ldif'},
			          "link" => "ldapcache_ldif.cgi" };
		     &config_icons("backupcache", "backupcache.cgi?", $ldapbk_icon,$ldapldif_icon );
		}
     print "</td></tr></table>\n";
 }
print "\n";
do "footer.pl";

