#!/usr/bin/perl
###############################################################
#             ***  GPRS Easy Connect V2.5.3_pre03 ***              
###############################################################
#                                                             
# A programot Simon Peter (Perl Tk),   Pinter Gabor
# (kapcsolodasi szkriptek) es Andrea Bravetti (kiegeszitesek,
# egyeb algoritmusok) keszitette.
#
# (Haszalat elott feltetlenul olvasd el a LICENSE allomanyt!)
#
###############################################################
#
# Connection and configurator program for GPRS systems. 
# Software made by Peter Simon (Perl program), Gabor Pinter
# (connecting scripts) and Andrea Bravetti
# (patches, alogythms).
#
# Before you use it, read the LICENSE file sure enough!
#
###############################################################
# simon.peter@linuxuser.hu, pinter.gabor@linuxuser.hu and
# andrea.bravetti@freeinternet.it
###############################################################

#versionnumber
$ver="2.5.3";
# date 2005.01.24.


use Tk;
use Socket;
use Tk::BrowseEntry;
use Tk::LabFrame;
use Tk::Balloon;
use Getopt::Long; # start with parameters
use LWP::Simple;
use Tk::ProgressBar;
use POSIX "uname";

my ($sysname, $nodename, $release, $version, $machine ) = uname;
$m_KernelName = $sysname;
$m_KernelDesc = $nodename.$release.$version.$machine;


chomp ($m_KernelName);
chomp ($m_KernelDesc);

if ($m_KernelName eq "Linux") {
	$gprs_shared_path="/usr/share";
	$gprs_bin_path="/usr/bin";
}

if ($m_KernelName eq "FreeBSD") {
	$gprs_shared_path="/usr/local/share";
	$gprs_bin_path="/usr/local/bin";
}


# user's home dir
users_home ();

#read of configuration
read_conf ();

if (!$apnid && !$chd_apnaid) {
	apn_def();
	new_config_save();
	$chd_apnaid=1;
}

# read of language settings
nyelvbeolv ();

#read of resolution
xvid ();

if ($m_KernelName ne "Linux" && $m_KernelName ne "FreeBSD") {
	$m_BadOSWin=MainWindow->new();
	$m_BadOSWin->title ("GPRSEC: Fatal error!");
	$m_BadOSWin->OnDestroy(sub {exit;});
	$m_BadOSWin->maxsize('300','60');
	$m_BadOSWin->minsize('300','60');
			$m_BadOSWinx=$xfele-150;
			$m_BadOSWiny=$yfele-30;
			$m_BadOSWin->geometry("+$m_BadOSWinx+$m_BadOSWiny");
	$m_BadOSLabel=$m_BadOSWin->Label(-fg=>'red', -text=>"The OS $m_KernelName is not supported!\nPlease, send to us the output of\nthe command 'uname -a',\nwe will try to support your os.")->pack();
	MainLoop();
} else {
	GetOptions("help|?",\&showhelp, "ver|version", sub {print "$ver\n";exit});
	nomore_gprsec ();
	last_conn_rm ();
	telcsibeolv ();
	foablak ();
	MainLoop();
}


# connecting subrutin
sub konnect {

`rm -f $home/.gprsec/dns`;

	if ($comp_main && $compact) {
		$comp_main->configure (-state=>disabled);
	}


	if (port_scan() eq "bibi") {
		return;
	}
	
	undef $resolvconf;
	open (FILE, "</etc/resolv.conf");
		while ($sor=<FILE>) {
			$resolvconf.=$sor;
		}
	close FILE;

	$_=$resolvconf;
	if (!/nameserver\ \d+\.\d+\.\d+\.\d+/) {
		hiba(lancolas($cl[188]));
		return;
	}

	if (-e "$ENV{HOME}/.gprsec/error") {
		`rm $ENV{HOME}/.gprsec/error`;
	}

	undef $kill_counter;
	
	if (!$id_disc=~ /Cancelled/) { # disable the previous disconnect's whatching cycle
		$id_disc->cancel;
		undef $id_disc;
	}


	if ($id) { # disable the cycle of watching of the successful connection (if it is running still)
		$id->cancel;
		undef $id;
	}

	if (!-e "/etc/ppp/options") {
		if ($kivagy eq "root") {
			`echo >/etc/ppp/options`;
		} else {
			hiba(lancolas($cl[187]));
			return;
		}
	}

	# destroy of other running windows
	winbezar ();

	# erase of disconnet's signer file
	if (-e "$home/.gprsec/disc") {
		`rm '$home/.gprsec/disc'`;
	}

	# if the user is not the root then the contingently earlier set nouath option will be removed from the "run" file
	if (-e "$home/.gprsec/run" && $kivagy ne "root") {
		
		undef $temp_run;
		open (FILE, "<$home/.gprsec/run");
			while ($sor=<FILE>) {
				$temp_run.=$sor;
			}
		close FILE;

		@temptomb_run=split /\n/, $temp_run;
		foreach (@temptomb_run) {
			if (/noauth/) {
				undef $_;
			}
		}
		open (FILE, ">$home/.gprsec/run");
		foreach (@temptomb_run) {
			print FILE $_."\n";
		}
		
		# read previous (new) configs
		read_config_file();
		
		undef $temp[27];
		
		write_config_file();
	}
	# cycle-generator for watching of connection
	$id = $winconn->repeat(300,=>\&be);
	if (!-e "$home/.gprsec/run") {
		hiba (lancolas($cl[18])); #Nem tallom a kapcsoldsi szkriptet!\nAdd meg a telefonod tpust!
	return;
	}
	if (!-e "$home/.gprsec/EasyConn.config") {
		hiba (lancolas($cl[66])); #Nincs configurcis llomny!\nEllen?rizd a belltsaid!
	return;
	}

	if ($connconf) {
		$connconf->destroy;
	}
	if (!$compact){
		$buttonx->configure (-state=>disabled);
	}
	$button ->configure (-state=>disabled);

	# run of the pppd script
	# pipe for the read2.pl file accross the pppd script
	if ($m_KernelName eq "Linux") {
		$run="/usr/sbin/pppd file $home/.gprsec/run 2>$home/.gprsec/error | $gprs_bin_path/read2.pl";
	}
	if ($m_KernelName eq "FreeBSD") {
		$run="/usr/sbin/pppd file $home/.gprsec/run 2>$home/.gprsec/conn.log | $gprs_bin_path/read2.pl&";
	}


	$SIG{TERM} = sub {wait};
	socketpair (PARENT, CHILD, PF_UNIX, SOCKET_STREAM, 0);
	if ($pid=fork()) {
		close PARENT;
		select CHILD;
		$|=1;
		select STDOUT;
	} elsif (defined $pid) {
		open (STDIN, ">&PARENT");
		open (STDOUT, ">&PARENT");
		close PARENT;
		select STDOUT;
		$|=1;
		exec ("$run");
		exit;
	}
	if ($reconn_on) {
		$id_disc = $winconn->repeat(300,=>\&ujrakapcs_figy);
	}

	$disconn->configure (-state=>'normal');
	# read2.pl figyelse
	$id_read2pl=$winconn->repeat(300,=>\&read2_x);

}

sub ec_signal_handler { 
	my $signal = shift; 
} 

sub ec_kill_all_pids { 
# send the signal $signal to a given list of pids. 
# it's intended to send a kill signal... 
	local($signal, @m_pidstokill) = @_; 
	foreach (@m_pidstokill) { 
		$m_cmdpid = $_; 
		$m_errcode = kill $signal, $m_cmdpid; 
	} 
} 

sub ec_get_pids(@_) { 
# get the pid from a given command string. 
	my ($mycommand) = @_; 
	my @mypids; 
	@pt2 = `ps ax -o pid,command`; # for performance, in a loop, we don't use our ec_exec();
	chomp @pt2; 
	foreach $process (@pt2) { 
		my ($pid,@cmd) = split(/ /, &trim($process)); 
		if (join(' ', @cmd) eq $mycommand) { 
			if ($pid != $$) { #i don't want to kill my self... 
				@mypids = (@mypids, $pid); 
			} 
		} 
	} 
	return @mypids; 
} 

sub trim() { 
	my ($string) = @_; 
	for ($string) { 
		s/^\s+//; 
		s/\s+$//; 
	} 
	return $string; 
} 

sub ec_prgs_kill { 
# this is the killer sobroutine. 

		$read2pl_pid=`ps ax | grep "/usr/bin/perl $gprs_bin_path/read2.pl"\$`;
		$read2pl_pid=~ s/(\d+)/$1/e;
		$read2pl_pid=$1;
		if ($read2pl_pid) {
			`kill -INT "$read2pl_pid"`;
		}

# signal propagation? no problem... 
	$SIG{TERM} = \&ec_signal_handler; 
	$SIG{HUP} = \&ec_signal_handler; 

# get the pid of "pppd", and kill it if $kill_counter<1 
	my @kill_signal = ('HUP','TERM','TERM','TERM','KILL'); 
	for my $kill_count (0..4) { 
		my @m_mypids = ec_get_pids('/usr/sbin/pppd file '.$home.'/.gprsec/run'); 
		if (!@m_mypids) { @m_mypids = ec_get_pids('\[pppd\]'); } 
		if (@m_mypids) { 
			ec_kill_all_pids($kill_signal[$kill_count], @m_mypids); 
			sleep 1; # this if the most important function...
		} 
	} 

# get the pid of "chat" and kill it. 

	
	@m_mypids = ec_get_pids($home.'/.gprsec/chat -v'); 
	ec_kill_all_pids('KILL', @m_mypids); 

	$SIG{TERM} = undef; 
	$SIG{HUP} = undef; 
} 

# disconnect script 
sub diskonnect { 
	if ($id) {$id->cancel, undef $id}
	if (!$compact && $buttonx) {
		$buttonx->configure (-state=> 'normal'); 
	}
	# if momentarily info window is active, then it blocks the them forms 
	if ($box6) { 
		$box6->configure(-state=>"disable"); 
	} 
	if ($helpwin ){ 
		$upgrade_butt->configure(-state=>"disable"); 
	} 
	
	$button ->configure (-state=> 'normal'); 
	$disconn->configure (-state => 'disabled'); 
	if ($upgrade_butt) {
			$upgrade_butt->configure(-state=>"disabled");
	}
	if ($donate_butt) {
			$donate_butt->configure(-state=>"disabled");
	}

ec_prgs_kill();
	if ($comp_main && $compact) {
		$comp_main->configure (-state=>normal);
	}
} # end disconnect sub 


sub exit_1 {
	diskonnect ();
	exit;
}

sub hiba {
	if ($hibawin) {
			if ($no_beep !=1) {
				$hibawin->bell;
			}
			$hibawin->focusForce;
			$hibawin->raise();
			$hibawin->deiconify;
			return;
	}
	$hibawin=MainWindow->new();
	if ($no_beep !=1) {
		$hibawin->bell;
	}

	$hibaszoveg=$_[0];
	$hibawin->title($cl[11]);
			$hibawinx=$xfele-100;
			$hibawiny=$yfele-100;
			$hibawin->geometry("+$hibawinx+$hibawiny");
	$hszoveg=$hibawin->Label(-fg=>'red', -text=>"$hibaszoveg")->pack();
	$hbutt=$hibawin->Button(-text=>"Ok", -command=>\&hshut)->pack();

	sub hshut {
		$hibawin->destroy;
		undef $hibawin;
	}
return;
}

sub nincsk {
	if (!$phonetype) {
		$felso=$winconn->Label(-width=>30, -height=>2);
		$felso->configure (-font=>[helvetica, 14], -text=>lancolas($cl[5])); #Vlaszd ki a mobilod tpust!\n(Bellts men.)
		$felso->configure (-relief=>'raised');
		$felso->configure (-bg=>'white');
			$back->createWindow(80,140, -window=>$felso, -anchor=>"w");
			$button->configure(-state=>"disable");
	}
	$also=$winconn->Label(-bg=>'white', -width=>33, -height=>1, -bd=>2, -relief=>'sunken');
	if ($phonetype) {

		$also->configure(-text=>$phonetype, -anchor=>'w');
			$phonetype_p=$phonetype;
			$phonetype_p=~ tr/\*//d;
			$get_tel_kep=$telcsikepek{$phonetype_p};# hozzadja a meglv? telcsi kpnek a nevt
			chomp $get_tel_kep;
			if ($get_tel_kep) {
				$kep_path="$gprs_shared_path/gprsec/images/phones/".$get_tel_kep;
				$pic_of_tel=$back->Photo(-file=>$kep_path);
				$back->createImage(330,200, -image=>$pic_of_tel, -anchor=>"c");
			}
	}
	$back->createWindow(20, 175, -window=>$also, -anchor=>"w");
}

