# Modification des postes NT de la DR
## V1.0 Nahum Marc - Serlog - Fev. 2001


#########Cache la fenetre DOS
my ($DOS) = Win32::GUI::GetPerlWindow();
Win32::GUI::Hide($DOS);



use Win32::NetAdmin;
use Win32::GUI;
use Win32::Lanman;


#Definition de variables

$wins1="138.21.29.70";
$wins2="138.21.46.130";

# Recuperation des fichiers reg necessaire

#pour les wins

system ("regedit /e c:\\Temp\\rx0000.txt HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\services\\NetBT\\Adapters");

debut:

#fenetre GUI de demande de n° de machine 

$Win = new Win32::GUI::Window(
        -left   => 300,
        -top    => 230,
        -width  => 290,
        -height => 100,
        -name   => "Win",
        -text   => "Modification des postes NT de la DR",
);


$Win->AddLabel (
       -text   => "Quel est le n° de la machine ? (6 ou 8 chiffres)",
       -name   => "Label_1",
	   -top		=> 5,
       -foreground => [255, 0, 0],
	   -left	=> 20,
      );

$titi="";
$TextField_1=$Win->AddTextfield (
       -text   => "$titi",
       -name   => "TextField_1",
       -left   =>  20,
       -top    =>  25,
       -width  => 100,
       -height => 25,
      );

$Win->AddButton (
       -text   => "OK",
       -name   => "Button_1",
       -left   =>  140,
       -top    =>  25
		-width   => 50,
		-default => 1,
      );

$font_about = Win32::GUI::Font->new(
               -name => "Comic Sans MS", 
	             -size => 8,
       );

$Win->AddButton(	
	-name    => "about",
	-text    => "...", 
	-font	=>$font_about,
	-left    => 240, 
	-top     => 2, 
	-width   => 40,

);



$Listmp=$Win->AddListbox(
	-name	=> "Listmp",
	-left	=> 10,
	-top	=> 180,
	-width	=> 100,
	-height	=> 20,
	-visible	=>0,
);

$Listmp->AddString("$titi");
$Listmp->Select(0);

fenetre1b:

$Win->Show();
Win32::GUI::Dialog();


sub about_Click {
	goto about;
}

sub Button_1_Click {
      my $sel = $Listmp->SelectedItem();
      if($sel != -1)
		{
		$nomnt=$Listmp->GetString($sel);
		return -1;
		goto suite;
		} 

   Window_Terminate();
	goto suite;
}

sub TextField_1_Change {
		my $sel = $Listmp->SelectedItem();
		if ($sel !=-1) 
			{
			$Listmp->RemoveItem($sel);
			$Listmp->InsertItem($TextField_1->Text, $sel);
			$Listmp->Select($sel);
			}
    return 1;
		}

	$Win->Hide();


suite:

if ($nomnt =~ /[^0-9]+/) 
	{
		$erreur="Merci de ne saisir que des chiffres ...\n";
		messerr();
		goto debut;

	}

$nbrcar=length($nomnt);

if ($nbrcar != 8 and $nbrcar !=6 )
	{
		$erreur="Attention 6 ou 8 chiffres uniquement !\n";
		messerr();
		goto debut;

	}


#modif wins

open(IMPORT,"<c:\\Temp\\rx0000.txt"); 	
@rx=<IMPORT>;		
close IMPORT;


foreach $ligne (@rx)
		{
		if ($ligne =~ /"NameServer"/i) {$ligne="\"NameServer\"=\"$wins1\"\n"};
		if ($ligne =~ /"NameServerBackup"/i) {$ligne="\"NameServerBackup\"=\"$wins2\"\n"};
		push(@modifnt,$ligne)
		}

# Creation du fichier REG de mise a jour wins et nom de machine

push(@modifnt,"[HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\ComputerName\\ActiveComputerName]\n");
push(@modifnt,"\"ComputerName\"=\"NT$nomnt\"\n");

push(@modifnt,"[HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\ComputerName\\ComputerName]\n");
push(@modifnt,"\"ComputerName\"=\"NT$nomnt\"\n");

push(@modifnt,"[HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters]\n");
push(@modifnt,"\"Hostname\"=\"NT$nomnt\"\n");


open(EXPORT,">c:\\temp\\modifnt.reg"); 	
print EXPORT (@modifnt);		
close EXPORT;


#execution du reg
system ("regedit /s /c c:\\Temp\\modifnt.reg");



#Ajout du compte Bureautique 

