#!/usr/bin/perl
# ldapcache_load.cgi
# Loading LDAP CACHE from ldiff File ...  Services with Tarantella.
# STTA Rev. 1.3 Copyright (c) 2001-2004 Jesús Pérez Lorenzo  --- license GNU GPL 
# stta: (@#) 1.31051043346- [2004_01_29_102036]

require './stta-lib.pl';
do "ldap-lib.pl";
&foreign_require("proc", "proc-lib.pl");
&ReadParse();

&headerstta($text{'index_ldapcacheload'}, "", "ldapcacheload",undef,1,0,"$text{'headpage_right'}"."$text{'head_logout'}",undef,undef,"$text{head_below}" );
print "<hr><p>\n"; 
print "<p>\n";
print "<table width=100% border>\n";
print "<tr $tb> <td><font color='$revtext'><b>$text{'titidx_ldapcacheload'}</b></td> </tr>\n";
print "<tr $cb> <td><table align=left>\n";
$dataFile = $in{dataFile};
if (!$dataFile) { 
           print "<tr></tr>\n";
           print "<tr><form METHOD=POST name=ldapcacheload ACTION=\"ldapcache_load.cgi\" >\n"; 
           print "<td valign=top>",&hlink("<b>$text{'f_loadcachefile'}</b>","floadfile"),"&nbsp;\n";
           print "<td valign=top><input TYPE=\"text\" NAME=\"dataFile\" VALUE=\"\" cols=\"52\" size=\"52\" ALIGN=left ", &file_chooser_button("dataFile",0,0,$config{ldapcache_ldif_dir}),"($config{ldapcache_ldif_dir})</td></tr>\n";
           print "        <tr><td valign=top><input TYPE=\"submit\" NAME=\"",$text{'f_sendreq'},"\" VALUE=\"",$text{'f_sendreq'},"\">\n";
           print "        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n";
           print "	</form>\n"; 
           print "<tr><tr></table>\n";
           print "<tr $tb> <td><font color='$revtext'><b>$text{'load_data'}</b></td></tr>\n";
           print "</table><hr><p>\n";
} else {
	print "<tr><td>\n";
        $exec_str="ldapcache";
        $cmd_str=$config{'ldapcache_stop'};
        $str=$config{'ldapcache_stop'};
        if (&run_cmd($str)) {
            $cmd_str=$config{'ldapcache_load'};
            $str=$config{'ldapcache_load'}." ".$config{ldapcache_ldif_dir}."/$dataFile ";
            if (&run_cmd($str)) {
                      $cmd_str=$config{'ldapcache_start'};
                      $str=$config{'ldapcache_start'};
                      &run_cmd($str);
                      print "</pre><tr><td><center><b>-- oOo --</b></center></td></tr>\n";
                      if ( $config{ldap2_server}.length gt 0 ) {
                         print "<tr $tb> <td><font color='$revtext'><b>$text{'replica_msg'}</b></td> </tr>\n";
                      }
            } else {
                      print "<b>$text{'index_cmderr'}</b>\n";
            }
        } else {
            print "<b>$text{'index_cmderr'}</b>\n";
        }
        print "<tr>\n";
        print "<tr>\n";
        print "<tr>\n";
        print "<tr><td><center>".&text('viewlog_action',$stta_sid)."</td></tr>"; 
        print "</table></table><p>\n";
 }
 &footer($config{'back_return'},$text{'index'});
 do "footer.pl";
 exit;