########################
# Procreation of the Info window
########################
sub help {
	if ($helpwin) {
		undef $absz;
		undef $abtpart;
		$helpwin->focusForce;
		$helpwin->raise();
		$helpwin->deiconify;
		return;
	}
	undef $hossz;
	undef $absz;
	undef $abtpart;
	$helpwin=MainWindow->new();
	$helpwin->title ("Info of GPRS Easy Connect");
			$helpwinx=$xfele-300;
			$helpwiny=$yfele-225	;
			$helpwin->geometry("+$helpwinx+$helpwiny");
	$helpwin->maxsize('600','450');
	$helpwin->minsize('600','450');
	$helpwin->OnDestroy(sub {undef $helpwin; undef $absz; undef $hossz; undef $upgrade_butt; undef $donate_butt; stop_upgr()});
	$helpwin->configure(-bg=>'black');
		
	$helpwin1=$helpwin->Frame(-bg=>'black')->pack(-side=>"top");
	$helpwin2=$helpwin->Frame(-bg=>'black')->pack(-side=>"bottom");
	
	
	$help=$helpwin1->Menubutton(-relief=>'raised', -text=>lancolas($cl[82]), -tearoff=>0);
	$help1=$helpwin1->Button(-text=>lancolas ($cl[68]), -command=>sub {[$helpwin->destroy, undef $helpwin], help("keszit")})->pack(-side=>"left", -pady=>10); # kszt?k
	$kajliy1=$helpwin1->Label(-bg=>'black')->pack(-side=>"left");
	$help2=$helpwin1->Button(-text=>lancolas ($cl[88]), -command=>sub {[$helpwin->destroy, undef $helpwin], help("history")})->pack(-side=>"left"); # trtnet
	$kajliy1=$helpwin1->Label(-bg=>'black')->pack(-side=>"left");
	$help3=$helpwin1->Button(-text=>'Info', -command=>sub {[$helpwin->destroy, undef $helpwin], help("info")})->pack(-side=>"left"); # info

	$help->separator;

	$upgrade_butt=$helpwin2->Button(-activeforeground=>'black',-text=>lancolas($cl[138]),-command=>\&upgrade)->pack(-pady=>4); # trtnet
#	if ($successful!=1) {
#		$upgrade_butt->configure(-state=>"disable");
#	}
	
	$donate_butt=$helpwin2->Button(-activeforeground=>'black',-text=>lancolas($cl[177]),-command=>\&donate)->pack(-pady=>4); # donate

#	if ($successful!=1) {
#		$donate_butt->configure(-state=>"disable");
#	}
	
	# grafikus fellet
	$back1=$helpwin->Canvas(-width=>600, -height=>340, -bg=>'black', -bd=>-1)->pack(-anchor=>"e");

	# httrkp

	$info_text=$back1->Label(-bg=>'black', -fg=>"#e2e2e0",);
 	$back1->createWindow(300, 170, -window=>$info_text, -anchor=>"c");
	$_=$sel_lang;
	if (!/magyar/ && (@_[0] eq "info" || @_[0] eq "")) {
		$abtext="The GPRS Easy Connect is a unique\nprogram which can help you to make\nthe GPRS Internet connection by\nthe easiest way.\nThis program supports the most\nphones & providers of the world.\nThis program is free and \ncome under the GNU GPL.\n\nHave a lot of fun with this!\n\nPeter Simon (simon.peter\@linuxuser.hu)\n\nGabor Pinter (pinter.gabor\@linuxuser.hu)\n\nAndrea Bravetti (andrea.bravetti\@freeinternet.it)\n\n      www.easyconnect.linuxuser.hu\n";
		infoprint();
		goto ez;
	} elsif (@_[0] eq "info" || @_[0] eq "") {
		$abtext="A GPRS Easy Connect egy klnleges\nprogram, ami segt a GPRS Internet\nkapcsolat felptsben a legegyszerbb\nmdon.\nEz a program tmogatja a vilgon\nlegtbb telefont s szolgltatt.\nA program szabad termk\ns a GNU GPL al esik.\n\nKellemes hasznlatot!\n\nSimon Pter (simon.peter\@linuxuser.hu)\n\nPintr Gbor (pinter.gabor\@linuxuser.hu)\n\nAndrea Bravetti (andrea.bravetti\@freeinternet.it)\n\n      www.easyconnect.linuxuser.hu\n";
		infoprint();
		goto ez;
	} elsif (@_[0] eq "keszit") {
		if (-e "$gprs_shared_path/gprsec/") {
			$kesz_fajl="$gprs_shared_path/gprsec/AUTHORS";
			$abtext=`cat $kesz_fajl`;
		}
	} elsif (@_[0] eq "history") {
		$his_path="$gprs_shared_path/gprsec/history";
		if (-e $his_path) {
			$abtext=`cat $his_path`;
		}
	}
	
	$kesz_sz=$back1->Text(-relief=>'ridge');
	$kesz_sz->configure (-bg=>'black', -fg=>'white');

	$scroll_15 = $back1->Scrollbar(-bg=>'black',-command=>['yview', $kesz_sz]);
	$kesz_sz->configure(-yscrollcommand=>['set', $scroll_15]);
	$scroll_15->pack(-side=>'right', -fill=>'y');
	$kesz_sz->pack(-side=>'left', -fill=>'both', -expand=>1);
	$kesz_sz->insert('end', $abtext);
	
sub infoprint {	
	$abx=10;
	$aby=20;
	$back1->create(text, $abx+2,$aby+2, -font=>[utopia, 20, bold, italic],  -fill=>'black', -text=>"GPRS Easy Connect v$ver", -anchor=>'w');
	$back1->create(text, $abx+1,$aby, -font=>[utopia, 20, bold, italic],  -fill=>"#898989", -text=>"GPRS Easy Connect v$ver", -anchor=>'w');
	$back1->create(text, $abx-1,$aby, -font=>[utopia, 20, bold, italic],  -fill=>"#898989", -text=>"GPRS Easy Connect v$ver", -anchor=>'w');
	$back1->create(text, $abx,$aby+1, -font=>[utopia, 20, bold, italic],  -fill=>"#898989", -text=>"GPRS Easy Connect v$ver", -anchor=>'w');
	$back1->create(text, $abx,$aby-1, -font=>[utopia, 20, bold, italic],  -fill=>"#898989", -text=>"GPRS Easy Connect v$ver", -anchor=>'w');
	$back1->create(text, $abx,$aby, -font=>[utopia, 20, bold, italic],  -fill=>"#fffa00", -text=>"GPRS Easy Connect v$ver", -anchor=>'w');
		
		
	$hossz= (length $abtext)+1;
	$abx=170;
	$aby=340;
	$absz=1;
	
	while ($absz<$hossz) {
		$abtpart= substr $abtext, 0 , $absz;
		$info_text->configure(-text=>"$abtpart", -anchor=>"e");
		$_=substr $abtext, $absz , 1;
		if ($_ ne " ") {
			$back1->after (5);
		}
		$helpwin->update;
		$absz++;
	}
}

	
	
ez:
	
}
##################################
# Configuration window and it's elements
##################################

