Transfer user accounts from Another FTP Server: Difference between revisions

From FileZilla Wiki
Jump to navigationJump to search
No edit summary
(added code tag)
 
(10 intermediate revisions by 5 users not shown)
Line 1: Line 1:
Это perl скрипт, который читать G6FTPD учетные записи файлов пользователей.ini, извлечь какую-то информацию (логин, пароль, папку и прав) и записать его в FilleZilla учетной записи сервера-файл "FileZilla Server.xml". Жаль, что я не могу найти, как писать код правильно в этом Вики :s [[файл:пример.jpg]]==Code== #!C:\Perl\bin -w use Digest::MD5 qw(md5_hex); sub авторские права { my (@Пермь)=@_; my $rights=""; if ($perm[0] eq "-") {$прав.= '<Option Name="FileRead">0</Option>'."\n"; } else {$прав.= '<Option Name="FileRead">1</Option>'."\n"; } if ($perm[1] eq "-") {$прав.= '<Option Name="FileWrite">0</Option>'."\n"; } else {$прав.= '<Option Name="FileWrite">1</Option>'."\n"; } if ($perm[2] eq "-") {$прав.= '<Option Name="FileDelete">0</Option>'."\n"; } else {$прав.= '<Option Name="FileDelete">1</Option>'."\n"; } if ($perm[3] eq "-") {$прав.= '<Option Name="FileAppend">0</Option>'."\n"; } else {$прав.= '<Option Name="Fileappend">1</Option>'."\n"; } if ($perm[4] eq "-") {$прав.= '<Option Name="DirCreate">0</Option>'."\n"; } else {$прав.= '<Option Name="DirCreate">1</Option>'."\n"; } if ($perm[5] eq "-") {$прав.= '<Option Name="Dirlist С Точками С Точками">0</Option>'."\n"; } else {$прав.= '<Option Name="Dirlist С Точками С Точками">1</Option>'."\n"; } if ($perm[6] eq "-") {$прав.= '<Option Name="DirDelete">0</Option>'."\n"; } else {$прав.= '<Option Name="DirDelete">1</Option>'."\n"; } if ($perm[7] eq "-") {$прав.= '<Option Name="DirSubdirs">0</Option>'."\n"; } else {$прав.= '<Option Name="DirSubdirs">1</Option>'."\n"; } return $прав; } открыть FICHIER,"< пользователи.ini" or die "File can t be read !"; $motiflogin = 'Login='; $motifpass = 'Pass='; $motifdir='Dir'; $motifattr='Attr'; $дебют='<FileZillaServer> <Settings> <Item name="Admin порт" type="numeric">14147</Item> </Settings> <группы/> <пользователей> '; $paramdivers = '<Option Name="Group"></Option> <Option Name="Bypass сервер userlimit">0</Option> <Option Name="User Limit">0</Option> <Option Name="IP-Limit">0</Option> <Option Name="Enabled">1</Option> <Option Name="Comments"></Option> <Option Name="ForceSsl">0</Option> <IpFilter> <Запрещено /> <Allowed /> </IpFilter> <разрешения>'; $userfin= '</разрешения> <SpeedLimits DlType="0" DlLimit="10" ServerDlLimitBypass="0" UlType="0" UlLimit="10" ServerUlLimitBypass="0"> <Download /> <Upload /> </SpeedLimits> </User>'; $fin = '</Users> </FileZillaServer>'; $i=0; $fz=$дебют; while ($ligne = <это>){ if ($ligne =~ /^$motiflogin[\.\w-]*/i) { @tab=split(/=/,$&); $fz.= "<User Name=\"".$на вкладке[1]."\">\n"; $i++; $h=1; } elsif ($ligne =~ /^$motifpass[\w-]*/i) { @tab=split(/=/,$&); $fz.= "<Option Name=\"Pass\">".md5_hex($tab[1])."</Option>\n"; $fz.= $paramdivers."\n"; } elsif ($ligne =~ /^$motifdir[\w\ \.\\:=]*/i) { @tab=split(/=/,$&); $fz.= "<Разрешение Dir=\"".$на вкладке[1]."\">\n"; } elsif ($ligne =~ /^$motifattr[-\w=]*/i) { @tab=split(/=/,$&); @Пермь=split(//,$tab[1]); $fz.= авторские права(@Пермь); $fz.= '<Option Name="IsHome">'.$ч.'</Option>'."\n"; $fz.= '<Option Name="Автосоздание">0</Option>'."\n".'</Разрешение>'."\n"; $h=0; } elsif ($ligne =~ /^\n/i) { $fz.= $userfin."\n"; } } $fz.= $userfin."\n"; $fz.= $fin; закрыть FICHIER; открыть писатель,"> FileZilla Server.xml" or die "файл не может быть записан !\n"; print писатель $ФЗ; close WRITER; print " ".$я.' учетная запись';---- JeF компьютерщик в jfmcorp DOT org
This is a Perl script that read G6FTPD user accounts file users.ini, extract some information (login, password, folder and rights) and write it in FileZilla Server account file "[[FileZilla Server.xml]]".
 