$verifbur=Win32::NetAdmin::UsersExist("","bureautique");
if ($verifbur==1) {goto checkadmin;}
else 
	{
		Win32::Lanman::NetUserAdd("", {'name' => 'bureautique',
                                                 'password' => 'toto',
                                                 'comment' => 'Compte Hotline Bureautique',
                                                 'flags' => UF_DONT_EXPIRE_PASSWD ,
                                                 'password_expired' => 0});
		Win32::Lanman::NetLocalGroupAddMembers("", 
                                            "Administrateurs", 
                                           ['bureautique']);

	}


checkadmin:
#Reset du mot de passe admin

$user = 'Administrateur';
     
exit 1
        unless Win32::Lanman::NetUserGetInfo("", $user, \%userinfo);
     
$userinfo{password} = "titi";
     
exit 2
        unless Win32::Lanman::NetUserSetInfo("", $user, \%userinfo);


#Ménage des fichiers

$delfic1=`cmd /c del c:\\Temp\\rx0000.txt >NUL`;
$delfic2=`cmd /c del c:\\Temp\\modifnt.reg >NUL`;

messfin:

#Message de fin

$winfin = Win32::GUI::Window->new(-name => 'winfin', -text => 'Fin de la mise à jour',
                                    -width => 320, -height => 150, -top => 100 , -left	=>100);

$font_about2 = Win32::GUI::Font->new(
               -name => "Garamond", 
	             -size => 24,
       );

$winfin->AddLabel(
                -text => "Fin de la mise à jour des NT Workstation",
                -foreground => [255, 0, 0],
				-top =>10,
				-font	=>$font_about2,
				-left	=>10,
        );

$winfin->AddLabel(
                -text => "Merci de redemarrer le poste",
                -foreground => [255, 0, 0],
				-top =>50,
				-font	=>$font_about2,
				-left	=>50,
        );


$font_about2 = Win32::GUI::Font->new(
               -name => "Garamond", 
	             -size => 24,
       );


$winfin->AddButton(	
	-name    => "fin_ok",
	-text    => "--OK--", 
	-left    => 70, 
	-top     => 85, 
	-width   => 150,

);


$winfin->Show();
$winfin->Dialog();


sub fin_ok_Click
	{
$winfin->Hide();
goto fin;
	};

sub Window_Terminate {warn ("toto\n"); return -1 }

fin:



#########Retour de la fenetre DOS
Win32::GUI::Show($DOS);

exit;

######################
# Erreur de saisie ###
######################

sub messerr
	{

$errwindows= Win32::GUI::Window->new(-name => 'errwindows', -text => "Erreur !!! ",
                                    -width => 320, -height => 100, -left	=> 100,);



my $font = Win32::GUI::Font->new(
               -name => "Comic Sans MS", 
	             -size => 24,
       );


$errwindows->AddLabel (
		-text   => $erreur,
		-name   => "Lerrwindows",
		-left   =>  10, 
		-top    =>  10,
		-font	=> $font,
		-foreground => [255, 0, 0],
	  );

$errwindows->AddButton(	
	-name    => "ok",
	-text    => "OK", 
	-left    => 125, 
	-top     => 50, 
	-width   => 50,
);


$errwindows->Show();
$errwindows->Dialog();

sub ok_Click 
	{
	$errwindows->Hide();
	goto debut;
	};

}


###########
## About ##
###########

about:


$winabout = Win32::GUI::Window->new(-name => 'winabout', -text => 'About ...',
                                    -width => 320, -height => 150);

$font_about2 = Win32::GUI::Font->new(
               -name => "Garamond", 
	             -size => 24,
       );

$winabout->AddLabel(
                -text => "Modification de postes NT workstation de la DR...",
                -foreground => [255, 0, 0],
				-top =>10,
				-font	=>$font_about2,
        );

$winabout->AddLabel(
                -text => "Version 1.0 - Fev. 2001",
                -foreground => [255, 0, 0],
				-top =>50,
				-font	=>$font_about2,
        );

$winabout->AddLabel(
                -text => "Nahum Marc - Serlog - DTSI/DTS ",
                -foreground => [255, 0, 0],
				-top =>70,
				-font	=>$font_about2,
        );

$font_about2 = Win32::GUI::Font->new(
               -name => "Garamond", 
	             -size => 24,
       );


$winabout->AddButton(	
	-name    => "about_ok",
	-text    => "--OK--", 
	-left    => 50, 
	-top     => 100, 
	-width   => 150,

);


$winabout->Show();
$return100= $winabout->Dialog();


sub about_ok_Click
	{
$winabout->Hide();
goto fenetre1b;
	};