sub connconf {
	#finding the browsers
 	@browsers=qw (mozilla opera galeon konqueror netscape lynx links firefox amaya);
	$def_path=$ENV{PATH};
	@exec_path=split /\:/, $def_path;
	push (@exec_path, "/usr/local/netscape");
	foreach (@browsers) {
		foreach $temp_path (@exec_path) {
			if (-d $temp_path && !$browser_path{$_}) {
				$browser_path{$_}=`find $temp_path -name $_ -type f -maxdepth 1 2>/dev/null`;
				chomp ($browser_path{$_});
			}
		}
	}

	# if the user doesn't have enough authority for a browser, then that won't be visualized.
	foreach $tempbr (keys %browser_path) {
		if (!-x "$browser_path{$tempbr}") {
			delete $browser_path{$tempbr};
		}
	}
	# scan of the usb,com, irda, bluetooth ports
	port_scan ();

	read_conf();
	
	apn_def();
	
	sub apn_def {
	
		# definition of the APNs
		
	
		if (-e "$gprs_shared_path/gprsec/tools/apn") {
			open (FILE, "<$gprs_shared_path/gprsec/tools/apn");
			while ($sor=<FILE>) {
				$elsochar=substr ($sor, 0, 1);
				if ($elsochar ne "#" && $elsochar ne " " && $elsochar && $elsochar ne "\n") {
					@apn_tomb=split/\t/,$sor;
					foreach (@apn_tomb) {chomp $_}
					if (!$apn_tomb[3]) {$apn_tomb[3]="???"}
					if (!$apn_tomb[4]) {$apn_tomb[4]="???"}
					$apn_tomb[3]=~s /\(\*\)/anything/;
					$apn_tomb[4]=~s /\(\*\)/anything/;
					$apn_tomb[3]=~s /\(\*{2}\)//;
					$apn_tomb[4]=~s /\(\*{2}\)//;
					$apn_tomb[3]=~s /\(\*{3}\)/lancolas($cl[87])/e;
					$apn_tomb[4]=~s /\(\*{3}\)/lancolas($cl[87])/e;
					$apn_tomb[3]=~s /\(\*{4}\)/lancolas($cl[87])/e;
					$apn_tomb[4]=~s /\(\*{4}\)/lancolas($cl[87])/e;
					$szolg_apn{$apn_tomb[1]}[0]=$apn_tomb[0]; #ID
					$szolg_apn{$apn_tomb[1]}[2]=$apn_tomb[2]; #apn
					$szolg_apn{$apn_tomb[1]}[3]=$apn_tomb[3]; #username
					$szolg_apn{$apn_tomb[1]}[4]=$apn_tomb[4]; #password
					$szolg_apn{$apn_tomb[1]}[5]=$apn_tomb[5]; #dns1
					$szolg_apn{$apn_tomb[1]}[6]=$apn_tomb[6]; #dns2
				}
			}
		}
	}
	last_conn_rm ();
	if ($connconf) {
		$connconf->focusForce;
		$connconf->raise();
		$connconf->deiconify;
		return;
	}

	$connconf=MainWindow->new();
	$connconf->title (lancolas($cl[10],"$ver ")); #bellts
		$connconf->maxsize('640','460');
		$connconf->minsize('640','460');

	$connconf->OnDestroy(\sub {undef_set_elements (); undef $connconf, winbezar (), $winconn->deiconify;});

			$connconfx=$xfele-290;
			$connconfy=$yfele-245;
			$connconf->geometry("+$connconfx+$connconfy");

	$j_up=$connconf->Frame()->pack(-side=>'top');
	$j_bal=$connconf->Frame()->pack(-side=>'left');

	@billpoz=qw/-side top -anchor w -padx 4/;
	#buttons
	$obl_butt=$j_bal->Button(-text=>lancolas ($cl[75]), -command=>\&obligatory)->pack(@billpoz); #Ktelez? paramterek
	$kajliq1=$j_bal->Label()->pack(-side=>"top");
	$opt_butt=$j_bal->Button(-text=>lancolas ($cl[76]), -command=>\&optional)->pack(@billpoz); #Vlaszthat paramterek
	$kajliq2=$j_bal->Label()->pack(-side=>"top");
	$rare_butt=$j_bal->Button(-text=>lancolas ($cl[79]), -command=>\&rare_parameters)->pack(@billpoz); #ritka paramterek
	$kajliq3=$j_bal->Label()->pack(-side=>"top");
	$lim_butt=$j_bal->Button(-text=>lancolas ($cl[111]), -command=>\&lim_watch)->pack(@billpoz); #Limitfigyels
	$kajliq4=$j_bal->Label()->pack(-side=>"top");
	$offstat_butt=$j_bal->Button(-text=>lancolas($cl[30]), -command=>\&offstat)->pack(@billpoz); # offline statisztika
	$kajliq5=$j_bal->Label(-text=>"\n" x 3)->pack(-side=>"top");


	$mentes=$j_bal->Button(-bg=>'#06a81c', -activebackground=>'#06a81c', -fg=>'white', -activeforeground=>'white', -text=>lancolas ($cl[9]), -command=>sub {read_some_setting(); clean_sett_win(); reg(); $winconn->deiconify;})->pack(-side=>"top"); #Rendben/Adatok mentse
	$kajli5=$j_bal->Label()->pack(-side=>"top");
	$kajliq10=$j_bal->Label()->pack(-side=>"top");
	$ment_cancel=$j_bal->Button(-text=>lancolas ($cl[57]), -command=>sub {clean_sett_win(), [$connconf->destroy, undef $connconf], winbezar (), $winconn->deiconify;})->pack(-side=>"top"); #mgse
	$j_right=$connconf->LabFrame(-label=>lancolas($cl[75]), -labelside=>"acrosstop")->pack(-side=>'right', -anchor=>'n'); #Ktelez? paramterek
	# graphical canvas
	$back_sett=$j_right->Canvas(-width=>420, -height=>420)->pack();

	obligatory (); # start with the obligatory window


sub read_some_setting {
	if ($spec_tel)  {
		$other_numb=$spec_tel->get;
		$spec_tel->destroy;
		undef $spec_tel;

	}
	if ($havilimit) {
		$havilimit_v=$havilimit->get;
		$havilimit->destroy;
		undef $havilimit;

	}
	if ($hetilimit) {
		$hetilimit_v=$hetilimit->get;
		$hetilimit->destroy;
		undef $hetilimit;

	}
	if ($user_name_v) {
		$user=$user_name_v->get;
		$user_name_v->destroy;
		undef $user_name_v;

	}
	if ($pass_w_v) {
		$passw=$pass_w_v->get;
		$pass_w_v->destroy;
		undef $pass_w_v;

	}
	if ($dns1_e1) {
		$dns1=$dns1_e1->get;
		$dns1_e1->destroy;
		undef $dns1_e1;

	}
	if ($dns1_e2) {
		$dns2=$dns1_e2->get;
		$dns1_e2->destroy;
		undef $dns1_e2;

	}
	if ($apn_w_v) {
		$def_apn=$apn_w_v->get;
		$apn_w_v->destroy;
		undef $apn_w_v;

	}

}
sub clean_sett_win {
	# unlock of the buttons
	if ($obl_butt) {
		$obl_butt->configure(-state=>"normal");
	}
	if ($opt_butt) {
		$opt_butt->configure(-state=>"normal");
	}
	if ($rare_butt) {
		$rare_butt->configure(-state=>"normal");
	}
	if ($lim_butt) {
		$lim_butt->configure(-state=>"normal");
	}
	if ($offstat_butt) {
		$offstat_butt->configure(-state=>"normal");
	}

	if ($back_sett) {$back_sett->destroy; undef $back_sett}
	$back_sett=$j_right->Canvas(-width=>420, -height=>420)->pack();
}


	sub obligatory {
		read_some_setting();
		clean_sett_win();
		$obl_butt->configure(-state=>"disable");
		$j_right->configure(-label=>lancolas($cl[75])); #Ktelez? paramterek
		# seletion of the phone
		$tel_duma=$back_sett->Label(-fg=>'blue', -text=>lancolas($cl[74])); #Add meg a tel. tp.
		$back_sett->createWindow(20, 15, -window=>$tel_duma, -anchor=>"w");

		$b2 = $back_sett->Balloon(-bg=>'yellow');
		$b2->attach($tel_duma,-msg=>lancolas($cl[108]));
		# phones in the a browseEntry
		$tel_sz = $back_sett->BrowseEntry( -variable=>\$phonetype, -command=>sub {othernumb(),cdma_tel(), tested (), place_pic()}, -width=>30);
		$back_sett->createWindow(13, 35, -window=>$tel_sz, -anchor=>"w");
		$tel_duma1=$back_sett->Label(); #tesztelt?
		$back_sett->createWindow(20, 60, -window=>$tel_duma1, -anchor=>"w");
		tested ();
		# erase of the earlier set personal (unique) phone number
		sub othernumb {
			undef $other_numb;
		}

		sub tested {
			if ($phonetype=~/\*/) {
				$tel_duma1->configure(-fg=>'red', -text=>lancolas($cl[136]));# mg nem tesztelt kszlk
			} else {
				$tel_duma1->configure(-text=>"");
			}
		}


		place_pic ();

		sub place_pic {
			$phonetype_p=$phonetype;
			$phonetype_p=~ tr/\*//d;
			$get_tel_kep=$telcsikepek{$phonetype_p};
			if ($get_tel_kep) {
				$kep_path="$gprs_shared_path/gprsec/images/phones/".$get_tel_kep;
				$pic_of_tel=$back_sett->Photo('IMG', -file=>$kep_path);
				$back_sett->createImage(300,20, -image=>$pic_of_tel, -anchor=>"nw");
			} else {
				$color=$back_sett->cget(bg);
				$back_sett->createRectangle(300,20, 380, 100, -width=>0, -fill=>$color, outline=>$color);
			}
		}


		foreach $temptelcsi (sort keys %teltype) {
    			$tel_sz->insert("end", $temptelcsi);
		}


		# settings of the providers
		$szolg_duma=$back_sett->Label(-fg=>'blue', -text=>lancolas($cl[61])); #Vlaszd ki a szolgltatd!
		$back_sett->createWindow(20, 80, -window=>$szolg_duma, -anchor=>"w");
		# providers in browseEntry
		$szolg_sz = $back_sett->BrowseEntry( -variable=>\$sel_szolg, -width=>33, -command=>\&user_pass);
    		$back_sett->createWindow(13, 100, -window=>$szolg_sz, -anchor=>"w");

		foreach $tempszolg (sort keys %szolg_apn) { # setting of the type of phones
			if ($tempszolg) {
				$szolg_sz->insert("end", $tempszolg);
			}
		}
		
		# writing of the APNs
		$apn_w = $back_sett->Label(-fg=>'blue', -text=>lancolas($cl[134]));#apn
		$back_sett->createWindow(20, 120, -window=>$apn_w, -anchor=>"w");
		$b24 = $back_sett->Balloon(-bg=>'yellow');
		$b24->attach($apn_w,-msg=>lancolas($cl[135]));
		$apn_w_v= $back_sett->Entry(-width=>33);
		$back_sett->createWindow(20, 140, -window=>$apn_w_v, -anchor=>"w");

		$apn_sel=$szolg_apn{$sel_szolg}[2];
		if ($def_apn) {
			$apn_sel=$def_apn;
		}

		$apn_w_v->insert('end', $apn_sel);

		#username
		$user_name = $back_sett->Label(-fg=>'blue', -text=>lancolas($cl[63]));#Felhasznl nv:
		$back_sett->createWindow(20, 160, -window=>$user_name, -anchor=>"w");
		$b3 = $back_sett->Balloon(-bg=>'yellow');
		$b3->attach($user_name,-msg=>lancolas($cl[98]));
		$user_name_v= $back_sett->Entry(-width=>25);
		$back_sett->createWindow(20, 180, -window=>$user_name_v, -anchor=>"w");
		$user_name_v->insert('end', $user);

		#password
		$pass_w = $back_sett->Label(-fg=>'blue', -text=>lancolas($cl[64]));#jelsz
		$back_sett->createWindow(20, 200, -window=>$pass_w, -anchor=>"w");
		$b4 = $back_sett->Balloon(-bg=>'yellow');
		$b4->attach($pass_w,-msg=>lancolas($cl[99]));
		$pass_w_v= $back_sett->Entry(-show=>"*", -width=>25)->pack(-anchor=>"w");
		$back_sett->createWindow(20, 220, -window=>$pass_w_v, -anchor=>"w");
		$pass_w_v->insert('end', $passw);
		$b4_pass = $back_sett->Balloon(-bg=>'yellow');
		$b4_pass->attach($pass_w_v,-msg=>$passw);

		sub user_pass {
			$user=$szolg_apn{$sel_szolg}[3];
			$passw=$szolg_apn{$sel_szolg}[4];
			$user_name_v->delete ('0.0','end');
			$pass_w_v->delete ('0.0','end');
			$user_name_v->insert('end', $user);
			$pass_w_v->insert('end', $passw);
			$apn_sel=$szolg_apn{$sel_szolg}[2];
			$apn_w_v->delete ('0.0','end');
			$apn_w_v->insert('end', $apn_sel);
			nulldns ();
		}

		# selection of the CDMA system phones
		sub cdma_tel {
			if ($phonetype=~ /Ac555_/) {
				$sel_szolg="CDMA System";
				user_pass ();
			}
		}

		# language settings
		$lang_duma=$back_sett->Label(-fg=>'blue', -text=>lancolas($cl[54])); #Vlaszd ki a nyelvezetet!
		$back_sett->createWindow(20, 240, -window=>$lang_duma, -anchor=>"w");
		# languages in browseEntry
		$lang_sz = $back_sett->BrowseEntry( -variable=>\$sel_lang);
    		$back_sett->createWindow(13, 260, -window=>$lang_sz, -anchor=>"w");

		undef @van_lang;

		# reading of the languages which are in the directory
		@langs=`ls -A $gprs_shared_path/gprsec/languages/`;
		foreach (@langs) {
			chomp $_;
			if (!/_/ && !/.lng/ && !-d "$gprs_shared_path/gprsec/languages/$_") {
				push (@van_lang, $_);
			}
		}

		foreach (sort @van_lang) {
    			$lang_sz->insert("end", $_);
		}

		$figy2=$back_sett->Label(-fg=>'blue', -text=>lancolas($cl[8])); #\nVlaszd ki a csatlakozsi portod!
		$back_sett->createWindow(20, 280, -window=>$figy2, -anchor=>"w");
		# ports browseEntry
		$rad = $back_sett->BrowseEntry( -variable=>\$kivp, -width=>"30");
    		$back_sett->createWindow(13, 300, -window=>$rad, -anchor=>"w");

			foreach $valami (sort keys %ports) {
    				$rad->insert("end", $valami);
			}

		# number of possibility shown ports
		$rad2 = $back_sett->Checkbutton(-text=>lancolas($cl[163]), -variable=>\$m_expert, -command=>\&connconf);
    		$back_sett->createWindow(380, 280, -window=>$rad2, -anchor=>"e");
		$b26 = $back_sett->Balloon(-bg=>'yellow');
		$b26->attach($rad2,-msg=>lancolas($cl[169]));

		if ($din_eng ne "0" && $m_KernelName ne "FreeBSD") {$din_eng=1}
		if ($din_eng eq "1") {undef $dns1; undef $dns2}

		$din_dns_sz=$back_sett->Checkbutton(-fg=>'blue', -text=>lancolas($cl[78]), -variable=>\$din_eng, -command=>\&dns12); #A szolgltatd engedlyezi a DNS-t?
		$back_sett->createWindow(20, 320, -window=>$din_dns_sz, -anchor=>"w");

		if ($m_KernelName eq "Linux") {
			$dns_set_mess=lancolas($cl[86]);
		}
		if ($m_KernelName eq "FreeBSD") {
			$dns_set_mess=lancolas($cl[175]);
		}

		$b25 = $back_sett->Balloon(-bg=>'yellow');
		$b25->attach($din_dns_sz,-msg=>lancolas($cl[86]));

			if ($m_KernelName eq "FreeBSD") {
				$din_dns_sz->configure(-state=>"disabled");
			}

		#dns1
		$dns1_sz1 = $back_sett->Label(-fg=>'blue', -text=>"DNS 1");
		$back_sett->createWindow(20, 340, -window=>$dns1_sz1, -anchor=>"w");
		$b6 = $back_sett->Balloon(-bg=>'yellow');
		$b6->attach($dns1_sz1,-msg=>lancolas($cl[100]));
		$dns1_e1= $back_sett->Entry();
		$back_sett->createWindow(20, 360, -window=>$dns1_e1, -anchor=>"w");
		$dns1_e1->insert('end', $dns1);

		#dns2
		$dns1_sz2 = $back_sett->Label(-fg=>'blue', -text=>"DNS 2");
		$back_sett->createWindow(20, 380, -window=>$dns1_sz2, -anchor=>"w");
		if ($m_KernelName eq "Linux") {
			$dns_message=lancolas($cl[100]);
		}
		if ($m_KernelName eq "FreeBSD") {
			$dns_message=lancolas($cl[174]);
		}
			$b7 = $back_sett->Balloon(-bg=>'yellow');
			$b7->attach($dns1_sz2,-msg=>$dns_message);

		$dns1_e2= $back_sett->Entry();
		$back_sett->createWindow(20, 400, -window=>$dns1_e2, -anchor=>"w");
		$dns1_e2->insert('end', $dns2);

		if ($kivagy ne "root" && $din_eng==1) {
			$dns1_e1->configure(-state=>"disabled");
			$dns1_e2->configure(-state=>"disabled");
			$din_dns_sz->configure(-state=>"disabled");
		}

		if ($m_KernelName eq "FreeBSD" && $kivagy ne "root") {
			$dns1_e1->configure(-state=>"disabled");
			$dns1_e2->configure(-state=>"disabled");
			$din_dns_sz->configure(-state=>"disabled");
		}

		sub dns12 {
			if ($m_KernelName eq "FreeBSD" && $kivagy ne "root") {
				nulldns ();
				return;
			}

			if ($m_KernelName eq "FreeBSD" && $kivagy eq "root") {
				engdns ();
				return;
			}
			if ($kivagy ne "root" && $din_eng==1) {
				$din_dns_sz->configure(-state=>"disabled");
				nulldns ();
				return;
			}
			if ($din_eng==0) {
				engdns ();
				return;
			}
			if ($din_eng==1) {
				nulldns ();
				return;
			}
		}

		sub nulldns {
			undef $dns1;
			undef $dns2;
			$dns1_e1->configure(-state=>"normal");
			$dns1_e2->configure(-state=>"normal");
			$dns1_e1->delete ('0.0','end');
			$dns1_e1->insert('end', $dns1);
			$dns1_e2->delete ('0.0','end');
			$dns1_e2->insert('end', $dns2);

			if ($kivagy eq "root" && $din_eng==0) {
				engdns ();
			}
			if ($m_KernelName eq "FreeBSD" && $kivagy ne "root") {
				engdns();
				$dns1_e1->configure(-state=>"disabled");
				$dns1_e2->configure(-state=>"disabled");
				$din_dns_sz->configure(-state=>"disabled");
			}


		}


		sub engdns {
			$dns1_e1->configure(-state=>"normal");
			$dns1_e2->configure(-state=>"normal");
			$dns1_sz1->configure(-fg=>"blue");
			$dns1_sz2->configure(-fg=>"blue");
			$dns1=$szolg_apn{$sel_szolg}[5];
			$dns2=$szolg_apn{$sel_szolg}[6];
			if (!$dns1 && !$dns2) {
				$dns1="???.???.???";
				$dns2="???.???.???";
			}
			$dns1_e1->delete ('0.0','end');
			$dns1_e1->insert('end', $dns1);
			$dns1_e2->delete ('0.0','end');
			$dns1_e2->insert('end', $dns2);
		}

	} # end obigatory subrutin

	sub optional {
		read_some_setting();
		clean_sett_win();
		$opt_butt->configure(-state=>"disabled");
		$j_right->configure(-label=>lancolas($cl[76])); #Vlaszthat paramterek
		$spped_sz=$back_sett->Label(-fg=>'blue', -text=>lancolas($cl[150])); #A kapcsolds sebessge
		$back_sett->createWindow(20, 15, -window=>$spped_sz, -anchor=>"w");

		if (!$connspeed) {$connspeed=57600}
		$cspped[0]="2147483 (2.048 Mb/s)";
		$cspped[1]="460800   (56.25 kB/s)";
		$cspped[2]="393216   (48 kB/s)";
		$cspped[3]="230400   (28.12 kB/s)";
		$cspped[4]="115200   (14.0 kB/s)";
		$cspped[5]="57600     (7.03 kB/s)";
		$cspped[6]="38400     (4.68 kB/s)";
		$cspped[7]="19200     (2.34 kB/s)";
		$cspped[8]="9600       (1.17 kB/s)";
		$cspped[9]="2400       (0.29 kB/s)";
		# sppeds in browseEntry
		$boxa1 = $back_sett->BrowseEntry( -variable=>\$connspeed, -command=>\&connspeed_sel);
		$back_sett->createWindow(13, 35, -window=>$boxa1, -anchor=>"w");
		foreach (@cspped) {
    			$boxa1->insert("end", $_);
		}
		sub connspeed_sel {
			$connspeed=~s /(\d+)/$1/;
			$connspeed=$1;
		}


		$panel_sz=$back_sett->Label(-fg=>'blue', -text=>lancolas($cl[12])); #\nA sikeres kapcsolds utn...:
		$back_sett->createWindow(20, 55, -window=>$panel_sz, -anchor=>"w");
		$cw_ic_sz=$back_sett->Checkbutton(-text=>lancolas($cl[59]), #Az EasyConn ablak ikonizlsa.
				   -variable=>\$cw_ic);
		$back_sett->createWindow(20, 75, -window=>$cw_ic_sz, -anchor=>"w");
		$panel_on_co=$back_sett->Checkbutton(-text=>lancolas($cl[15]), #A Kapcsolds ablak ikonizlsa.
				   -variable=>\$co_pan);
		$back_sett->createWindow(20, 95, -window=>$panel_on_co, -anchor=>"w");
		$b_sz=$back_sett->Label(-fg=>'blue', -text=>lancolas($cl[13])); #Kapcsolds utn a kvetkez? bngsz? indtsa:
		$back_sett->createWindow(20, 120, -window=>$b_sz, -anchor=>"w");
		$b8 = $back_sett->Balloon(-bg=>'yellow');
		$b8->attach($b_sz,-msg=>lancolas($cl[103]));

		# browsers in browseEntry
		$box2 = $back_sett->BrowseEntry( -variable=>\$brow, -width=>"33");
		$back_sett->createWindow(13, 145, -window=>$box2, -anchor=>"w");
		$box2->insert("end", "--");
		foreach $tempbr (sort values %browser_path) {
    			$box2->insert("end", $tempbr);
		}

		$reconn_sz=$back_sett->Label(-fg=>'blue', -text=>lancolas($cl[56])." (sec) ?"); #jrakapcsolds
		$back_sett->createWindow(20, 165, -window=>$reconn_sz, -anchor=>"w");
		# reconnect times in browseEntry
		$box3 = $back_sett->BrowseEntry( -variable=>\$reconn_on, -command=>\&en_dis_bg_rec);
		$back_sett->createWindow(13, 185, -window=>$box3, -anchor=>"w");
		foreach (qw/-- 5 10 15 20 25 30 35 40 45 50 55 60/) {
    			$box3->insert("end", $_);
		}

		$rec_db_sz=$back_sett->Label(-text=>lancolas($cl[94])); #jrakapcs. db
		$back_sett->createWindow(20, 205, -window=>$rec_db_sz, -anchor=>"w");
		$rec_db_scale = $back_sett->Scale(qw/-orient horizontal -length 200 -from 3 -to 20
   			 	      -resolution 1 -sliderlength  20 -command/=>\&reconn_db_meghat);
		$rec_db_scale->set($reconn_db);
		$rec_db_scale->pack(qw/-expand yes -anchor w/);
		$back_sett->createWindow(20, 235, -window=>$rec_db_scale, -anchor=>"w");
		sub reconn_db_meghat {
			($reconn_db) =@_;
		}


		$bg_rec_sz=$back_sett->Checkbutton(-text=>lancolas($cl[90]),-variable=>\$bg_rec); #jrakapcsolds a httrben
		$back_sett->createWindow(20, 270, -window=>$bg_rec_sz, -anchor=>"w");
		$b9 = $back_sett->Balloon(-bg=>'yellow');
		$b9->attach($bg_rec_sz,-msg=>lancolas($cl[104]));

		en_dis_bg_rec ();

		sub en_dis_bg_rec {
			if ($reconn_on && $reconn_on ne "--") {
				$bg_rec_sz->configure(-state=>'normal');
				$rec_db_scale->configure(-state=>'normal');
				$rec_db_sz->configure(-fg=>'black');
			} else {
				$bg_rec_sz->configure(-state=>'disable');
				$rec_db_scale->configure(-state=>'disable');
				$rec_db_sz->configure(-fg=>'gray');
				undef $bg_rec;
			}
		}
		if (!$idores || $idores <200){$idores=200}

		$cikl_seb_sz=$back_sett->Label(-fg=>'blue', -text=>lancolas($cl[77])); #Kapcsolatfelpts figyelsnek id?rse (ms):
		$back_sett->createWindow(20, 290, -window=>$cikl_seb_sz, -anchor=>"w");
		$b10 = $back_sett->Balloon(-bg=>'yellow');
		$b10->attach($cikl_seb_sz,-msg=>lancolas($cl[102]));
		$idres_scale = $back_sett->Scale(qw/-orient horizontal -length 200 -from 200 -to 2000
   			 	      -resolution 50 -sliderlength  20 -command/=>\&idores_meghat);
		$idres_scale->set($idores);
		$idres_scale->pack(qw/-expand yes -anchor w/);
		$back_sett->createWindow(20, 320, -window=>$idres_scale, -anchor=>"w");
		sub idores_meghat {
			($idores) =@_;
		}

		$auto_csat_sz=$back_sett->Label(-fg=>'blue', -text=>lancolas($cl[7])); #A program indtsa utn...
		$back_sett->createWindow(20, 350, -window=>$auto_csat_sz, -anchor=>"w");
		$auto_csat_cs=$back_sett->Checkbutton(-text=>lancolas($cl[17]),-variable=>\$autocsat, -command=>\&aut_save); #automatikus csatlakozs
		$back_sett->createWindow(20, 370, -window=>$auto_csat_cs, -anchor=>"w");

		$silent=$back_sett->Checkbutton(-fg=>'blue', -text=>lancolas($cl[89]),-variable=>\$no_beep); #Hangjelzsek tiltsa
		$back_sett->createWindow(20, 390, -window=>$silent, -anchor=>"w");
		
		$compact_c=$back_sett->Checkbutton(-fg=>'blue', -text=>lancolas($cl[189]),-variable=>\$compact); #Compact mode
		$back_sett->createWindow(20, 410, -window=>$compact_c, -anchor=>"w");
		$b22 = $back_sett->Balloon(-bg=>"yellow");
		$b22->attach($compact_c,-msg=>lancolas($cl[190]));

	} # end of optional subrutin

	sub rare_parameters {
		read_some_setting();
		clean_sett_win();
		$rare_butt->configure(-state=>"disabled");
		$j_right->configure(-label=>lancolas($cl[79])); #ritka
		$spec_tel_sz=$back_sett->Label(-fg=>'blue', -text=>lancolas($cl[106]));#Egyedi telefonszm
		$back_sett->createWindow(20, 15, -window=>$spec_tel_sz, -anchor=>"w");
		$b12 = $back_sett->Balloon(-bg=>'yellow');
		$b12->attach($spec_tel_sz,-msg=>lancolas($cl[107]));
		$spec_tel= $back_sett->Entry();
		$back_sett->createWindow(20, 35, -window=>$spec_tel, -anchor=>"w");
		$spec_tel->insert('end', $other_numb);


		# if there is not definied CID then the default will be set
		@cidtomb=("--", 1..10);
		# CIDs in browseEntry
		$cid_sz=$back_sett->Label(-fg=>'blue', -text=>lancolas($cl[81])); #Egyedi CID rtk belltsa:
		$back_sett->createWindow(20, 55, -window=>$cid_sz, -anchor=>"w");
		$b13 = $back_sett->Balloon(-bg=>'yellow');
		$b13->attach($cid_sz,-msg=>lancolas($cl[97]));

		$box4 = $back_sett->BrowseEntry( -variable=>\$cid);
		$back_sett->createWindow(13, 75, -window=>$box4, -anchor=>"w");
		foreach (@cidtomb) { #default
    			$box4->insert("end", $_);
		}

		$no_cgq_sz=$back_sett->Checkbutton(-fg=>'blue', -text=>lancolas($cl[95]),-variable=>\$no_cgq); #CGQ tilts
		$back_sett->createWindow(20, 105, -window=>$no_cgq_sz, -anchor=>"w");
		$b14 = $back_sett->Balloon(-bg=>'yellow');
		$b14->attach($no_cgq_sz,-msg=>lancolas($cl[96]));
		# noauth option
		$no_auth_sz=$back_sett->Checkbutton(-fg=>'blue', -text=>lancolas($cl[127]),-variable=>\$no_auth); #auth tilts
		$back_sett->createWindow(20, 145, -window=>$no_auth_sz, -anchor=>"w");
		$b15 = $back_sett->Balloon(-bg=>'yellow');
		$b15->attach($no_auth_sz,-msg=>lancolas($cl[129]));
		if ($kivagy eq "root") {
			$no_auth_sz->configure(-state=>"normal");
		} else {
			$no_auth=0;
			$no_auth_sz->configure(-state=>"disable");
		}

		#BSD compresssion
		$bsd_comp_sz=$back_sett->Checkbutton(-fg=>'blue', -text=>lancolas($cl[132]),-variable=>\$bsd_comp); #BSD compresszi
		$back_sett->createWindow(20, 185, -window=>$bsd_comp_sz, -anchor=>"w");
		$b17 = $back_sett->Balloon(-bg=>'yellow');
		$b17->attach($bsd_comp_sz,-msg=>lancolas($cl[133]));

		#disable of watching of data transmission
		$no_dev_sz=$back_sett->Checkbutton(-fg=>'blue', -text=>lancolas($cl[151]),-variable=>\$no_dev); #Adatforgalmi figyels tiltsa
		$back_sett->createWindow(20, 225, -window=>$no_dev_sz, -anchor=>"w");
		$b20 = $back_sett->Balloon(-bg=>'yellow');
		$b20->attach($no_dev_sz,-msg=>lancolas($cl[152]));

		# enable debug mode
		$debug_mod=$back_sett->Checkbutton(-fg=>'blue', -text=>lancolas($cl[130]),-variable=>\$debug, -command=>\&telcsibeolv); #Hibakeres? md
		$back_sett->createWindow(20, 265, -window=>$debug_mod, -anchor=>"w");
		$b18 = $back_sett->Balloon(-bg=>'yellow');
		$b18->attach($debug_mod,-msg=>lancolas($cl[131]));

		# remove a username and password under FreeBSD
		$remove_useres=$back_sett->Checkbutton(-fg=>'blue', -text=>lancolas($cl[164]),-variable=>\$rem_user, -command=>\&remove_window); #Add/Remove users
		$back_sett->createWindow(20, 305, -window=>$remove_useres, -anchor=>"w");
		$b21 = $back_sett->Balloon(-bg=>"yellow");
		$b21->attach($remove_useres,-msg=>lancolas($cl[170]));

		if ($m_KernelName ne "FreeBSD" || $kivagy ne "root") {
			$remove_useres->configure(-state=>"disable");
		}

		
		sub remove_window {
		$rem_user=0;
			if ($m_KernelName eq "FreeBSD" && $kivagy eq "root") {
				if ($remove_win) {
					$remove_win->focusForce;
					$remove_win->raise();
					$remove_win->deiconify;
					return;
				}

				$remove_win=MainWindow->new();
				$remove_win->title (lancolas($cl[171])); #remove user window
				$remove_win->maxsize('300','300');
				$remove_win->minsize('300','300');

				$remove_win->OnDestroy(\sub {undef $remove_win, undef %users_and_pass, undef $deleted_user, undef $deleted_pass, undef $rem_line});

				$remove_winx=$xfele-175;
				$remove_winy=$yfele-100;
				$remove_win->geometry("+$remove_winx+$remove_winy");
				@users_and_pass_temp=`cat /etc/ppp/pap-secrets`;
				foreach (@users_and_pass_temp) {
					$u_p_temp=$_;
					$u_p_temp=~ tr/\*//d;
					$u_p_temp=~ tr/\t/\-/;
					$u_p_temp=~ tr/\n//d;
     					if ($u_p_temp) {
						$users_and_pass{$u_p_temp}=$_;
					}
				}


				$rem_top=$remove_win->LabFrame(-label=>lancolas ($cl[172]), -labelside=>"acrosstop")->pack(-anchor=>'c', -padx=>"10"); # add user
				$new_bsd_user_butt=$rem_top->Button(-text=>lancolas ($cl[93]), -command=>\&add_bsd_new_user)->pack(-side=>"bottom", -pady=>"5");# ok
				$new_bsd_user_butt=$rem_top->Label()->pack(-side=>"bottom");# ok

				$closewindow=$remove_win->Button(-text=>lancolas ($cl[83]), -command=>sub {$remove_win->destroy, undef $remove_win, undef %users_and_pass})->pack(-side=>"bottom", -pady=>"5");# close this window
				$rem_bottom=$remove_win->LabFrame(-label=>lancolas ($cl[173]), -labelside=>"acrosstop")->pack(-anchor=>'c', -padx=>"10"); # remove user

				# user add frame
				$rem_top_top=$rem_top->Frame()->pack(-side=>"top");
				$new_bsd_user_sz=$rem_top_top->Label(-fg=>'blue', -text=>lancolas($cl[165]))->pack(-side=>"left");#New username?
				$new_bsd_user= $rem_top_top->Entry()->pack(-side=>"left");

				$rem_top_bott=$rem_top->Frame()->pack(-side=>"bottom");
				$new_bsd_pass_sz=$rem_top_bott->Label(-fg=>'blue', -text=>lancolas($cl[166]))->pack(-side=>"left");#New password?
				$new_bsd_passz= $rem_top_bott->Entry()->pack(-side=>"left");

				sub add_bsd_new_user {
					$new_user_name=$new_bsd_user->get;
					$new_user_pass=$new_bsd_passz->get;
					$new_user_string="\"$new_user_name\"\t\*\t\"$new_user_pass\"\n";
					$new_auth="\"$new_user_name\"--\"$new_user_pass\"";
					$users_and_pass{$new_auth}=$new_user_string;

					open (FILE, ">/etc/ppp/pap-secrets");
					foreach $kulcsok (keys %users_and_pass) {
						print FILE $users_and_pass{$kulcsok};
					}
					close FILE;
					#`echo $new_user_string>>/etc/ppp/pap-secrets`;
					$remove_win->destroy;
					remove_window();
				}

				# user remove frame
				$rem_line_sz=$rem_bottom->Label(-fg=>'blue', -text=>lancolas($cl[167]))->pack(-anchor=>"c");
				$box7 = $rem_bottom->BrowseEntry( -variable=>\$rem_line)->pack(-anchor=>"c");
				foreach $kulcsok (keys %users_and_pass) {
    					$box7->insert("end", $kulcsok);
				}
				$kajli_rem1=$rem_bottom->Label()->pack;
				$removeuserbutton=$rem_bottom->Button(-text=>lancolas($cl[168]), -command=>\&remove_user)->pack(-pady=>"5");


			} else {
				return;
			}
		}

		sub remove_user {
			foreach $kulcsok (keys %users_and_pass) {
				if ($rem_line eq $kulcsok) {
					@deleted_u_p=split /\t/, $users_and_pass{$kulcsok};
					$deleted_user=$deleted_u_p[0];
					$deleted_user=~ tr/\"//d;
					chomp ($deleted_user);
					$deleted_pass=$deleted_u_p[2];
					$deleted_pass=~ tr/\"//d;
					chomp ($deleted_pass);

					delete($users_and_pass{$kulcsok});

					if ($deleted_user eq $user && $deleted_pass eq $passw) {
						undef $user;
						undef $passw;
					}
				}
			}
			open (FILE, ">/etc/ppp/pap-secrets");
			foreach $kulcsok (keys %users_and_pass) {
				print FILE $users_and_pass{$kulcsok};
			}
			close FILE;
    			$box7->delete('0.0', 'end');
			foreach $kulcsok (keys %users_and_pass) {
    					$box7->insert("end", $kulcsok);
			}
			$remove_win->destroy;
			remove_window();

		}

	} # end of rare_parameters subrutin

	sub lim_watch {
		read_some_setting();
		clean_sett_win();
		$lim_butt->configure(-state=>"disable");
		$j_right->configure(-label=>lancolas($cl[111])); #Limitfigyels
		# element of limit watching
		@honapnapjai=("--", 1..31);
		# date of earase in browseEntry
		$havit_sz=$back_sett->Label(-fg=>'blue', -text=>lancolas($cl[112])); #Trls napja
		$back_sett->createWindow(20, 15, -window=>$havit_sz, -anchor=>"w");
		$b15 = $back_sett->Balloon(-bg=>'yellow');
		$b15->attach($havit_sz,-msg=>lancolas($cl[115]));
		$box5 = $back_sett->BrowseEntry( -variable=>\$havit_v, -command=>\&havilimitvan);
    		$back_sett->createWindow(13, 35, -window=>$box5, -anchor=>"w");
		foreach (@honapnapjai) { #default
    			$box5->insert("end", $_);
		}


		$havilimit_sz=$back_sett->Label(-fg=>'blue', -text=>lancolas($cl[113])); #Havi max. adatforgalom (GB)
		$back_sett->createWindow(20, 55, -window=>$havilimit_sz, -anchor=>"w");
		$havilimit= $back_sett->Entry();
		$back_sett->createWindow(20, 75, -window=>$havilimit, -anchor=>"w");
		$havilimit->insert('end', $havilimit_v);
		havilimitvan ();
		sub havilimitvan {
			if ($havit_v =~ /\d/) {
				$havilimit->configure(-state=>"normal");
				$havilimit_sz->configure(-fg=>"blue");
			} else {
				$havilimit->delete('0.0','end');
				$havilimit->configure(-state=>"disabled");
				$havilimit_sz->configure(-fg=>"gray");
			}
		}

		$hetilimit_sz=$back_sett->Label(-fg=>'blue', -text=>lancolas($cl[114])); #Heti max. adatforgalom (MB)
		$back_sett->createWindow(20, 105, -window=>$hetilimit_sz, -anchor=>"w");
		$b16 = $back_sett->Balloon(-bg=>'yellow');
		$b16->attach($hetilimit_sz,-msg=>lancolas($cl[116]));
		$hetilimit= $back_sett->Entry();
		$back_sett->createWindow(20, 125, -window=>$hetilimit, -anchor=>"w");
		$hetilimit->insert('end', $hetilimit_v);


	} #end of lim_watch subrutin

	# offline statistics and erase of those
	sub offstat {
		read_some_setting();
		clean_sett_win();
		$offstat_butt->configure(-state=>"disabled");
		$forgalom=lancolas($cl[109]);
		$forgalom=~ tr/\://d;
		$j_right->configure(-label=>$forgalom); #Limitfigyels

		$start_y=16;

		# start date of the saving of the data

		$regtimekezd_szov=$back_sett->Label(-text=>lancolas($cl[84])); #kezdet ideje
		$back_sett->createWindow(10, $start_y+0, -window=>$regtimekezd_szov, -anchor=>'w' ); # kezd. id?
		$regtimekezd_v=$back_sett->Label(); #kezdet ideje
		$back_sett->createWindow(255, $start_y+0, -window=>$regtimekezd_v, -anchor=>'w' ); # kezd. id?

		$reg_time_kiir=$reg_time;
		$reg_time_kiir=~ tr /\;/\:/;
		$regtimekezd_v->configure(-text=>$reg_time_kiir); #kezdet ideje

		# Totally downloaded data

		$ob_l_szov=$back_sett->Label(-text=>lancolas($cl[28], $kivagy)); #Az EasyConnal sszesen letlttt adatok:
		$back_sett->createWindow(10, $start_y+20, -window=>$ob_l_szov, -anchor=>'w' );
		$ob_l=$back_sett->Label();
		$back_sett->createWindow(260, $start_y+20, -window=>$ob_l, -anchor=>'w' );
  		if (-e "$home/.gprsec/osszb_le") {
			$ob_l_v=`cat '$home/.gprsec/osszb_le'`;
		}
		$m_egy3=" byte";
		$oszb3=$ob_l_v;
		if ($ob_l_v>1024) {
			$oszb3=int(($ob_l_v/1024)*100)/100;
			$m_egy3=" KB";
		}
		$mb=1024*1024;
		if ($ob_l_v>$mb) {
			$oszb3=int(($ob_l_v/$mb)*1000)/1000;
			$m_egy3=" MB";
		}
		$ob_l->configure(-text=>"$oszb3 $m_egy3");

		# Totally uploaded data
		$ob_f_szov=$back_sett->Label(-text=>lancolas($cl[29], $kivagy)); #Az EasyConnal sszesen feltlttt adatok:
		$back_sett->createWindow(10, $start_y+40, -window=>$ob_f_szov, -anchor=>'w' );
		$ob_f=$back_sett->Label();
		$back_sett->createWindow(260, $start_y+40, -window=>$ob_f, -anchor=>'w' );

		if (-e "$home/.gprsec/osszb_fel") {
			$ob_f_v=`cat '$home/.gprsec/osszb_fel'`;
		}
		$m_egy4=" byte";
		$oszb4=$ob_f_v;
		if ($ob_f_v>1024) {
			$oszb4=int(($ob_f_v/1024)*100)/100;
			$m_egy4=" KB";
		}
		$mb=1024*1024;
		if ($ob_f_v>$mb) {
			$oszb4=int(($ob_f_v/$mb)*100)/100;
			$m_egy4=" MB";
		}
		$ob_f->configure(-text=>"$oszb4 $m_egy4");

		# All transmitted bytes

		$osszlefel_sz_sz=$back_sett->Label(-text=>lancolas($cl[109])); #sszesen Forgalmazott adatmennyisg:
		$back_sett->createWindow(10, $start_y+60, -window=>$osszlefel_sz_sz, -anchor=>'w' );
		$osszlefel_sz=$back_sett->Label(); #up and down
		$back_sett->createWindow(260, $start_y+60, -window=>$osszlefel_sz, -anchor=>'w' ); #fe s le

		$osszfl=$ob_l_v+$ob_f_v;
		$m_egy5=" byte";
		$oszb5=$osszfl;
		if ($osszfl>1024) {
			$oszb5=int(($osszfl/1024)*100)/100;
			$m_egy5=" KB";
		}
		$mb=1024*1024;
		if ($osszfl>$mb) {
			$oszb5=int(($osszfl/$mb)*100)/100;
			$m_egy5=" MB";
		}
		$osszlefel_sz->configure(-text=>"$oszb5 $m_egy5");

		# erase of data
		$addelbutt=$back_sett->Button(-fg=>red,
						-activebackground=>'red',
						-activeforeground=>'white',
						-command=>\&st_c,
						-text=>lancolas($cl[19])); # adattrlsek
		$back_sett->createWindow(20, $start_y+120, -window=>$addelbutt, -anchor=>'w' );

	} #end of offline statistics and erase of data

sub undef_set_elements {
	 undef $tel_duma;
	 undef $b2;
	 undef $tel_sz;
	 undef $tel_duma1;
	 undef $szolg_duma;
	 undef $szolg_sz;
	 undef $apn_w;
	 undef $b24;
	 undef $apn_w_v;
	 undef $user_name;
	 undef $b3;
	 undef $user_name_v;
	 undef $pass_w;
	 undef $b4;
	 undef $pass_w_v;
	 undef $lang_duma;
	 undef $lang_sz;
	 undef $figy2;
	 undef $rad;
	 undef $din_dns_sz;
	 undef $b25;
	 undef $dns1_sz1;
	 undef $b6;
	 undef $dns1_e1;
	 undef $dns1_sz2;
	 undef $b7;
	 undef $dns1_e2;
	 #optional
	 undef $spped_sz;
	 undef $boxa1;
	 undef $panel_sz;
	 undef $cw_ic_sz;
	 undef $panel_on_co;
	 undef $b_sz;
	 undef $b8;
	 undef $box2;
	 undef $reconn_sz;
	 undef $box3;
	 undef $rec_db_sz;
	 undef $rec_db_scale;
	 undef $bg_rec_sz;
	 undef $b9;
	 undef $cikl_seb_sz;
	 undef $b10;
	 undef $idres_scale;
	 undef $auto_csat_sz;
	 undef $auto_csat_cs;
	 undef $silent;
	 undef $compact;
	# rare
	 undef $spec_tel_sz;
	 undef $b12;
	 undef $spec_tel;
	 undef $cid_sz;
	 undef $b13;
	 undef $box4;
	 undef $no_cgq_sz;
	 undef $b14;
	 undef $no_auth_sz;
	 undef $b15;
	 undef $bsd_comp_sz;
	 undef $b17;
	 undef $no_dev_sz;
	 undef $b20;
	 undef $debug_mod;
	 undef $b18;
	# limit watching
	 undef $havit_sz;
	 undef $b15;
	 undef $box5;
	 undef $havilimit_sz;
	 undef $havilimit;
	 undef $hetilimit_sz;
	 undef $b16;
	 undef $hetilimit;
	# transmitted data
	 undef $regtimekezd_szov;
	 undef $regtimekezd_v;
	 undef $ob_l_szov;
	 undef $ob_l;
	 undef $ob_f_szov;
	 undef $ob_f;
	 undef $osszlefel_sz_sz;
	 undef $osszlefel_sz;
	 undef $addelbutt;
}

MainLoop();

} # here's the end of configuration window