Sorry I can't find how to write code properly in this Wiki :s
 
<code>
#!C:\Perl\bin -w
use Digest::MD5 qw(md5_hex);
sub copyrights
{
my (@perm)=@_;
my $rights="";
if ($perm[0] eq "-")
{$rights.= '<Option Name="FileRead">0</Option>'."\n"; }
else
{$rights.= '<Option Name="FileRead">1</Option>'."\n"; }
if ($perm[1] eq "-")
{$rights.= '<Option Name="FileWrite">0</Option>'."\n"; }
else
{$rights.= '<Option Name="FileWrite">1</Option>'."\n"; }
if ($perm[2] eq "-")
{$rights.= '<Option Name="FileDelete">0</Option>'."\n"; }
else
{$rights.= '<Option Name="FileDelete">1</Option>'."\n"; }
if ($perm[3] eq "-")
{$rights.= '<Option Name="FileAppend">0</Option>'."\n"; }
else
{$rights.= '<Option Name="Fileappend">1</Option>'."\n"; }
if ($perm[4] eq "-")
{$rights.= '<Option Name="DirCreate">0</Option>'."\n"; }
else
{$rights.= '<Option Name="DirCreate">1</Option>'."\n"; }
if ($perm[5] eq "-")
{$rights.= '<Option Name="DirList">0</Option>'."\n"; }
else
{$rights.= '<Option Name="DirList">1</Option>'."\n"; }
if ($perm[6] eq "-")
{$rights.= '<Option Name="DirDelete">0</Option>'."\n"; }
else
{$rights.= '<Option Name="DirDelete">1</Option>'."\n"; }
if ($perm[7] eq "-")
{$rights.= '<Option Name="DirSubdirs">0</Option>'."\n"; }
else
{$rights.= '<Option Name="DirSubdirs">1</Option>'."\n"; }
return $rights;
}
open FICHIER,"< users.ini" or die "File can t be read !";
$motiflogin = 'Login=';
$motifpass = 'Pass=';
$motifdir='Dir';
$motifattr='Attr';
$debut='<FileZillaServer>
<Settings>
<Item name="Admin port" type="numeric">14147</Item>
</Settings>
<Groups/>
<Users>
';
$paramdivers = '<Option Name="Group"></Option>
<Option Name="Bypass server userlimit">0</Option>
<Option Name="User Limit">0</Option>
<Option Name="IP Limit">0</Option>
<Option Name="Enabled">1</Option>
<Option Name="Comments"></Option>
<Option Name="ForceSsl">0</Option>
<IpFilter>
<Disallowed />
<Allowed />
</IpFilter>
<Permissions>';
$userfin= '</Permissions>
<SpeedLimits DlType="0" DlLimit="10" ServerDlLimitBypass="0" UlType="0" UlLimit="10"   ServerUlLimitBypass="0">
<Download />
<Upload />
</SpeedLimits>
</User>';
$fin = '</Users>
</FileZillaServer>';
$i=0;
$fz=$debut;
while ($ligne = <FICHIER>){
if ($ligne =~ /^$motiflogin[\.\w-]*/i) {
@tab=split(/=/,$&);
$fz.= "<User Name=\"".$tab[1]."\">\n";
$i++;
$h=1;
}
elsif ($ligne =~ /^$motifpass[\w-]*/i) {
@tab=split(/=/,$&);
$fz.= "<Option Name=\"Pass\">".md5_hex($tab[1])."</Option>\n";
$fz.= $paramdivers."\n";
}
elsif ($ligne =~ /^$motifdir[\w\ \.\\:=]*/i) {
@tab=split(/=/,$&);
$fz.= "<Permission Dir=\"".$tab[1]."\">\n";
}
elsif ($ligne =~ /^$motifattr[-\w=]*/i) {
@tab=split(/=/,$&);
@perm=split(//,$tab[1]);
$fz.= copyrights(@perm);
$fz.= '<Option Name="IsHome">'.$h.'</Option>'."\n";
$fz.= '<Option Name="AutoCreate">0</Option>'."\n".'</Permission>'."\n";
$h=0;
}
elsif ($ligne =~ /^\n/i) {
$fz.= $userfin."\n";
}
}  
$fz.= $userfin."\n";
$fz.= $fin;
close FICHIER;
 
open WRITER,"> FileZilla Server.xml" or die "File can't be written !\n";
print WRITER $fz;
close WRITER;
print " ".$i.' account created';
 
</code
 
----
JeF  
 
geek AT jfmcorp DOT org

Latest revision as of 15:08, 14 July 2019

This is a Perl script that read G6FTPD user accounts file users.ini, extract some information (login, password, folder and rights) and write it in FileZilla Server account file "FileZilla Server.xml".

Sorry I can't find how to write code properly in this Wiki :s

#!C:\Perl\bin -w
use Digest::MD5 qw(md5_hex);

sub copyrights
	{
	my (@perm)=@_;
	my $rights="";
		if ($perm[0] eq "-")
			{$rights.= '<Option Name="FileRead">0</Option>'."\n"; }
		else	
			{$rights.= '<Option Name="FileRead">1</Option>'."\n"; }
		if ($perm[1] eq "-")
			{$rights.= '<Option Name="FileWrite">0</Option>'."\n"; }
		else
			{$rights.= '<Option Name="FileWrite">1</Option>'."\n"; }
		if ($perm[2] eq "-")
			{$rights.= '<Option Name="FileDelete">0</Option>'."\n"; }
		else
			{$rights.= '<Option Name="FileDelete">1</Option>'."\n"; }
		if ($perm[3] eq "-")
			{$rights.= '<Option Name="FileAppend">0</Option>'."\n"; }
		else
			{$rights.= '<Option Name="Fileappend">1</Option>'."\n"; }
		if ($perm[4] eq "-")
			{$rights.= '<Option Name="DirCreate">0</Option>'."\n"; }
		else
			{$rights.= '<Option Name="DirCreate">1</Option>'."\n"; }
		if ($perm[5] eq "-")
			{$rights.= '<Option Name="DirList">0</Option>'."\n"; }
		else
			{$rights.= '<Option Name="DirList">1</Option>'."\n"; }
		if ($perm[6] eq "-")
			{$rights.= '<Option Name="DirDelete">0</Option>'."\n"; }
		else
			{$rights.= '<Option Name="DirDelete">1</Option>'."\n"; }
		if ($perm[7] eq "-")
			{$rights.= '<Option Name="DirSubdirs">0</Option>'."\n"; }
		else
			{$rights.= '<Option Name="DirSubdirs">1</Option>'."\n"; }
		return $rights;
	}

open FICHIER,"< users.ini" or die "File can t be read !";

$motiflogin = 'Login=';
$motifpass = 'Pass=';
$motifdir='Dir';
$motifattr='Attr';

$debut='<FileZillaServer>
<Settings>
<Item name="Admin port" type="numeric">14147</Item>
</Settings>
<Groups/>
<Users>
';


$paramdivers = '<Option Name="Group"></Option>
<Option Name="Bypass server userlimit">0</Option>
<Option Name="User Limit">0</Option>
<Option Name="IP Limit">0</Option>
<Option Name="Enabled">1</Option>
<Option Name="Comments"></Option>
<Option Name="ForceSsl">0</Option>
<IpFilter>
<Disallowed />
<Allowed />
</IpFilter>
<Permissions>';


$userfin= '</Permissions>
<SpeedLimits DlType="0" DlLimit="10" ServerDlLimitBypass="0" UlType="0" UlLimit="10"   ServerUlLimitBypass="0">
<Download />
<Upload />
</SpeedLimits>
</User>';

$fin = '</Users>
</FileZillaServer>';

$i=0;
$fz=$debut;
while ($ligne = <FICHIER>){

	if ($ligne =~ /^$motiflogin[\.\w-]*/i) {
		@tab=split(/=/,$&);
		$fz.= "<User Name=\"".$tab[1]."\">\n";
		$i++;
		$h=1;
		}
	elsif ($ligne =~ /^$motifpass[\w-]*/i) {
		@tab=split(/=/,$&);
		$fz.= "<Option Name=\"Pass\">".md5_hex($tab[1])."</Option>\n";	
		$fz.= $paramdivers."\n";
		}
	elsif ($ligne =~ /^$motifdir[\w\ \.\\:=]*/i) {
		@tab=split(/=/,$&);
		$fz.= "<Permission Dir=\"".$tab[1]."\">\n";	
		}
	elsif ($ligne =~ /^$motifattr[-\w=]*/i) {
		@tab=split(/=/,$&);	
		@perm=split(//,$tab[1]);
		$fz.= copyrights(@perm);
		$fz.= '<Option Name="IsHome">'.$h.'</Option>'."\n";
		$fz.= '<Option Name="AutoCreate">0</Option>'."\n".'</Permission>'."\n";
		$h=0;
		}
	elsif ($ligne =~ /^\n/i) {
		$fz.= $userfin."\n";
		}
} 
$fz.= $userfin."\n"; 		
$fz.= $fin;
close FICHIER;
 
open WRITER,"> FileZilla Server.xml" or die "File can't be written !\n";
print WRITER $fz;
close WRITER;

print " ".$i.' account created';

</code


JeF

geek AT jfmcorp DOT org