#!/usr/bin/perl -w use strict; use warnings; use Curses::Application; my $guestaccount = "gość"; my $smbget = "/usr/local/bin/smbget"; my $nmblookup = "/usr/local/bin/nmblookup"; my $smbclient = "/usr/local/bin/smbclient"; my $awk = "/bin/awk"; my $grep = "/bin/grep"; my $remotePos = "groups"; my $remotePathR = ""; my $Rworkgroup = ""; my $Rhost = ""; my $Rshare = ""; my $Rpath = ""; my $LocalDir = ""; my @copylist; my $olditem = ""; my $fsize1 = ""; my $helptxt = "TAB - focus to next window\nr - refresh window\nEnter - download a file / execute a directory\nd - download file or directory\ns - show downloading status\nk - stop downloading\nc - continue downloading\nq - quit\n\nauthor: Rafal Michniewicz \nhome page: http://www.rafim.prv.pl"; my $str = ""; my $form = ""; my $error = ""; my @rv = ""; sub upperPath($;) { my $string = shift; my $x = length($string); while (substr($string,$x,1) ne "/" and $x ne "0") { $x = $x-1; } return substr($string, 0, $x); } sub get_masters_ip() { my @list = `$nmblookup -M -- - 2>&1 | $grep -v "que" | $awk '{ print \$1 }'`; chomp(@list); foreach my $tmp (@list) { if (index($tmp, "Usage:") >= 0) { return ""; } } return @list; } sub get_group_name($;) { my $master_ip = shift; my $result = `$nmblookup -T -A $master_ip 2>&1 | $grep "<00>" | $grep "" | $awk 'BEGIN { FS="<" }{ print \$1 }'`; return $result; } sub get_host_name($;) { my $ip = shift; my $result = `$nmblookup -T -A $ip 2>&1 | $grep "<00>" | $grep -v "" | $awk 'BEGIN { FS="<" }{ print \$1 }'`; return $result; } sub get_mastername_from_groupname($;) { my $groupname = shift; my $result = `$nmblookup -S -M $groupname 2>&1 | $grep "<00>" | $grep -v "" | $awk 'BEGIN { FS="<" }{ print \$1 }'`; return $result; } sub get_host_from_group($;) { my $mastername = shift; my @result = `$smbclient -N -L $mastername 2>&1 | $grep -A 1000 "Server Comment" | $grep -B 1000 "Workgroup Master" | $awk 'BEGIN{ yes=0 }{ str=substr(\$0,1,20) }{ if (str=="") yes=1 }{ if (FNR>2 && yes==0) print str }'`; return @result; } sub get_share_from_host($;) { my $hostname = shift; my @result; my @tl = ""; $SIG{ALRM} = sub { dialog('Error',BTN_OK, "I can't enter to $hostname.\nMaybe it has firewall or it is shutdown.", qw(white blue red)); $error = "SIGALRM"; die ".." }; eval { alarm 10; @result = `$smbclient -N -L $hostname 2>&1 | $grep -A 1000 "Sharename Type Comment" | $grep -B 1000 "Server Comment" | $awk 'BEGIN{ yes=0 }{ FS=" " }{ if (\$0=="") yes=1 }{ if (FNR>2 && yes==0) print \$0 }' | grep -v "\\\\\$" | grep -v "Anonymous login successful"`; alarm 0; if (defined($result[0])) { if (index($result[0],"NT_STATUS_ACCESS_DENIED") >= 0) { dialog('Error',BTN_OK, "I can't enter to $hostname.\nAccess denied.", qw(white blue red)); $error = "SIGALRM"; } } }; my $nr = 0; @tl = ""; foreach my $tmp (@result) { if (index($tmp, "Error r") >= 0) { return ".."; } my $tmp2 = ciach($tmp); $tmp2 = substr($tmp2, 0, length($tmp2)-4); $tl[$nr] = $tmp2; $nr += 1; } return @tl; } sub get_dir_from_host($;$;$;) { my $hostname = shift; my $share = shift; my $dir = shift; my @result; $SIG{ALRM} = sub { dialog('Error',BTN_OK, "I can't enter to //$hostname/$share.\nMaybe it has firewall.", qw(white blue red)); $error = "SIGALRM"; die ".." }; eval { alarm 10; @result = `$smbclient "//$hostname/$share" -o guest -D "$dir" -c "dir" 2>&1 | $awk 'BEGIN{ yes=0 }{FS=" "}{ if (\$0=="") yes=1 }{ if (FNR>2 && yes==0) print \$0 }'`; alarm 0; return @result; }; } sub ciach { my $s = shift; $s =~ s/^\s+//; $s =~ s/\s+$//; $s =~ s/\s+/ /g; return $s; } sub statusbarmessage($;$;$;) { my $app = shift; my $msgno = shift; my $msg = shift; if ($msgno == 0) { $app->statusbar("running..."); } if ($msgno == 1) { $app->statusbar("TAB-focus | r-refresh | Enter-download/execute | d-download file/dir | 1-help"); } if ($msgno == 2) { $app->statusbar("downloading $msg"); } } #------------------------------------------------------------------- my $HOME = ciach(`set | grep "HOME=" | awk 'BEGIN{ FS="=" }{ print \$2 }'`); my $homeg = "$HOME/gecik"; my $homegtmp = "$HOME/geciktmp"; my $homegtmp1 = "$HOME/geciktmp1"; my $homes = "$HOME/smbcr"; if (not -X $homes) { ` echo "#!/bin/bash while [ -f ~/gecik ]; do ~/gecik rm -f ~/gecikb cat ~/gecik | awk '{ if (NR>1) print \\\$0}' >> ~/gecikb rm -f ~/gecik mv ~/gecikb ~/gecik chmod a+x ~/gecik rm -f ~/gecikb size=\\\`ls -la ~/gecik | awk '{print \\\$5}'\\\` if [ \\\"\\\$size\\\" = \\\"0\\\" ]; then rm -f ~/gecik fi done; " > ~/smbcr && chmod a+x ~/smbcr`; } my $app = Curses::Application->new({ FOREGROUND => 'white', BACKGROUND => 'black', CAPTIONCOL => 'yellow', TITLEBAR => 1, STATUSBAR => 1, CAPTION => "Samba Commander 0.1.3 for Samba 3.0.0", MAINFORM => { Main => 'MainFrm' }, INPUTFUNC => \&myscankey, }); my ($f, $w, $rv); my ($cw, $l, @tmp, $d, @tmp2); # Get the current working directory chomp($d = `pwd`); $cw = int(($app->maxyx)[1] / 2) - 2; $l = ($app->maxyx)[0] - 5; $app->createForm(qw(Main MainFrm)); statusbarmessage($app, 0, ""); $w = $app->getForm('Main')->getWidget('lstLocal'); @tmp = @{$w->getField('COLWIDTHS')}; $tmp[0] = $cw - 16; @tmp2 = loaddir($d); $LocalDir = "$d"; $w->setField( CAPTION => "Local: $d", LINES => $l - 1, COLUMNS => $cw, LISTITEMS => [@tmp2], COLWIDTHS => [@tmp], CWD => $d, ); $w = $app->getForm('Main')->getWidget('lstRemote'); @tmp2 = loadsambadir("groups", ""); @tmp = @{$w->getField('COLWIDTHS')}; $tmp[0] = $cw-7; $w->setField( CAPTION => "Remote: /", X => $cw + 2, LINES => $l - 1, COLUMNS => $cw, LISTITEMS => [@tmp2], COLWIDTHS => [@tmp], CWD => $d, ); statusbarmessage($app, 1, ""); $app->execute; exit 0; sub myscankey { # Usage: $key = myscankey($mwh); my $mwh = shift; my $key = -1; while ($key eq -1) { clock(); $key = $mwh->getch }; return $key; } sub clock { # Usage: clock(); my $time = scalar localtime; my $x = ($app->maxyx)[1] - length($time); my $caption = substr($app->getField('CAPTION'), 0, $x); $caption .= ' ' x ($x - length($caption)) . $time; $app->titlebar($caption); if (-X $homeg) { open FILEI, "<$homeg"; open FILEO, ">$homegtmp1"; while () { my $str = $_; print FILEO $str } close FILEI; close FILEO; open FILEI, "<$homegtmp1" or die ".."; my $st = ; close FILEI; `rm -f $homegtmp1`; if (defined($st)) { my $stt0 = getnextandcut($st,1); my $stt1 = getnextandcut($st,3); my $stt2 = getnextandcut($st,4); my $stt3 = getnextandcut($st,5); my $stt4 = getnextandcut($st,6); my $stt5 = getnextandcut($st,8); if ($stt5 ne "0") { my $ff = "$stt0/$stt4"; my $fsize = 0; if (-e $ff) { $fsize = (stat($ff))[7]; } my $count = sizer2($stt5-$fsize); my $procent = int(($fsize/$stt5)*100); if (not defined($fsize)) { $fsize = "*"; }; statusbarmessage($app,2,"$count $procent% //$stt1/$stt2/$stt3/$stt4"); } else { statusbarmessage($app,2,"//$stt1/$stt2/$stt3/$stt4"); } } } else { statusbarmessage($app,1,""); } } sub quit { my $rez = dialog('Quit',BTN_OK | BTN_CANCEL, " \n Are you sure?\n ", qw(white red yellow)); if ($rez == 0) { exit 0 unless ($rv); } } sub loaddir { # Returns a sort list of list, with each sublist being a file # and its attributes. # # Usage: @entries = loaddir($dir); my $dir = shift; my ($e, @rv); if (opendir(DIR, $dir)) { while (defined($e = readdir(DIR))) { push(@rv, $e); } closedir(DIR); @rv = map { [$_, sizer(-s "$dir/$_"), transmode("$dir/$_")] } sort @rv; } return @rv; } sub sizer { my $size = shift || 0; my @suffixes = qw(B K M G); my $l = length($size); my $indx = 0; my $p; if ($size eq "..") { return ".."; } # Find the byte prefix while ($l > 3) { ++$indx; $l -= 3; } $size /= 1024 ** $indx if $indx > 0; # Find the sprintf argument if ($l >= 2) { $p = "\% 3d$suffixes[$indx]"; } else { $p = "\%1.1f$suffixes[$indx]"; } return sprintf($p, $size); } sub sizer2 { my $size = shift || 0; if ($size eq "..") { return 0; } my $fix = "B"; my $t = int($size/1024); if ($t > 0) { $size = $t; $fix = "K"; } $t = int($size/1024); if ($t > 0) { $size = $t; $fix = "M"; } $t = int($size/1024); if ($t > 0) { $size = $t; $fix = "G"; } my $rt = ciach($size); $rt = "$rt$fix"; while (length($rt) < 4) { $rt = " $rt"; } return $rt; } sub transmode { # Returns a string showing the entry permissions (a la ls -l) # # Usage: $mode = transmode($file); my $file = shift; my $stat = (stat($file))[2]; my $mode = defined $stat ? sprintf('%04o', $stat & 07777) : '0000'; my @ebits = qw(r w x); my @bits = (4, 2, 1); my ($digit, $i, $rv); # Translate last three octets foreach $digit (split(//, substr($mode, 1))) { for ($i = 0; $i < @bits; $i++) { $rv .= $digit & $bits[$i] ? $ebits[$i] : '-'; } } # Check if it's a link if (-l $file) { $rv = "l$rv"; # Or a directory } elsif (-d _) { $rv = "d$rv"; # Or a block device } elsif (-b _) { $rv = "b$rv"; # Or a character device } elsif (-c _) { $rv = "c$rv"; # Or a socket } elsif (-S _) { $rv = "s$rv"; # Or a pipe } elsif (-p _) { $rv = "p$rv"; } else { $rv = "-$rv"; } # Check for sticky bits substr($rv, 3, 1) = 's' if -u _; substr($rv, 6, 1) = 's' if -g _; substr($rv, 9, 1) = 't' if -k _; return $rv; } sub chgdir { # Changes the current directory as per the selected entry in # the list box. # # Usage: chgdir(); my $w = shift; my ($pos, $items, $cwd, $caption) = $w->getField(qw(CURSORPOS LISTITEMS CWD CAPTION)); return if $$items[$pos][0] eq '.'; if (-d $$items[$pos][0] || -d "$cwd/$$items[$pos][0]") { if ($$items[$pos][0] eq '..') { $cwd =~ s#/[^/]+/?$##; $cwd = '/' if $cwd eq ''; } else { $cwd .= "/$$items[$pos][0]"; } $caption =~ s/^(\w+: ).+$/$1$cwd/; $LocalDir = "$cwd"; $w->setField( LISTITEMS => [loaddir($cwd)], CWD => $cwd, CAPTION => $caption, CURSORPOS => '0', ); } else { return 0; } } sub addtocopyfile($;$;$;) { my $source = shift; my $type = shift; my $size = shift; my $comment = " \n$source\nFrom://$Rworkgroup/$Rhost/$Rshare/$Rpath\nTo:$LocalDir\n "; my $rez = dialog('Copy',BTN_OK | BTN_CANCEL, $comment, qw(white red yellow)); if ($rez == 0) { open FILE, ">>$homeg"; #if ($type eq "file") { print FILE "cd $LocalDir && $smbclient \"//$Rhost/$Rshare\" --directory=\"$Rpath\" --command=\"get \\\"$source\\\"\" -o guest && exit # ??? $LocalDir ??? $Rworkgroup ??? $Rhost ??? $Rshare ??? $Rpath ??? $source ??? F ??? $size ??? \n"; } if ($type eq "file") { print FILE "cd $LocalDir && $smbget \"smb://$Rhost/$Rshare/$Rpath/$source\" -u $guestaccount -n -r ; exit # ??? $LocalDir ??? $Rworkgroup ??? $Rhost ??? $Rshare ??? $Rpath ??? $source ??? F ??? $size ??? \n"; } if ($type eq "dir") { print FILE "cd $LocalDir && $smbclient \"//$Rhost/$Rshare\" --command=\"cd \\\"$Rpath\\\"; prompt; recurse; mget \\\"$source\\\"\" -o guest ; exit # ??? $LocalDir ??? $Rworkgroup ??? $Rhost ??? $Rshare ??? $Rpath ??? $source ??? D ??? 0 ??? \n"; } close FILE; if (not -X $homeg) { `chmod a+x $homeg && screen -dmS smbcr ~/smbcr`; } } } sub remotename($;$;) # $what = 1 return file name # $what = 2 return file type # $what = 3 return file size { my $file = shift; my $what = shift; my $f = length($file); my $posday = 0; my $possize = 0; my $postype = 0; my $filetype = ""; my $day; if ($file eq "..") { return $file; }; if ($f > 3) { $f = $f - 3; }; while ($f != 0 and $posday == 0) { $day = substr($file, $f, 3); foreach my $t ("Mon","Tue","Wed","Thu","Fri","Sat","Sun") { if ($day eq $t) { $posday = $f; }; } $f = $f - 1; } if ($f > 0) { $f = $f - 1 } while ($f != 0 and $possize == 0) { if (substr($file, $f, 1) eq " ") { $possize = $f+1; } $f = $f - 1; } $possize = $f+1; if ($what == 3) { # return file size my $rt = substr($file, $possize, $posday-$possize); return ($rt); } while ($f != 0 and $postype == 0) { if (substr($file, $f, 3) eq " D ") { $postype = $f+1; $possize = $f+1; } if (substr($file, $f, 3) eq " A ") { $postype = $f+1; $possize = $f+1; } if (substr($file, $f, 3) eq "AR " or substr($file, $f, 3) eq "DR ") { $postype = $f; $possize = $f; $f = $f - 1; } $f = $f -1; } if ($postype > 0 and substr($file, $postype,1) eq "D") { $filetype = "D"; } else { $filetype = "F" } if ($what == 2) { return ($filetype); } return ciach(substr($file, 0, $possize)); } sub loadsambadir { my $status = shift; my $dir = shift; my $pos; my $tmp1; my ($e, @rv); my $nr = 0; if ($status eq "groups") { foreach $pos (get_masters_ip()) { $tmp1 = ciach(get_group_name($pos)); if (length($tmp1) > 0) { push(@rv, "$tmp1"); } } } if ($status eq "hosts") { push(@rv, ".."); my $mastername = ciach(get_mastername_from_groupname($dir)); foreach my $pos (get_host_from_group($mastername)) { $tmp1 = ciach($pos); if (length($tmp1) > 0) { push(@rv, "$tmp1"); } } } if ($status eq "share") { my @ss = get_share_from_host($dir); if ($error eq "SIGALRM") { return; }; if ($ss[0] eq "") { $error = "SIGALRM"; dialog('Error',BTN_OK, "Host $dir doesn't share anyting.", qw(white blue red)); return; } else { push(@rv, ".."); $remotePathR = ""; foreach $pos (@ss) { $tmp1 = ciach($pos); if (length($tmp1) > 0) { push(@rv, "$tmp1"); } } } } if ($status eq "mntshare") { push(@rv, ".."); foreach $pos (get_dir_from_host($Rhost, $Rshare, $dir)) { $tmp1 = ciach($pos); if (remotename($tmp1,1) ne ".." and length($tmp1) > 0) { push(@rv, "$tmp1"); } } } if ($status eq "mntshare") { @rv = map { [remotename($_,1),sizer2(remotename($_,3)),remotename($_,2),remotename($_,3)] } sort @rv; } else { @rv = map { [$_] } sort @rv; } return @rv; } sub remotechgdir { my $w = shift; my @tmp; my $oldRemotePos = $remotePos; my $oldRworkgroup = $Rworkgroup; my $oldRhost = $Rhost; my $oldRshare = $Rshare; my $oldRpath = $Rpath; my ($pos, $items) = $w->getField(qw(CURSORPOS LISTITEMS)); my $item = ciach($$items[$pos][0]); my $itemtype = $$items[$pos][2]; my $itemsize = $$items[$pos][3]; if (not defined($itemtype)) { $itemtype = ""; } if ($itemtype eq "F") { addtocopyfile($item,"file",$itemsize); } else { if ($remotePos eq "groups") { $remotePos = "hosts"; $Rworkgroup = $item; } elsif ($remotePos eq "hosts") { if ($item eq "..") { $remotePos = "groups"; $Rworkgroup = ""; $item = ""; } else { $remotePos = "share"; $Rhost = $item; } } elsif ($remotePos eq "share") { if ($item eq "..") { $remotePos = "hosts"; $item = $Rworkgroup; $Rhost = ""; } else { $remotePos = "mntshare"; $Rshare = $item; } } elsif ($remotePos eq "mntshare") { if ($item eq "..") { if ($Rpath eq "") { $remotePos = "share"; $item = $Rhost; $Rshare =""; } else { $Rpath = upperPath($Rpath); $item = $Rpath; } } else { if ($Rpath ne "") { $Rpath = "$Rpath/$item"; } else { $Rpath = "$item"; } $item = $Rpath; } } $w->setField( CURSORPOS => '0',); @tmp = loadsambadir($remotePos, $item); if ($error eq "SIGALRM") { $error = ""; $remotePos = $oldRemotePos; $Rworkgroup = $oldRworkgroup; $Rhost = $oldRhost; $Rshare = $oldRshare; $Rpath = $oldRpath; } else { $olditem = $item; my $ty = "/"; if ($Rworkgroup ne "") { $ty = "$ty$Rworkgroup" }; if ($Rhost ne "") { $ty = "$ty/$Rhost" }; if ($Rshare ne "") { $ty = "$ty/$Rshare" }; if ($Rpath ne "") { $ty = "$Rshare/$Rpath" }; $w->setField( LISTITEMS => [@tmp], CAPTION => "Remote: $ty", ); } } } sub showhelp { my $rez = dialog('Help',BTN_OK, $helptxt, qw(white blue red)); } sub reloadlocaldisk { my $f = shift; my @tmp2 = loaddir($LocalDir); my $w = $app->getForm('Main')->getWidget('lstLocal'); $w->setField( LISTITEMS => [@tmp2], ); $f->setField(DONTSWITCH => 1); } sub remotedownloaddir { my $w = shift; my ($pos, $items) = $w->getField(qw(CURSORPOS LISTITEMS)); my $item = ciach($$items[$pos][0]); my $itemtype = $$items[$pos][2]; my $itemsize = $$items[$pos][3]; if ($Rhost ne "") { if (not defined($itemtype)) { $itemtype = ""; } if ($itemtype eq "D") { addtocopyfile($item,"dir",$itemsize); } if ($itemtype eq "F") { addtocopyfile($item,"file",$itemsize); } } } sub stopdownloading { my $stt=`ps x | grep smbcr | grep -v grep | awk '{print \$1}'`; my $rez = ""; if (length($stt) > 0) { $stt = ciach($stt); } else { $stt = "" }; if ($stt ne "") { $rez = dialog('Stop downloading',BTN_OK | BTN_CANCEL, " \nAre you sure stop downloading?\n ", qw(white red yellow)); if ($rez == 0) { `kill $stt > /dev/null 2>&1 &`; } } else { dialog('Stop downloading',BTN_OK, " \n Downloading are already stoped.\n ", qw(white red yellow)); } } sub continuedownloading { my $stt=`ps x | grep smbcr | grep -v grep | awk '{print \$1}'`; my $rez = ""; if (length($stt) > 0) { $stt = ciach($stt); } else { $stt = "" }; if ($stt eq "") { $rez = dialog('Continue downloading',BTN_OK | BTN_CANCEL, " \nAre you sure continue downloading?\n ", qw(white red yellow)); if ($rez == 0) { if (-X $homeg) { `screen -dmS smbcr ~/smbcr`; } } } else { dialog('Continue downloading',BTN_OK, " \n Downoloading are already running.\n ", qw(white red yellow)); } } sub myscankey2 { my $mwh = shift; my $key = -1; while ($key eq -1) { if (-X $homeg) { my $fsize11 = (stat($homeg))[7]; if ($fsize1 ne $fsize11) { $fsize1 = $fsize11; loadhomeg(); } } $key = $mwh->getch; }; if ($key eq "r") { loadhomeg(); } if ($key eq "d") { my ($pos) = $form->getField(qw(CURSORPOS)); my $nr = 0; open FILEI, "<$homeg"; while () { $nr += 1; }; close FILEI; open FILEI, "<$homeg"; open FILEO, ">$homegtmp"; while () { my $str = $_; $nr -= 1; if ($nr ne $pos) { print FILEO $str } } close FILEI; close FILEO; `cat $homegtmp > $homeg && rm -f $homegtmp > /dev/null 2>&1`; if ((stat($homeg))[7] == 0) { `rm -f $homeg > /dev/null 2>&1`; }; loadhomeg(); } return $key; } sub getdest { my $str = shift; my $s1 = getnextandcut($str,3); my $s2 = getnextandcut($str,4); my $s3 = getnextandcut($str,5); return "//$s1/$s2/$s3"; } sub getnextandcut { my $str = shift; my $nr = shift; my $pos = 0; my $ix = 0; my $ixold = 0; while ($ix >= 0 and $nr >= 0) { $ixold = $pos; $ix = index($str, " ??? ",$ixold); $nr -= 1; $pos = $ix+5; } if ($ix < 0) { return $str } else { my $tmp = substr($str, $ixold, $ix-$ixold); return $tmp; } } sub loadhomeg { open FILE, "<$homeg"; my @rv; while () { $str = $_; if (length($str) > 0) { push(@rv, "$str"); } } close FILE; @rv = map { [getnextandcut($_,7), getnextandcut($_,6), getdest($_)] } @rv; $form->setField( LISTITEMS => [@rv], CURSORPOS => '0', ); } sub statusdownloading { my $tDestination = ""; my $tWorkgroup = ""; my $tHost = ""; my $tShare = ""; my $tDirectory = ""; my $tFile= ""; my $tFileType= ""; if (-X $homeg) { my $mwh = new Curses; $mwh->keypad(1); $mwh->syncok(1); $form = Curses::Widgets::ListBox::MultiColumn->new({ TYPE => 'ListBox::MultiColumn', COLUMNS => ($app->maxyx)[1]-2, LINES => ($app->maxyx)[0]-4, Y => 0, X => 0, CAPTION => 'Downloading status d - delete from list q - quit ', MULTISEL => 0, SELECTEDCOL => 'red', HEADERS => [qw(type file/directory source)], COLWIDTHS => [1,30,($app->maxyx)[1]], HEADERFGCOL => 'white', HEADERBGCOL => 'cyan', BIGHEADER => 1, FOCUSSWITCH => "qw", CWD => '', LISTITEMS => [@rv], INPUTFUNC => \&myscankey2, }); loadhomeg(); $form->draw($mwh); $form->execute($mwh); } else { dialog('Status download',BTN_OK, " \n No files or directiories are downloaded.\n ", qw(white red yellow)); } } sub localexit { # Keeps the focus on the listbox. # # Usage: srcexit($form, $key); my $f = shift; my $key = shift; my $w = $f->getWidget('lstLocal'); if ($key eq "s") { statusdownloading(); $f->setField(DONTSWITCH => 1); } if ($key eq "c") { continuedownloading(); $f->setField(DONTSWITCH => 1); } if ($key eq "k") { stopdownloading(); $f->setField(DONTSWITCH => 1); } if ($key eq "1") { showhelp(); $f->setField(DONTSWITCH => 1); } if ($key eq "q") { quit(); $f->setField(DONTSWITCH => 1); } if ($key eq "\n") { chgdir($w); $f->setField(DONTSWITCH => 1); } if ($key eq "r") { reloadlocaldisk($f); } } sub remoteexit { my $f = shift; my $key = shift; my $w = $f->getWidget('lstRemote'); if ($key eq "s") { statusdownloading(); $f->setField(DONTSWITCH => 1); } if ($key eq "c") { continuedownloading(); $f->setField(DONTSWITCH => 1); } if ($key eq "k") { stopdownloading(); $f->setField(DONTSWITCH => 1); } if ($key eq "1") { showhelp(); $f->setField(DONTSWITCH => 1); } if ($key eq "q") { quit(); $f->setField(DONTSWITCH => 1); } if ($key eq "\n") { remotechgdir($w); $f->setField(DONTSWITCH => 1); } if ($key eq "d") { remotedownloaddir($w); $f->setField(DONTSWITCH => 1); } if ($key eq "r") { my @tmp = loadsambadir($remotePos, $olditem); $f->setField(DONTSWITCH => 1); $w->setField( LISTITEMS => [@tmp]); } } __DATA__ %forms = ( MainFrm => { TABORDER => [qw(lstLocal lstRemote)], FOCUSED => 'lstRemote', WIDGETS => { lstLocal => { TYPE => 'ListBox::MultiColumn', COLUMNS => 20, LINES => 10, Y => 0, X => 0, CAPTION => 'Local', MULTISEL => 0, SELECTEDCOL => 'red', HEADERS => [qw(filename size perm)], COLWIDTHS => [20, 4, 10], HEADERFGCOL => 'white', HEADERBGCOL => 'cyan', BIGHEADER => 1, FOCUSSWITCH => "\n\tr1qsck", CWD => '', OnExit => \&main::localexit, }, lstRemote => { TYPE => 'ListBox::MultiColumn', COLUMNS => 20, LINES => 10, Y => 0, X => 20, CAPTION => 'Remote', MULTISEL => 0, SELECTEDCOL => 'red', HEADERS => [qw(group/host/directory/filename size perm)], COLWIDTHS => [20,4,1], HEADERFGCOL => 'white', HEADERBGCOL => 'cyan', BIGHEADER => 1, FOCUSSWITCH => "\n\tr1qdsck", CWD => '', OnExit => \&main::remoteexit, }, }, }, );