#####################################
# Saving of the configuration data #
#####################################

sub reg {
	winbezar ();
	if (!$idores || $idores <200){$idores=200}
	if (!$connspeed) {$connspeed=57600}
	#if (!$reconn_on && $id_disc) {
	#	$id_disc->cancel;
	#	undef $id_disc;
	#} else {
	#	if (!$id_disc) {
	#		$id_disc = $winconn->repeat(100,=>\&ujrakapcs_figy);
	#	}
	#}
	# configuration blank error
	if (!$phonetype || !$kivp || !$sel_lang || !$sel_szolg) {
		$osszhiba=$cl[69];
		if (!$phonetype) {
			push (@confhibak, $cl[70]);
		}
		if (!$kivp) {
			push (@confhibak, $cl[71]);
		}
		if (!$sel_lang) {
			push (@confhibak, $cl[72]);
		}
		if (!$sel_szolg) {
			push (@confhibak, $cl[73]);
		}
		foreach (@confhibak) {
			$osszhiba.="\n$_";
		}
		hiba (lancolas($osszhiba));
		undef $osszhiba;
		undef @confhibak;
		return;

	}

	##############################
	# making of chat script      #
	##############################

	$sel_szolg_on=$def_apn;
	chomp $sel_szolg_on;
	$chat_file=$chat_eleje."\n".$teltype{$phonetype};
	$chat_file=~s /\?\?\?/$sel_szolg_on/e;
	($mp, $perc, $ora, $nap, $honap, $ev)=localtime();
	$honap++;
	$ev+=1900;
	$chatduma="\n# GPRS Easy Connect program ekkor mdostotta: $ev.$honap.$nap\n";
	$chat_file.=$chatduma."\n";

	#  building of CID
	if ($cid && $cid ne "--") {
		$chat_file=~s /CGDCONT\=\d+/"CGDCONT\=".$cid/ge;
		$chat_file=~s /CGQREQ\=\d+/"CGQREQ\=".$cid/ge;
		$chat_file=~s /CGQMIN\=\d+/"CGQMIN\=".$cid/ge;
		$chat_file=~s /(\*\d+)(\*+)\d+\#/$1.$2.$cid."#"/ge;
	}

	# personal phone number
	if ($other_numb) {
		$chat_file=~s /\*\d+\*+\d+\#/$other_numb/ge;
	}

	# forbidding of CGQ commands
	if ($no_cgq==1) {
		@chat_file_t=split /\n/, $chat_file;
		undef $chat_file;
		foreach (@chat_file_t) {
			foreach $ch_temp (qw/ATS0 CGQREQ CGQMIN CGATT/) {
				if (/$ch_temp/) {
					undef $_;
				}
			}
			$ttt++;
			if ($_) {
				$chat_file.=$_."\n";
			}
		}
	}

	# writing of chat script
	$tempfilename=">$home/.gprsec/chat";
	open (FILE, $tempfilename);
	chmod 0666, $tempfilename;
	print FILE $chat_file;

	##############################
	# building of the pppd script#
	##############################

	$kivp_on=$ports{$kivp};
	$alap=`cat '$gprs_shared_path/gprsec/tools/gprs-conn-script'`;
	$conn_user="\n".$kivp_on;

	if ($user eq lancolas($cl[87])) {
		$user="unknown";
	}

	if ($passw eq lancolas($cl[87])) {
		$passw="unknown";
	}

	if (!$user) {
		$user="";
	}

	if (!$passw) {
		$passw="";
	}


	# set of the static DNS(s)
	if ($kivagy eq "root" && $dns1 && !$din_eng) {
		$res_file="search localdomain\n\nnameserver $dns1\nnameserver $dns2\n";
		open (FILE, ">/etc/resolv.conf");
		print FILE $res_file;
		close FILE;
	}

	if ($m_KernelName eq "Linux") {
		$disconnect_script="\ndisconnect '/usr/sbin/chat -e -f $gprs_shared_path/gprsec/tools/disconnect -v'";
		$conn_sor="\nconnect '/usr/sbin/chat -e -f $home/.gprsec/chat -v'";
		$egyben=$alap.$disconnect_script.$conn_sor.$conn_user."\nuser $user"."\npassword $passw";
		if ($din_eng) {
			$egyben.="\n#Enable the DNSs from server";
			$egyben.="\nusepeerdns";
		}
		$egyben.="\n#With this option, pppd will accept all control characters from the peer, including those marked in the receive asyncmap";
		$egyben.="\nreceive-all";
		# pipe for pppd
		$egyben.="\n"."logfile ".'"'."$home/.gprsec/conn.log".'"'."\n";
	}

	if ($m_KernelName eq "FreeBSD") {
		$disconnect_script="disconnect '/usr/bin/chat -e -f $gprs_shared_path/gprsec/tools/disconnect -v'";
		$conn_sor="\nconnect '/usr/bin/chat -e -f $home/.gprsec/chat -v'";
		$egyben=$alap.$disconnect_script.$conn_sor.$conn_user."\nuser $user";
	}


	if ($no_auth && $kivagy eq "root") {
		$egyben.="\n#Do  not  require  the  peer to authenticate itself.";
		$egyben.="\nnoauth";
	}

	if (!$bsd_comp) {
		$egyben.="\nnobsdcomp";
		$egyben.="\nnodeflate";
	}

	# building the CDMA system chat script
	if ($phonetype=~ /Ac555_/) {
		$alap=`cat '$gprs_shared_path/gprsec/tools/cdma-conn-script'`;
		if ($m_KernelName eq "Linux") {
			$disconnect_script="disconnect '/usr/sbin/chat -e -f $gprs_shared_path/gprsec/tools/disconnect -v'";
			$conn_sor="\nconnect '/usr/sbin/chat -e -t3 -f $home/.gprsec/chat -v'";
			$conn_user="\n".$kivp_on;
			$egyben=$alap.$disconnect_script.$conn_sor.$conn_user."\nuser $user"."\npassword $passw";
			$egyben.="\n"."logfile ".'"'."$home/.gprsec/conn.log".'"'."\n";
		}
		if ($m_KernelName eq "FreeBSD") {
			$disconnect_script="disconnect '/usr/bin/chat -e -f $gprs_shared_path/gprsec/tools/disconnect -v'";
			$conn_sor="\nconnect '/usr/bin/chat -e -t3 -f $home/.gprsec/chat -v'";
			$conn_user="\n".$kivp_on;
			$egyben=$alap.$disconnect_script.$conn_sor.$conn_user."\nuser $user";
		}
	}

	$speed_change="# Speed\n$connspeed";
	$egyben=~s /\# Speed\n\d+/$speed_change/e;

	$tempfilename=">$home/.gprsec/run";
	open (FILE, $tempfilename);
	chmod 0666, $tempfilename;
	print FILE $egyben;


	####################################
	# Save the configuration data      #
	####################################

	# set of the data of reconnect
	if (!$reconn_on || $reconn_on eq "--") {
		undef $reconn_on;
	}

	# set of the browser's data
	if ($brow eq "--" or !$brow) {
		$br_on=0;
		$brow="";
	} else {$br_on=1}
	#$brow_path=$browser_path{$brow};

	if (!$reg_time) {
		($mp, $perc, $ora, $nap, $honap, $ev)=localtime();
		$honap++;
		$ev+=1900;
		$reg_time=" $ev/$honap/$nap $ora;$perc";
	}

	# reading of special CID
	if ($cid eq "--") {undef $cid}

	$havilimit_v=~s /\,/\./;
	$hetilimit_v=~s /\,/\./;
	if ($honap_old!=$honap) {
		$honap=$honap_old;
	}

	if (!$no_dev) {
		$nodev=0;
	}
	
	$newly=1;
	new_config_save();
	

	# saving username and password under FreeBSD
	if ($m_KernelName eq "FreeBSD" && $kivagy eq "root") {
		$new_user_pass="\\\"$user\\\"\t*\t\\\"$passw\\\"";
		`echo "$new_user_pass" >>/etc/ppp/pap-secrets`;
	}

	undef $c;
	undef $qss;
	undef $kivp;
	undef $kivp_on;
	undef $egyben;
	undef $conn_sor;
	undef $conn_user;
	undef $alap;
	undef $ss;
	undef $ssa;
	undef @rad;
	undef $qsa;
	undef @nyelv;
	undef @cl;
	undef %ports;
	undef $cw_ic;
	undef $sel_szolg;
	undef $user;
	undef $passw;
	undef $chat_file;
	undef $reconn_on;
	undef $idores;
	undef $reg_time;
	undef $din_eng;
	undef $cid;
	undef $dns1;
	undef $dns2;
	undef $no_beep;
	undef $bg_rec;
	undef $reconn_db;
	undef $no_cgq;
	undef $other_numb;
	undef @van_lang;
	undef $havit_v;
	undef $havilimit_v;
	undef $hetilimit_v;
	undef $honap;
	undef $no_auth;
	undef $debug;
	undef $bsd_comp;
	undef $connspeed;
	undef $no_dev;
	undef $no_find;
	undef $def_apn;
	$connconf->destroy;
	$winconn->destroy;
	read_conf ();
	nyelvbeolv ();
	foablak ();
} # end of the data save subrutine

