182 lines
7.3 KiB
Perl
Executable File
182 lines
7.3 KiB
Perl
Executable File
#!/usr/bin/perl
|
|
# tta_loadous.cgi
|
|
# Loading Ous from File to ... 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';
|
|
if ( $config{'has_ldapusers'} eq "true" ) {
|
|
do "ldap-lib.pl";
|
|
}
|
|
&foreign_require("proc", "proc-lib.pl");
|
|
&ReadParse();
|
|
|
|
&headerstta($text{'index_loadou'}, "", "loadou",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_loadou'}</b></td> </tr>\n";
|
|
print "<tr $cb> <td><table align=left>\n";
|
|
$file = $in{file};
|
|
if (!$file) {
|
|
print "<tr></tr>\n";
|
|
print "<tr><form METHOD=POST name=loadous ACTION=\"tta_loadous.cgi\" >\n";
|
|
print "<td valign=top>",&hlink("<b>$text{'f_loadfile'}</b>","floadfile")," \n";
|
|
print "<td valign=top><input TYPE=\"text\" NAME=\"file\" VALUE=\"\" cols=\"52\" size=\"52\" ALIGN=left ", &file_chooser_button("file",0,0,$config{tta_backup_dir})," ($config{tta_backup_dir})</td></tr>\n";
|
|
print " <tr><td valign=top><input TYPE=\"submit\" NAME=\"",$text{'f_sendreq'},"\" VALUE=\"",$text{'f_sendreq'},"\">\n";
|
|
print " \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";
|
|
&footer($config{'back_return'},$text{'index'});
|
|
print "<p><p><p>\n";
|
|
do "footer.pl";
|
|
exit;
|
|
}
|
|
unless ( open DATAFILE, "$config{tta_backup_dir}/$file" || open DATAFILE, "$file") {
|
|
if ( $file ne "" ) { print "<p><b>$text{'loadou_noexist'} $file </b></td> </tr>\n"; }
|
|
print "<tr><tr></table></table><hr><p>\n";
|
|
&footer($config{'back_return'},$text{'index'});
|
|
print "<p><p><p>\n";
|
|
do "footer.pl";
|
|
exit;
|
|
}
|
|
|
|
$str=$file." : ".$text{'titidx_loadou'};
|
|
&additional_log('tta_loadous.cgi', "loadou", $str);
|
|
&webmin_log('tta_loadous.cgi', "loadou", "loading $file");
|
|
|
|
$ntdomain=$config{'companyntdomain'};
|
|
$lnum=0;
|
|
%h_ou=&list_ous();
|
|
@listobj="";
|
|
while(<DATAFILE>) {
|
|
if (/\S/ && !/^[#\+\-]/ ) {
|
|
chomp($lin);
|
|
@lin = split(/::/, $_, -1);
|
|
# $lin[1]=~ s/"//g;
|
|
# $is_space=chop($lin[1]);
|
|
# if ( $is_space eq " " ) { chop($lin[1]); }
|
|
push(@listobj, { 'grpou' => $lin[0],
|
|
'alias' => $lin[1],
|
|
'name' => $lin[2],
|
|
'link' => $lin[3],
|
|
'maxsess' => $lin[4],
|
|
'descrip' => $lin[5],
|
|
'num' => scalar(@listobj) });
|
|
$idx{$lin[0]} = $listobj[$#listobj];
|
|
}
|
|
$lnum++;
|
|
}
|
|
%h_links=&list_links();
|
|
LINE: foreach $newobj (@listobj) {
|
|
$ou_alias=$newobj->{alias};
|
|
next LINE if ( $ou_alias eq "" ) ;
|
|
$type_cmd ="new_orgunit";
|
|
$ou_name=$newobj->{name};
|
|
if ( $ou_name eq "" ) { $ou_name=$ou_alias; }
|
|
$grpou=$newobj->{grpou};
|
|
if ( $grpou eq "" || $grpou eq $ou_alias) { $grpou=$config{users_alias}; }
|
|
$ou_descrip=$newobj->{descrip};
|
|
if ( $ou_descrip eq "" ) { $ou_descrip=$ou_name; }
|
|
$ou_link=$newobj->{link};
|
|
$ou_maxsess=$newobj->{maxsess};
|
|
if ( $ou_maxsess lt 0 ) { $ou_maxsess=$config{default_maxsess}; }
|
|
|
|
$organizationname="";
|
|
$dn_ou="";
|
|
$ens_ou="";
|
|
%h_ous=&list_ous();
|
|
if ( $h_ous{$ou_alias}->{'alias'} eq $ou_alias) { # Already there
|
|
$str="ERROR: ".$ou_name." -> ".$ou_alias." -> ".$text{'list_err'};
|
|
&webmin_log('tta_loadous.cgi', "loadou", "error: $str");
|
|
print "<tr><p><b>$str</b></tr>\n";
|
|
next LINE;
|
|
}
|
|
if ( $h_ous{$grpou}->{'alias'} ne $grpou) { # No mother OU up in the tree
|
|
$str="ERROR: ".$ou_name." -> ".$grpou." -> ".$text{'list_errno'};
|
|
&webmin_log('tta_loadous.cgi', "loadou", "error: $str");
|
|
print "<tr><p><b>$str</b></tr>\n";
|
|
next LINE;
|
|
}
|
|
|
|
$dn_ou=$h_ous{$grpou}->{'obj'};
|
|
$organizationname=$h_ous{$grpou}->{'name'};
|
|
$ens_ou=$h_ous{$grpou}->{'ens'};
|
|
|
|
if ( $dn_ou eq "" ) {
|
|
$dnou = "ou=$ou_name";
|
|
$ens = "ou=$ou_name";
|
|
} else {
|
|
$dnou = "ou=$ou_name,$dn_ou";
|
|
$ens = "$ens_ou/ou=$ou_name";
|
|
}
|
|
$ens_obj = "--name \"".$config{tta_base}."/$ens\"";
|
|
$dn = "$dnou,".$config{ldap_base};
|
|
if ( $config{'has_ldapusers'} eq "true" ) {
|
|
$ldap_server=1;
|
|
&connect ();
|
|
if ( &add_ou($dn) eq 0 ) {
|
|
if ( $config{ldap2_server}.length gt 0 ) {
|
|
$ldap_server=2;
|
|
&connect ();
|
|
if ( &add_ou($dn) ne 0 ) { &err_replication() }
|
|
}
|
|
} else {
|
|
$str="ERROR: ".$ou_name." -> ".$dn." -> ".$ens_obj;
|
|
&webmin_log('tta_loadous.cgi', "loadou", "error: $str");
|
|
print "<tr><p><b>$str</b></tr>\n";
|
|
next LINE;
|
|
}
|
|
}
|
|
$| = 1;
|
|
$temp_f=$config{'tta_defaults_ou'};
|
|
# Assigning and collecting values to be used in the form ...
|
|
%h_ttaobj=&load_ttaobj();
|
|
$cdm =$h_ttaobj{'cdm'}->{'value'};
|
|
$inherit =$h_ttaobj{'inherit'}->{'value'};
|
|
$webtop =$h_ttaobj{'webtop'}->{'value'};
|
|
$conntype=$h_ttaobj{'conntype'}->{'value'};
|
|
$temp_f = &tempname();
|
|
open(TEMPF, ">$temp_f");
|
|
print TEMPF "$ens_obj\\\n";
|
|
if ( $cdm ne "" ) {print TEMPF " --cdm \"$cdm\"\\\n"; }
|
|
if ( $inherit ne "" ) {print TEMPF " --inherit \"$inherit\"\\\n"; }
|
|
if ( $conntype ne "" ) { print TEMPF " --conntype \"$conntype\"\\\n"; }
|
|
if ( $webtop ne "" ) {print TEMPF " --webtop \"$webtop\"\\\n"; }
|
|
print TEMPF " --description \"$in{ouname}\" \n";
|
|
close(TEMPF);
|
|
|
|
if (&run_tta_cmd($type_cmd,$ens_obj,$temp_f)) {
|
|
$lin_ou=$ou_alias."::".$ou_name."::"."$dnou"."::"."$ens"."::".$ou_maxsess."::".$ou_descrip;
|
|
&lock_file($config{'ou_list'});
|
|
open(FILEOUS, ">>$config{'ou_list'}");
|
|
print FILEOUS "$lin_ou\n";
|
|
close (FILEOUS);
|
|
&unlock_file($config{'ou_list'});
|
|
$str=$text{'user_made'}.$ou_name." -> ".$dn;
|
|
&additional_log('tta_loadous.cgi', "loadou", $str);
|
|
&webmin_log($config{'ou_list'}, "loadou", "write",$lin_ou);
|
|
if ( $ou_link ne "" && $h_links{$ou_link}->{'alias'} eq $ou_link ) {
|
|
$temp_f = &tempname();
|
|
open(TEMPF, ">$temp_f");
|
|
print TEMPF "$ens_obj\\\n";
|
|
print TEMPF " --link \"$config{tta_base}/".$h_links{$ou_link}->{'ens'}."\" \n";
|
|
close(TEMPF);
|
|
$type_cmd="add_link";
|
|
&run_tta_cmd($type_cmd,$ens_obj,$temp_f);
|
|
}
|
|
print "<tr><p><b>".$text{'user_made'}."$ou_name -> $grpou ($ou_link)</b></tr>\n";
|
|
print "<tr></tr>\n";
|
|
if ( $debug lt 2 ) { unlink($temp_f); }
|
|
}
|
|
}
|
|
close (DATAFILE);
|
|
print "<tr><td><center>".&text('viewlog_action',$stta_sid)."</td></tr>";
|
|
print "<tr><tr></table></table><hr><p>\n";
|
|
&footer($config{'back_return'},$text{'index'});
|
|
print "<p><p><p>\n";
|
|
do "footer.pl";
|
|
exit;
|