##################
# window of erase
##################
sub st_c {
	if ($delwin) {
		$delwin->focusForce;
		$delwin->raise();
		$delwin->deiconify;
		return;
	}
	$delwin=MainWindow->new();
	$delwin->title(lancolas($cl[119]));
			$delwinx=$xfele-100;
			$delwiny=$yfele-100;
			$delwin->geometry("+$delwinx+$delwiny");
	$delwin->OnDestroy(\sub {undef $delwin});
	$delad[1]=$delwin->Checkbutton(-fg=>'blue', -text=>lancolas($cl[120]),-variable=>\$delhavi)->pack(-anchor=>'w'); #Havi adatforgalom trlse
	$delad[2]=$delwin->Checkbutton(-fg=>'blue', -text=>lancolas($cl[121]),-variable=>\$delheti)->pack(-anchor=>'w'); #Heti adatforgalom trlse
	$delad[3]=$delwin->Checkbutton(-fg=>'blue', -text=>lancolas($cl[122]),-variable=>\$del5perc)->pack(-anchor=>'w'); #tperces tlagok trlse
	$delad[4]=$delwin->Checkbutton(-fg=>'blue', -text=>lancolas($cl[123]),-variable=>\$delido)->pack(-anchor=>'w'); #Forgalmi id? trlse

	$ment_yes=$delwin->Button(-text=>lancolas ($cl[93]), -command=>\&delsub)->pack(-side=>"left"); #Rendben
	$del_cancel=$delwin->Button(-text=>lancolas ($cl[57]), -command=>sub {[$delwin->destroy, undef $delwin]})->pack(-side=>"right"); #mgse
	sub delsub {
		# erase of data transmissions
		if ($delhavi) {
			foreach (qw/osszb_fel osszb_le/) {
				if (-e "$home/.gprsec/$_") {
				`rm '$home/.gprsec/$_'`;
				}
			}
			# begin of the saving of statisctic data
		
			($mp, $perc, $ora, $nap, $honap, $ev)=localtime();
			$honap++;
			$ev+=1900;
			
			read_config_file();
			
			$temp[13]="  $ev/$honap/$nap $ora;$perc";
			
			read_config_file();
			
		}
		# erase of weakly data
		if ($delheti) {
			foreach (qw/7d.dir 7d.pag/) {
				if (-e "$home/.gprsec/$_") {
				`rm '$home/.gprsec/$_'`;
				}
			}
		}
		# erase 5 minutes averages
		if ($del5perc) {
			if (-e "$home/.gprsec/sp_stat") {
			$tempfilename=">$home/.gprsec/sp_stat";
			open (FILE, $tempfilename);
			chmod 0666, $tempfilename;
			for ($x=1; $x<=288; $x++) {
				print FILE "$x\:\:\:\n";
			}
			close FILE;
			}
		}
		# erase of total time
		if ($delido) {
			if (-e "$home/.gprsec/ossz_ido") {
				`rm '$home/.gprsec/ossz_ido'`;
			}
		}
	$delwin->destroy;
	undef $delwin;
	read_conf ();
	}
MainLoop();
}

sub font_t_sub {
	if ($fontwin) {
		$fontwin->focusForce;
		$fontwin->raise();
		$fontwin->deiconify;
		return;
	}
	$fontwin=MainWindow->new();

	$fontwin->OnDestroy(\sub {undef $fontwin});
	$font_text_path="$gprs_shared_path/gprsec/languages/".$sel_lang."_imp";
	if (-e "$font_text_path") {
		$font_text=`cat $font_text_path`;
	}
	$fontwin->title (lancolas($cl[16])); #Fontos tudnivalk
			$fontwinx=$xfele-300;
			$fontwiny=$yfele-300;
			$fontwin->geometry("+$fontwinx+$fontwiny");
	$figy=$fontwin->Label(-justify=>'left', -fg=>'red', -text=>lancolas($cl[6]))->pack(); #Fontos tudnivalk
	$fontos_sz=$fontwin->Text();

	$scroll_6 = $fontwin->Scrollbar(-command=>['yview', $fontos_sz]);
	$fontos_sz->configure(-yscrollcommand=>['set', $scroll_6]);
	$scroll_6->pack(-side=>'right', -fill=>'y');
	$fontos_sz->pack(-side=>'left', -fill=>'both', -expand=>1);
	$fontos_sz->insert('end', $font_text);
}

sub aut_save {

	read_config_file();

	$temp[5]=$autocsat;
			
	read_config_file();

}

sub nyelvbeolv {
# reading the languages
# the default is the english
# the algotythm overwrites the english texts to the translated texts
	undef $clx;
	undef @temp_cl;
	$temp_cl[0]=" ";
	open (FILE, "<$gprs_shared_path/gprsec/languages/english");
	binmode FILE;
	while ($sor=<FILE>) {
		chomp $sor;
		$sor=~s /\\n/\n/g;
		binmode $sor;
		push (@temp_cl, $sor);
	}

	$cl[0]=" ";
	open (FILE, "<$gprs_shared_path/gprsec/languages/$sel_lang");
	binmode FILE;
	while ($sor=<FILE>) {
		chomp $sor;
		$sor=~s /\\n/\n/g;
		binmode $sor;
		push (@cl, $sor);
	}
	#overwite of the english
	$tempsl_len=@temp_cl;
	for ($clx=0; $clx<=$tempsl_len; $clx++) {
		if (!$cl[$clx] && $temp_cl[$clx]) {
			$cl[$clx]=$temp_cl[$clx];
		}
	}
}


sub lancolas {
	# subrutin if the print of texts
	undef $kirak;
	undef $po;
	@l_temp=split /\*\*\*/, $_[0];
	foreach (@l_temp) {
		$po++;
		$kirak.="$_$_[$po]";
	}
	return $kirak;
}

##############################
# main window
###############################

sub foablak {

	if (!$compact) {

		$winconn=MainWindow->new();
		$winconn->title ("GPRS Easy Connect v$ver");
		$winconn->maxsize('400','300');
		$winconn->minsize('400','300');
		$winconn->appname("fo");
				$winconnx=$xfele-200;
				$winconny=$yfele-150;
				$winconn->geometry("+$winconnx+$winconny");
		$winconn->OnDestroy(\sub { ec_prgs_kill(); winbezar(),  connconf_zar() });

		# graphical layer
		$back=$winconn->Canvas(-width=>400, -height=>300)->pack();

		# background image
		$pic=$winconn->Photo(-file=>"$gprs_shared_path/gprsec/images/ind.gif");
		$back->createImage(200,150, -image=>$pic);

		# version number and the dropped shadow
		$back->create(text, 200,31, -font=>[utopia, 20, bold, italic], -fill=>"#353535", -text=>"GPRS Easy Connect" , -anchor=>'c');
		$back->create(text, 199,30, -font=>[utopia, 20, bold, italic], -fill=>"#a01e1e", -text=>"GPRS Easy Connect", -anchor=>'c');

		$back->create(text, 200,61, -font=>[utopia, 14, bold, italic], -fill=>"#353535", -text=>"... for Linux and FreeBSD" , -anchor=>'c');
		$back->create(text, 200,60, -font=>[utopia, 14, bold, italic], -fill=>"#a01e1e", -text=>"... for Linux and FreeBSD", -anchor=>'c');


		# connect button
		$button=$winconn->Button (-text=>"$cl[1]", #Csatlakozs
                	          -command=>\&last_conn_rm_konn,
				  -bg=>'#9dea7e',
			  	-activebackground=>'#d4fcc2');  # a konnekt sub hvsa
		$back->createWindow(75, 115, -window=>$button);

		# provider
		$prov_name=$winconn->Label(-bg=>'white', -width=>33, -height=>1, -bd=>2, -relief=>'sunken');
		$prov_name->configure(-text=>$sel_szolg, -anchor=>'w');
		$back->createWindow(20, 205, -window=>$prov_name, -anchor=>"w");

		# name of the connecting port
		$port_name_sz=$winconn->Label(-bg=>'white', -text=>$kivp, -width=>33, -height=>1, -bd=>2, -relief=>'sunken', -anchor=>"w");
		$back->createWindow(20, 235, -window=>$port_name_sz, -anchor=>"w");

		# disconnect button
		$disconn=$winconn->Button (-state=>disabled);
		$disconn->configure (-bg=>'red', -text=>"$cl[2]",
				-activebackground=>'#ff7777',
				-command=>\&diskonnect); #megszakts
		$back->createWindow(325, 115, -window=>$disconn);

		nincsk ();

		# info
		$help=$winconn->Button (-text=>lancolas($cl[82]), -command=>\&help); #Info

		$back->createWindow(37, 283, -window=>$help);

		# config
		$buttonx=$winconn->Button (-text=>"$cl[3]", -command=>\&connconf); #EasyConn belltsa.
		$back->createWindow(190, 283, -window=>$buttonx);

		# exit button
		$button_out=$winconn->Button (-text=>"$cl[4]", -command=>\&exit_1); #Kilps
		$back->createWindow(360, 283, -window=>$button_out);


		if ($autocsat==1) {
			konnect ();
		}
	#compact mode	
	} else { 
		$winconn=MainWindow->new();
		$winconn->title ("GPRS Easy Connect v$ver");
		$winconn->maxsize('250','50');
		$winconn->minsize('250','50');
		$winconn->appname("fo");
				$winconnx=$xfele-170;
				$winconny=$yfele*2-50;
				$winconn->geometry("+$winconnx+$winconny");
		$winconn->OnDestroy(\sub {winbezar(),  connconf_zar(), disckonnect ()});

		# graphical layer
		$back=$winconn->Canvas(-width=>400, -height=>300)->pack();

		# background image
		$pic=$winconn->Photo(-file=>"$gprs_shared_path/gprsec/images/ind.gif");
		$back->createImage(200,150, -image=>$pic);
		
		# connect button
		$button=$winconn->Button (-text=>"$cl[1]", #Csatlakozs
                	          -command=>\&last_conn_rm_konn,
				  -bg=>'#9dea7e',
			  	-activebackground=>'#d4fcc2');  # a konnekt sub hvsa
		$back->createWindow(5, 20, -window=>$button, -anchor=>"w");
		
		# disconnect button
		$disconn=$winconn->Button (-state=>disabled);
		$disconn->configure (-bg=>'red', -text=>"$cl[2]",
				-activebackground=>'#ff7777',
				-command=>\&diskonnect); #megszakts
		$back->createWindow(140, 20, -window=>$disconn, -anchor=>"w");
		
		$comp_main = $back->Checkbutton(-text=>lancolas($cl[189]), -variable=>\$compact, -command=>sub {comp_sub(); $winconn->destroy; read_conf ();nyelvbeolv ();foablak ()});
		$back->createWindow(50, 40, -window=>$comp_main, -anchor=>"w");
		$bcom2 = $back->Balloon(-bg=>'yellow');
		$bcom2->attach($comp_main,-msg=>lancolas($cl[191]));

sub comp_sub {

	read_config_file();
	
	$temp[34]=$compact;
			
	write_config_file();
	if ($compact=0) {
		undef $comp_main;
	}
}
	
		if ($autocsat==1) {
			konnect ();
		}
	}
$winconn->update;

} # end of Main window

sub read_conf {
	# delete of the previously error file
	if (-e "$ENV{HOME}/.gprsec/error") {
		`rm $ENV{HOME}/.gprsec/error`;
	}
	# read previous (old) configs
	open (FILE, "<$home/.gprsec/EasyConn.config");
	$sor=<FILE>;
	close FILE;
	@spl=split /\:/, $sor;

	#change (if needed) to the new config architecture
	$tempspl=@spl;
	if ($tempspl>1) {
		$old_bad=1;
	}
	
	if (!$old_bad) {
		# read previous (new) configs
		undef @spl;
		undef @spl_comment;
		open (FILE, "<$home/.gprsec/EasyConn.config");
			while ($sor=<FILE>) {
				@spl_temp=split /\#/, "$sor";
				push (@spl, $spl_temp[0]);
				push (@spl_comment, "#".$spl_temp[1]);
			}
		close FILE;
		undef $old_bad;
	}
	
	$phonetype=$spl[0];
	$kivp=$spl[1];
	$co_pan=$spl[2];
	$brow=$spl[3];
	$br_on=$spl[4];
	$autocsat=$spl[5];
	$sel_lang=$spl[6];
	$cw_ic=$spl[7];
	$sel_szolg=$spl[8];
	$user=$spl[9];
	$passw=$spl[10];
	$reconn_on=$spl[11];
	$idores=$spl[12];
	$reg_time=$spl[13];
	$din_eng=$spl[14];
	$cid=$spl[15];
	$dns1=$spl[16];
	$dns2=$spl[17];
	$no_beep=$spl[18];
	$bg_rec=$spl[19];
	$reconn_db=$spl[20];
	$no_cgq=$spl[21];
	$other_numb=$spl[22];
	$havit_v=$spl[23];
	$havilimit_v=$spl[24];
	$hetilimit_v=$spl[25];
	$honap_old=$spl[26];
	$no_auth=$spl[27];
	$debug=$spl[28];
	$bsd_comp=$spl[29];
	# continued below

	$def_language=$ENV{LANG};
	$lang{cs_CZ}="cesky";
	$lang{de_DE}="deutsch";
	$lang{de_AT}="deutsch";
	$lang{fi_FI}="suomi";
	$lang{fr_FR}="franais";
	$lang{hu_HU}="magyar";
	$lang{it_IT}="italiano";
	$lang{es_ES}="espanol";
	$lang{tr_TR}="trkce";

	# set the default language
	if (!$sel_lang) {
		foreach $keys (keys %lang) {
			if ($keys eq $def_language) {
				$sel_lang=$lang{$def_language};
			}
		}
	}

	if (!$sel_lang) { # if the user's language is not translated then the english will be the default
		$sel_lang="english";
	}

	if ($reconn_db<3) {
		$reconn_db=3;
	}
	$connspeed=$spl[30];
	$no_dev=$spl[31];
	$no_find=$spl[32];
	$def_apn=$spl[33];
	$compact=$spl[34];
	$newly=$spl[35];
	$apnid=$spl[36];
	
	chomp ($apnid);
	
	if ($old_bad) {
		new_config_save();
		# read previous (new) configs
		undef @spl;
		undef @spl_comment;
		open (FILE, "<$home/.gprsec/EasyConn.config");
			while ($sor=<FILE>) {
				@spl_temp=split /\#/, "$sor";
				push (@spl, $spl_temp[0]);
				push (@spl_comment, "#".$spl_temp[1]);
			}
		close FILE;
		undef $old_bad;
	}
	
	# trying to wake up the earlier selected port
	$try_port=$kivp;
	$try_port=~ s/\((\S+)\)/$1/e;
	$try_port=$1;
	`$try_port 2>/dev/null`;
	
} # end of the setting reading sub

# watching of the successful connection
sub be {
	if (-e "$home/.gprsec/dns") {
		succ_conn ();
	}
}
# settings after a successful connection
sub succ_conn {
	if ($box6) {
		$box6->configure(-state=>"normal");
	}

	if ($upgrade_butt) {
			$upgrade_butt->configure(-state=>"normal");
	}
	if ($donate_butt) {
			$donate_butt->configure(-state=>"normal");
	}
	$successful=1;
	if ($cw_ic && $icwas==0) {
		$winconn->iconify;
		$icwas=1;
	}
	# starting the browser
	if ($br_on==1 && !$pid1) {
		$SIG{INT} = sub {wait};
		socketpair (PARENT, CHILD, PF_UNIX, SOCKET_STREAM, 0);
		if ($pid1=fork()) {
			close PARENT;
			select CHILD;
			$|=1;
			select STDOUT;
		} elsif (defined $pid1) {
			open (STDIN, ">&PARENT");
			open (STDOUT, ">&PARENT");
			close PARENT;
			select STDOUT;
			$|=1;
			exec ("$brow");
			exit;
		}
	}

	$id->cancel;
	undef $id;
	
	# if you don't want to send us your phone type and your provider's name for our statistics
	# please comment the following lines
	# Otherwise thank you for co-operation!
	# serverupdate: apn, dns
	
	
	open (FILE, "<$home/.gprsec/dns");
	while ($sor=<FILE>) {
		push (@getdns, $sor);
	}
	
	# serverupdate: conn. stats, new phone's chat script
	$ascii_sel_szolg=$sel_szolg;
	$ascii_sel_szolg=~ s/\n/\@10\@/g;
	$ascii_sel_szolg=~ s/\#/\@83\@/g;
	$ascii_sel_szolg=~ s/\*/\@90\@/g;
	$ascii_sel_szolg=~ s/\&/\@38\@/g;
	$ascii_sel_szolg=~ s/\ /\@32\@/g;
	
	
	if ($newly) {
		$doc1 =get ("http://www.easyconnect.linuxuser.hu/get_apn.php?provider_id=$apnid&provider_name=$ascii_sel_szolg&apn=$def_apn&username=$user&primary_dns=$getdns[0]&secondary_dns=$getdns[1]");
	}
	undef $newly;
	new_config_save();
	

	$doc=get ("http://www.easyconnect.linuxuser.hu/connect_cnt.php?op=inc&phone=$phonetype&phone_id=$phoneids{$phonetype}&provider=$ascii_sel_szolg&provider_id=$apnid");
		
	if ($doc==1) { # getting chat script
		open (FILE, "<$home/.gprsec/chat");
		while ($sor=<FILE>) {
			$sor=~ s/\n/\@10\@/g;
			$sor=~ s/\#/\@83\@/g;
			$sor=~ s/\*/\@90\@/g;
			$sor=~ s/\&/\@38\@/g;
			$sor=~ s/\ /\@32\@/g;
			$chat_sc.=$sor;
		}
		$doc2= get ("http://www.easyconnect.linuxuser.hu/get_script.php?name=$phonetype&data=$chat_sc");
	}
}


sub last_conn_rm {
	# erase of the previously conn.log file
	if (-e "$home/.gprsec/conn.log") {
		`rm '$home/.gprsec/conn.log'`;
	}
	if (-e "$home/.gprsec/re") {
	`rm '$home/.gprsec/re'`;
	}
}

sub last_conn_rm_konn {
	undef $reconcount;
	last_conn_rm ();
	$successful=0;
	konnect ();
}


sub ujrakapcs_figy {
	if (-e "$home/.gprsec/disc") {
		ujrakapcs ();
	}
}

sub ujrakapcs {
	if ($reconn_on) {
		ec_prgs_kill ();
		$disconn->configure (-state=>'disabled');
		# erase of the disconnect signer file
		`rm '$home/.gprsec/disc'`;
		if (-e "$home/.gprsec/conn.log") {
			`rm '$home/.gprsec/conn.log'`;
		}
		# reconnect window
		$rewin = MainWindow->new;
		if ($bg_rec==0) {
			$rewin->title(lancolas($cl[56]));
		} else {
			$rewin->title($reconn_on);
			$rewin->iconify;
		}

		$ujrak_time=$reconn_on;
		$ujrcikl = $ujrak_time;
		$countdown1 = $rewin->Label(-text=>lancolas($cl[55]))->pack;
		$no_reconn=$rewin->Button(-text=>lancolas($cl[57]), -command=>\sub {$stop_cd=1, $ujrcikl=0})->pack(-side=>'bottom');
		$countdown = $rewin->Label();
		$countdown->pack;
		$greadwinx=$xfele-100;
		$greadwiny=$yfele-100;
		$rewin->geometry("+$greadwinx+$greadwiny");

		while ($ujrcikl>=1) {
    			$rewin->after(1000);
			$ujrcikl--;
    			$countdown->configure(-text=>$ujrcikl);
			if ($bg_rec==0) {
				$rewin->title(lancolas($cl[56]));
			} else {
				$rewin->title($ujrcikl);
			}
    			$rewin->update;
    		}
		undef $id_disc;
		$rewin->destroy;
		undef $rewin;
		if ($stop_cd==1) {
			diskonnect ();
			undef $stop_cd;
		} else {
			diskonnect ();
			$tempfilename=">$home/.gprsec/re";
			open (FILE, $tempfilename);
			chmod 0666, $tempfilename;
			close FILE;
			$reconcount++;
			if ($reconcount>($reconn_db-1)) {
				elegemvan ();
				return;
			}
			konnect ();
		}
	}

}

sub read2_x {
	# monitoring of the port-authority
	if (-e "$ENV{HOME}/.gprsec/error") {
		$_=`cat $ENV{HOME}/.gprsec/error`;
		if (/unrecognized option \'\/dev\//) {
			hiba (lancolas($cl[137]));
			diskonnect ();
			`rm $ENV{HOME}/.gprsec/error`;
		}
	}
	# if the read2.pl is not running, then: disconnect!
	$read2pl_pid=`ps ax | grep "/usr/bin/perl $gprs_bin_path/read2.pl"\$`;
	$read2pl_pid=~ s/(\d+)/$1/e;
	$read2pl_pid=$1;
	if (!$read2pl_pid) {
		# bravetti's kill:
		ec_prgs_kill();
		#ec_kill_all_pids();
		$id_read2pl->cancel;
		undef $id_read2pl;
		$button ->configure (-state=> 'normal');
		$disconn->configure (-state => 'disabled');
		if (!$compact) {
			$buttonx ->configure (-state=> 'normal'); 
		}
	}
}


#######################################
# too much reconnect rehearsal's window
#######################################
sub elegemvan {
	$reconn_his=MainWindow->new();
	$reconn_his->title (lancolas($cl[91]," $ver ")); #hiba
			$reconn_hisx=$xfele-100;
			$reconn_hisy=$yfele-100;
			$reconn_his->geometry("+$reconn_hisx+$reconn_hisy");
	$reconn_his->configure(-bg=>'white');
	$h_reconn_sz=$reconn_his->Label(-fg=>'red', -relief=>'sunken', -borderwidth=>1, -text=>lancolas($cl[92]), -bg=>'white')->pack();
	$h_reconn_sz=$reconn_his->Button(-text=>lancolas($cl[93]), -command=>\&izebigyo)->pack();
	sub izebigyo {

	$winconn->focusForce;
	$reconn_his->destroy;
	$winconn->raise();
	$winconn->deiconify;

	}
	diskonnect ();
MainLoop();
}

# closing of the running windows
sub winbezar {
	if ($conn_his) {
		$conn_his->destroy;
		undef $conn_his;
	}
	if ($delwin) {
		$delwin->destroy;
		undef $delwin;
	}
	if ($fontwin) {
		$fontwin->destroy;
		undef $fontwin;
	}
	if ($keszwin) {
		$keszwin->destroy;
		undef $keszwin;
	}
	if ($upgpwin) {
		$upgpwin->destroy;
		undef $upgpwin;
	}
	if ($remove_win) {
		$remove_win->destroy;
		undef $remove_win;
	}


}
sub connconf_zar {
	if ($connconf) {
		$connconf->destroy;
		undef $connconf;
	}
}



sub telcsibeolv {
	undef %teltype;
	# read the phone's script from the $gprs_shared_path/gprsec/tools dir
	if (-e "$gprs_shared_path/gprsec/tools/gprs-chat-scripts") {

			$telcsik_fajl=`cat "$gprs_shared_path/gprsec/tools/gprs-chat-scripts"`;

	}
	@telcsik3=split /\[/, $telcsik_fajl;
	shift (@telcsik3);
	foreach (@telcsik3) {       
		$_=~tr /\]//d;
		@temptel = split /\n/, $_; 
		$lentemptel=@temptel;
		@id_tel=split /\|/, $temptel[0];
		$phone_id=$id_tel[0];
		$temptel[0]=$id_tel[1];
		
		if (!$temptel[0]) {
			$temptel[0]=$phone_id;
			undef $phone_id;
		} else {
			$phoneids{$temptel[0]}=$phone_id;
		}
	
		$temptel2=$temptel[0];
		$temptel2=~tr /\*//d;
		$telcsikepek{$temptel2}=$temptel[1];
		for ($sx=2; $sx<=$lentemptel; $sx++) {
			if ($debug) {
				$teltype{$temptel[0]}.="SAY '\\nC#".$sx."'\n".$temptel[$sx]."\n\n"; # ha a debug md aktv
			} else {
				$teltype{$temptel[0]}.=$temptel[$sx]."\n";
			}
		}
	}
}

sub port_scan {
# new port_scan
# andrea 'brand77' bravetti
# andrea.bravetti@freeinternet.it
	$m_findp="find /dev -type c -path";
	if ($m_expert > 0) { $m_limit="[0-9]*"; }
	else { $m_limit="[0-7]"; }
	if ($m_KernelName eq "Linux") {
		port_add("COM", `$m_findp '*\/dev\/tts\/$m_limit' ;
		$m_findp '*\/ttyS$m_limit'`);
		port_add("USB-COM", `$m_findp '*usb\/tts\/$m_limit' ;
		$m_findp '*\/ttyUSB$m_limit'`);
		port_add("USB-ACM", `$m_findp '*\/acm\/$m_limit' ;
		$m_findp '*\/ttyACM$m_limit'`);
		port_add("USB-Bluetooth", `$m_findp '*\/ttub\/$m_limit';
		$m_findp '*\/ttyUB$m_limit'`);

		port_add("IrDa", `$m_findp '*\/ircomm$m_limit';
		$m_findp '*\/ircomm\/$m_limit'`);
		port_add("Bluetooth", `$m_findp '*\/rfcomm$m_limit';
		$m_findp '*\/rfcomm\/$m_limit'`);

	}
	if ($m_KernelName eq "FreeBSD") {
		port_add("COM", `$m_findp '\/dev\/cuaa$m_limit'`);
		port_add("USB-COM", `$m_findp '\/dev\/ucom$m_limit'`);
		port_add("USB-Bluetooth", `$m_findp '\/dev\/ubt$m_limit'`);
	}

	sub port_add {
		local($m_descr, @m_device) = @_;
		$m_count=0;
		chomp (@m_device);
		foreach (@m_device) {
   if ($m_expert) { $m_newdescr="$_ (".$m_descr.")";
			} else {
				$m_count=$m_count + 1;
				if ($m_count > 9) { $m_filler=""; } else { $m_filler="0"; }
				$m_newdescr=$m_descr." $m_filler$m_count ($_)";
			}
			$ports{$m_newdescr}="$_";
		}
	}

vanport();

	sub vanport {
		undef $vanhiba;
		
		# checking of the "living" selected port
		foreach $letezoportok (keys %ports) {
			if ($letezoportok eq $kivp) {
				$vanegyezoport=1;
			}
		}
		if ($vanegyezoport!=1  && $kivp) {
			hiba(lancolas($cl[137]));
			$vanhiba="bibi";
			return ($vanhiba);
		}
	}
}

# start of upgrade
sub upgrade {
$upgrade_butt->configure(-state=>"disable");
# upgrade window
	if ($upgpwin) {
		$upgpwin->focusForce;
		$upgpwin->raise();
		$upgpwin->deiconify;
		return;
	}
	$upgpwin=MainWindow->new();
	$upgpwin->title ("Upgrade of GPRS Easy Connect");
			$upgpwinx=$xfele-152;
			$upgpwiny=$yfele-115;
			$upgpwin->geometry("+$upgpwinx+$upgpwiny");
	$upgpwin->maxsize('305','130');
	$upgpwin->minsize('305','130');
	$upgpwin->OnDestroy(sub {stop_upgr()});

	$upgrade_sz=$upgpwin->Label(-text=>lancolas($cl[138]))->pack();
	$upgrade_message=$upgpwin->Label(-height=>"3")->pack();
	if ($brow && $br_on) {
		$upgr_brow=$brow;
	}

	$status_var = 0;

	($fromv,$tov) = (0,100);
     	$res = 1;
     	$blks = 10;
	$progress=$upgpwin->ProgressBar(
	    -borderwidth=>1,
	    -relief=>'sunken',
	    -width=>10,
	    -padx=>1,
	    -pady=>1,
	    -variable=>\$status_var,
	    -colors=>[0=>'red'],
	    -resolution=>$res,
	    -blocks=>$blks,
	    -anchor=>"w",
	    -from=>$fromv,
	    -to=>$tov
	)->pack(-padx=>100);
	$sz_status=$upgpwin->Label()->pack();
	$upgrade_butt_stop=$upgpwin->Button(-text=>lancolas($cl[140]), -activebackground=>'black', -activeforeground=>'white')->pack(-side=>'bottom'); #Lellts

	$upgrade_message->configure(-text=>lancolas($cl[141])); #Keress folyamatban!

	$upgrade_butt->configure(-state=>'disable');
	$upgrade_butt_stop->configure(-command=>\&stop_upgr);
	MainLoop();
	open (FILE, "<$gprs_shared_path/gprsec/version");
	$elsosor=<FILE>;
	$elsosor=~tr /\.\(\)pre//d; #/
	chomp $elsosor;
	$doc= get ("http://www.easyconnect.linuxuser.hu/update.php?prg=GPRSEC&ver=$elsosor");

	if ($doc eq "" || $doc=~ /error/) {
		$upgrade_message->configure(-fg=>'red', -text=>lancolas($cl[142])); #Nem tudtam kapcsoldni a szerverhez!
		$upgrade_butt_stop->configure(-text=>lancolas($cl[83]), -command=>\sub {$upgpwin->destroy, undef $upgpwin});
		$upgrade_butt->configure(-state=>'normal');
		} else {
			if ($doc eq "0") {
				$upgrade_message->configure(-fg=>'red', -text=>lancolas($cl[143])); #Nincs frissebb verzi a szerveren!
				$upgrade_butt_stop->configure(-text=>lancolas($cl[83]), -command=>\sub {$upgpwin->destroy, undef $upgpwin});
				$upgrade_butt->configure(-state=>'normal');
				return ;
			} else {
				@link_size=split /\*/, $doc;
				$link=@link_size[0];
				$size=@link_size[1];
				@temp=split /\//,$link;
				$upg_prg_name=pop (@temp);
				$home_upg=$ENV{HOME}."/.gprsec/upgrade";
				`rm  -r -f $home_upg`;
				chdir $home_upg;
				mkdir ("$home_upg", 0777);	# upgrade knyvtr ltrehozsa
				$SIG{TERM} = sub {wait};
				socketpair (PARENT, CHILD, PF_UNIX, SOCKET_STREAM, 0);
				if ($pid4=fork()) {
				$wget_pid=$pid4;
				close PARENT;
				select CHILD;
				$|=1;
				select STDOUT;
				} elsif (defined $pid4) {
					open (STDIN, ">&PARENT");
					open (STDOUT, ">&PARENT");
					close PARENT;
					select STDOUT;
					$|=1;
					exec ("wget -v -P $home_upg -O $home_upg/$upg_prg_name -o $home_upg/info $link");
					exit;
				}

				$id_upgarde = $winconn->repeat(2000,=>\&upgrade_status);
				sub upgrade_status {
				if (-e "$home_upg/info") {
					$_=`cat $home_upg/info`;
				}
				if (/Resolving/ && !$resolv) {
					$upgrade_message->configure(-fg=>'black', -text=>lancolas($cl[144])); #Nvszerver feloldsa...
					$resolv=1;
				}
				if (/failed\:/) {
					$upgrade_message->configure(-fg=>'red', -text=>lancolas($cl[145])); #Nem tallom a hostot!
					stop_upgr ();
					return;
				}
				if (/connected\./ && !$connected) {
					$upgrade_message->configure(-fg=>'black', -text=>lancolas($cl[146])); #Kapcsolds easyconnect.linuxuser.hu-hoz megtrtnt.
					$connected=1;
				}
				if (/HTTP/ && !$http_req) {
					$upgrade_message->configure(-fg=>'black', -text=>lancolas($cl[147])); #HTTP krs elkldve, vrom a vlaszt...
					$http_req=1;
				}
				($dev, $inode, $mode, $nlink, $uid, $gid, $rdev, $file_size, $atime, $mtime, $ctime, $bsize, $blocks)=stat "$home_upg/$upg_prg_name";
				$hossz=$file_size;
				$hossz=int(($hossz/$size)*100);
				if ($file_size>0) {
					$size_inkb=(int($size/1024)*10)/10;
					$upgrade_message->configure(-fg=>'black', -text=>lancolas($cl[148], $size_inkb)); #A letlts folyamatban...\nTeljes mret: $size_inkb KB
				}
				if ($lasthossz!=$hossz) {
					if ($hossz>100) {$hossz=100}
					$file_size=(int($file_size/1024)*10)/10;
					$sz_status->configure(-text=>$file_size." KB \/ ".$hossz."%");
					$status_var=$hossz;
				}
				$lasthossz=$hossz;
				if (/\[\d+\/\d+\]/) {
					$letoltve=1;
				$upgrade_message->configure(-fg=>'black', -text=>lancolas($cl[149], $upg_prg_name)); #A program letltve.\nA program neve:\n$upg_prg_name
				$b19 = $upgpwin->Balloon(-bg=>'yellow');
				$b19->attach($upgrade_message,-msg=>"$home_upg\/$upg_prg_name");
				if ($wget_pid) {
					`kill -KILL $wget_pid`;
				}
				if ($id_upgarde) {
					$id_upgarde->cancel;
					undef $id_upgarde;
				}

				$upgrade_butt_stop->configure(-text=>lancolas($cl[83]), -command=>\&stop_upgr);
				}
			}
		}

	}
}

sub stop_upgr {
		if ($wget_pid) {
			`kill -KILL $wget_pid`;
		}
		if ($id_upgarde) {
			$id_upgarde->cancel;
			undef $id_upgarde;
		}

		if ($upgpwin) {
			$upgpwin->destroy;
			undef $upgpwin;
			$upgrade_butt->configure(-state=>'normal');
		}
		#$helpwin->configure(-state=>'normal');
		undef $status_var;
		undef $box6;
}

sub  nomore_gprsec {
	# stops the start if an other GPRS EC is running
	# In some case the grep command finds itself!
	# So after the reading of the running gprsec proc.,
	# we have to select the "real" gprsec process!
	@fgh=`ps ax | grep "/usr/bin/perl" | grep "gprsec"\$`;
	if (@fgh>1) {
		$winconn1=MainWindow->new();
		$winconn1->title ("GPRS Easy Connect");
		$winconn1x=$xfele-100;
		$winconn1y=$yfele-100;
		$winconn1->geometry("+$winconn1x+$winconn1y");
		if ($no_beep !=1) {
			$winconn1->bell;
		}
		$marfut_sz=$winconn1->Label(-fg=>'red', -text=>lancolas($cl[60]))->pack(); #Egyszerre csak egy\nEasyConn program futhat!
		$marfut_b=$winconn1->Button(-text=>"Ok", -command=>\sub {exit})->pack();
		$winconn1->OnDestroy(\sub {exit});
		MainLoop ();
	}
}

sub xvid {
	# resolution
	$xvidtune=`xvidtune -show`;
	$xvidtune=~s /(\"\d+)x(\d+\")/$1.$2/e;
	$xvhor=$1;
	$xvver=$2;
	$xvhor=~ tr /\"//d;
	$xvver=~ tr /\"//d;;
	# if the X version doesn't know the xvidtune command, then the default starting points will be the center of 800*600
	if (!$xvhor) {
		$xvhor=800;
		$xvver=600;
	}
	$xfele=$xvhor/2;
	$yfele=$xvver/2;
}

sub users_home {
	# user
	$kivagy=`whoami`;
	chomp $kivagy;
	# user's home dir
	$home=$ENV{"HOME"};
	if (!-e "$home/.gprsec") {
		`mkdir $home/.gprsec`;
	}
}

sub showhelp { # started with "help" option
	print "\nFor the help see the $gprs_shared_path/gprsec/\'s files!\n\n";
	exit;
}

sub donate {
	undef $who_keys;
	undef $t_count;
	undef @cuccos;
	undef $ch_count;
	undef @donat_mess;
	undef %wqw;
	if ($sel_lang eq "magyar") {
		$d_lang="hu";
	} else {
		$d_lang="en";
	}
	$donate= $doc= get ("http://www.easyconnect.linuxuser.hu/donate.php?lang=$d_lang");

	if ($donate eq "0" && $donate ne "1") {
		mess_win (lancolas($cl[11]), lancolas($cl[142]));
		return;
	}

	# donate window
	if ($donatewin) {
		$donatewin->focusForce;
		$donatewin->raise();
		$donatewin->deiconify;
		return;
	}
	$donatewin=MainWindow->new();
	$donatewin->title (lancolas($cl[177])); #Donate the GPRS Easy Connect team!
			$donatewinx=$xfele-330;
			$donatewiny=$yfele-$yfele;
			$donatewin->geometry("+$donatewinx+$donatewiny");
			#$donatewin->maxsize('305');
			#$donatewin->minsize('305');

	if ($doc eq "" || $doc=~ /error/) {
		$donatewinx=$xfele-200;
		$donatewiny=$yfele-30;
		$donatewin->geometry("+$donatewinx+$donatewiny");

		$don_back_left=$donatewin->Canvas(-width=>360, -height=>70)->pack();
		$don_info_text=$don_back_left->Label(-fg=>'red', -text=>lancolas($cl[142]));#Nem tudtam kapcsoldni a szerverhez!
		$don_back_left->createWindow(180, 20, -window=>$don_info_text, -anchor=>"c");
		$don_cl_butt=$don_back_left->Button(-text=>lancolas ($cl[83]), -command=>sub {$donatewin->destroy, undef $donatewin})->pack(-side=>"bottom", -pady=>"5");# close this window
		$don_back_left->createWindow(180, 50, -window=>$don_cl_butt, -anchor=>"c");
	} else {
		$don_info_text=$donatewin->Label(-fg=>'red', -text=>lancolas($cl[178]))->pack(-anchor=>"c");#If you like this program and you would like to help our work, please donate to us.
		$don_back_left=$donatewin->LabFrame(-label=>lancolas($cl[179]), -labelside=>"acrosstop")->pack(-side=>'left', -anchor=>'n'); #What we would like to get
		$don_back_left_canv=$don_back_left->Canvas(-width=>330)->pack();
		$don_back_r=$donatewin->Frame()->pack(-side=>"right", -anchor=>'n');
		$don_back_right=$don_back_r->LabFrame(-label=>lancolas($cl[180]), -labelside=>"acrosstop")->pack(-side=>'top', -anchor=>'n'); #What we would like to get
		$don_back_right_r_b=$don_back_r->Frame()->pack(-side=>"bottom");

		@team_meb=split /\n\!/, $doc;
		@team_meb2=split /\n/, $team_meb[0];

		$user_ip=shift @team_meb2;
		foreach (@team_meb2) {
			@who_what=split /\/, $_;
			$who{$who_what[0]}=@who_what[1];
		}
		foreach $keys (reverse sort keys %who) {
				undef $t_count;
				@stuffs=split /\,/ ,$who{$keys};
				push (@cuccos, $keys);
				foreach (@stuffs) {
					$r_who{$keys}[$t_count]=$_;
					push (@cuccos, $r_who{$keys}[$t_count]);
					$t_count++;
				}
		}

		$off_sz=$don_back_left_canv->Label(-fg=>"red", -text=>lancolas($cl[181]));
		$don_back_left_canv->createWindow(10, 20, -window=>$off_sz, -anchor=>"w");
		$start_h=20;

		foreach (@cuccos) {
			$who_keys++;
			$don_y=$start_h+$who_keys*20;
			if (/\@/) {
				$foreg="#8e1b3b";
				$user=$_;
			} else {
				$foreg='blue';
				$t_count++;
				}
			if ($foreg eq "#8e1b3b") {
				$donat_mess[$who_keys]=$don_back_left_canv->Label(-fg=>$foreg, -text=>$_);
				$anch="w";
				$d_pos=10;
			} else {
				$stuff=$user."\:".$_;

				$donat_mess[$who_keys]=$don_back_left_canv->Checkbutton(-fg=>$foreg, -text=>$_, -variable=>\$wqw{$stuff});
				$anch="w";
				$d_pos=20;
			}
			$don_back_left_canv->createWindow($d_pos, $don_y, -window=>$donat_mess[$who_keys], -anchor=>$anch);
		}
		$mag=13*20+$t_count*20;

		$don_back_left_canv->configure(-height=>$mag);
		$who_keys+=1;

		$don_y=$start_h+$who_keys*20;

		$off_sz_name=$don_back_left_canv->Label(-text=>lancolas($cl[154]));#nv?
		$don_back_left_canv->createWindow($d_pos, $don_y, -window=>$off_sz_name, -anchor=>$anch);

		$who_keys+=1;
		$don_y=$start_h+$who_keys*20;

		$off_sz_n_entr=$don_back_left_canv->Entry(-width=>35);
		$don_back_left_canv->createWindow($d_pos, $don_y, -window=>$off_sz_n_entr, -anchor=>$anch);

		$who_keys+=2;
		$don_y=$start_h+$who_keys*20;

		$off_sz_em=$don_back_left_canv->Label(-text=>lancolas($cl[155]));#email
		$don_back_left_canv->createWindow($d_pos, $don_y, -window=>$off_sz_em, -anchor=>$anch);

		$who_keys+=1;
		$don_y=$start_h+$who_keys*20;

		$off_sz_em_entr=$don_back_left_canv->Entry(-width=>35);
		$don_back_left_canv->createWindow($d_pos, $don_y, -window=>$off_sz_em_entr, -anchor=>$anch);

		$who_keys+=2;
		$don_y=$start_h+$who_keys*20;

		$off_sz_ip=$don_back_left_canv->Label(-text=>lancolas($cl[182])." ".$user_ip);#ip
		$don_back_left_canv->createWindow($d_pos, $don_y, -window=>$off_sz_ip, -anchor=>$anch);

		$who_keys+=2;
		$don_y=$start_h+$who_keys*20;
		$don_close_b=$don_back_left_canv->Button(-text=>,lancolas($cl[183]), -command=>\sub {don_sel_s()});#Send the intention of the donate!
		$don_back_left_canv->createWindow(180, $don_y, -window=>$don_close_b, -anchor=>"c");
		$b22 = $don_back_left_canv->Balloon(-bg=>"yellow");
		$b22->attach($don_close_b,-msg=>lancolas($cl[186]));

		#right side
		$team_meb[1]=~s /\n/\n\n/g;
		$team_meb[1]=~s /\,/\t\-/g;
		$team_meb[1]=~s /\/\n\t\- /g;
		$spons_sz=$don_back_right->Text(-width=>40, -height=>20);
		$scroll_7 = $don_back_right->Scrollbar(-command=>['yview', $spons_sz]);
		$spons_sz->configure(-yscrollcommand=>['set', $scroll_7]);
		$scroll_7->pack(-side=>'right', -fill=>'y');
		$spons_sz->pack(-side=>'left', -fill=>'both', -expand=>1);
		$spons_sz->insert('end', $team_meb[1]);
		$don_kjl1=$don_back_right_r_b->Label()->pack();
		$don_ex=$don_back_right_r_b->Button(-text=>lancolas($cl[83]), -command=>\sub {$donatewin->destroy, undef $donatewin})->pack(-side=>"top");
	}

}
sub don_sel_s {
	undef @stuff_t;
	undef $zz;
	foreach $kulcsok (keys %wqw) {
		if ($wqw{$kulcsok}) {
			@sp_stuff=split /\:/, $kulcsok;
			@csak_nev=split /\</, $sp_stuff[0];
			push (@stuff_t, "$csak_nev[0],$sp_stuff[1]<br>");
		}
	$zz++;
	}
	$d_email=$off_sz_n_entr->get;
	$d_nev=$off_sz_em_entr->get;

	$db_stuff=@stuff_t;
	if (!$d_email || !$d_nev || $db_stuff=="0") {
		hiba (lancolas($cl[184]));#You didn't give us all needed data!
		return;
	}

	$donate_send= get ("http://www.easyconnect.linuxuser.hu/donate.php?sponsor=$d_nev&mail=$d_email&item=@stuff_t");

	if ($donate_send eq "0" && $donate_send ne "1" && $donate_send ne "2") {
		mess_win (lancolas($cl[11]), lancolas($cl[142]));
	} elsif ($donate_send eq "2") {
		mess_win (lancolas($cl[11]), lancolas($cl[185]));#Couldn't write into the server's database.\nPlease try it again.
	} else {
		mess_win (lancolas($cl[25]), lancolas($cl[159]));
		$donatewin->destroy;
		undef $donatewin;
	}
}

sub mess_win {
	if ($messwin) {
			if ($no_beep !=1) {
				$messwin->bell;
			}
			$messwin->focusForce;
			$messwin->raise();
			$messwin->deiconify;
			return;
	}
	$messwin=MainWindow->new();
	if ($no_beep !=1) {
		$messwin->bell;
	}

	$mess_title=$_[0];
	$mess_szoveg=$_[1];
	$messwin->title($mess_title);
			$messwinx=$xfele-100;
			$messwiny=$yfele-100;
			$messwin->geometry("+$messwinx+$messwiny");
	$mess_szoveg_sz=$messwin->Label(-fg=>'red', -text=>$mess_szoveg)->pack();
	$mess_szoveg_butt=$messwin->Button(-text=>"Ok", -command=>\&me_hshut)->pack();

	sub me_hshut {
		$messwin->destroy;
		undef $messwin;
	}
return;
}

sub read_config_file {
		# read previous (new) configs
		undef @temp;
		undef @temp_comment;
		open (FILE, "<$home/.gprsec/EasyConn.config");
		while ($sor=<FILE>) {
			@temp_temp=split /\#/, "$sor";
			push (@temp, @temp_temp[0]);
			push (@temp_comment, "\#".@temp_temp[1]);
		}
		close FILE;
}

sub write_config_file {
	$tempfilename=">$home/.gprsec/EasyConn.config";
	open (FILE, $tempfilename);
	chmod 0666, $tempfilename;
	undef $newconfig_file;
	$temp_lenght=@temp;
	for (my $x=0; $x<=$temp_lenght; $x++) {
		$newconfig_file.="$temp[$x]"."@temp_comment[$x]"
	}
	print FILE $newconfig_file;
	close FILE;	

}

sub new_config_save{
	$tempfilename=">$home/.gprsec/EasyConn.config";
	open (FILE, $tempfilename);
	chmod 0666, $tempfilename;

	my $configfile="";
	$configfile.=$phonetype."#\t\t\t"."phone type\n";
	$configfile.=$kivp."#\t\t\t"."selected port\n";
	$configfile.=$co_pan."#\t\t\t"."connect window to panel?\n";
	$configfile.=$brow."#\t\t\t"."start this browser\n";
	$configfile.=$br_on."#\t\t\t"."enable starting of a browser\n";
	$configfile.=$autocsat."#\t\t\t"."enable automatic connection\n";
	$configfile.=$sel_lang."#\t\t\t"."language\n";
	$configfile.=$cw_ic."#\t\t\t"."main window to panel?\n";
	$configfile.=$sel_szolg."#\t\t\t"."selected provider\n";
	$configfile.=$user."#\t\t\t"."username\n";
	$configfile.=$passw."#\t\t\t"."password\n";
	$configfile.=$reconn_on."#\t\t\t"."reconnect after the disconnect in xx sec.\n";
	$configfile.=$idores."#\t\t\t"."time interval. of the watching buliding connection\n";
	$configfile.=$reg_time."#\t\t\t"."date of starting of data's save\n";
	$configfile.=$din_eng."#\t\t\t"."enable dynamic DNSs\n";
	$configfile.=$cid."#\t\t\t"."own CID number\n";
	$configfile.=$dns1."#\t\t\t"."own DNS1\n";
	$configfile.=$dns2."#\t\t\t"."own DNS2\n";
	$configfile.=$no_beep."#\t\t\t"."disable warning beep\n";
	$configfile.=$bg_rec."#\t\t\t"."reconnect in the backround\n";
	$configfile.=$reconn_db."#\t\t\t"."number of enabled reconnections\n";
	$configfile.=$no_cgq."#\t\t\t"."disable CGQ commands\n";
	$configfile.=$other_numb."#\t\t\t"."own calling number\n";
	$configfile.=$havit_v."#\t\t\t"."date of erase of monthly limit's data\n";
	$configfile.=$havilimit_v."#\t\t\t"."monthly limit\n";
	$configfile.=$hetilimit_v."#\t\t\t"."weekly limit\n";
	$configfile.=$honap."#\t\t\t"."month of last erase\n";
	$configfile.=$no_auth."#\t\t\t"."Do not require the peer to authenticate itself\n";
	$configfile.=$debug."#\t\t\t"."debug mode on\n";
	$configfile.=$bsd_comp."#\t\t\t"."enable BSD compression\n";
	$configfile.=$connspeed."#\t\t\t"."connection speed\n";
	$configfile.=$no_dev."#\t\t\t"."disable read/write data during connection\n";
	$configfile.=$no_find."#\t\t\t"."disabe the sending of info of new tested phone\n";
	$configfile.=$def_apn."#\t\t\t"."own APN\n";
	$configfile.=$compact."#\t\t\t"."compact mode\n";
	$configfile.=$newly."#\t\t\t"."newly set data\n";
	$configfile.=$szolg_apn{$sel_szolg}[0]."#\t\t\t"."APN ID\n";
	
	print FILE $configfile;
	close FILE;
}