annotate docs/parse-netrc.pl @ 864:c71bc7d32ce5

2006-11-30 Brian Masney <masneyb@gftp.org> * docs/sample.gftp/Makefile.am docs/sample.gftp/gftp-16x16.png docs/sample.gftp/gftp-22x22.png docs/sample.gftp/gftp-24x24.png docs/sample.gftp/gftp-32x32.png docs/sample.gftp/gftp-48x48.png docs/sample.gftp/gftp-scalable.svg docs/gftp.desktop docs/sample.gftp/gftp-mini-logo.png docs/sample.gftp/gftp-mini-logo.xpm - added new icons for gftp from Tango Friday theme. (closes #370627)
author masneyb
date Sat, 23 Dec 2006 19:29:16 +0000
parents 8b1883341c6f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1 #!/usr/bin/perl -w
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
3 # Brian Masney <masneyb@gftp.org>
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
4
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
5 my ($host, $user, $pass, $account, $descr, %bmhash);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
6 use strict;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
7
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
8 open NRC, "<.netrc" or die "Can't open .netrc: $!\n";
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
9 open BM, "+>>.gftp/bookmarks" or die "Can't open .gftp/bookmarks: $!\nTry running gFTP once to create a default bookmarks file\n";
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
10 seek (BM, 0, 0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
11 while (<BM>)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
12 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
13 ($descr) = /\[(.*?)\]/;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
14 next if !defined ($descr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
15 $bmhash{$descr} = 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
16 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
17
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
18 seek (BM, 0, 2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
19
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
20 while (<NRC>)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
21 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
22 if (/machine /)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
23 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
24 print_bookmark ();
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
25 ($host) = /machine (.*?)\s+/;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
26 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
27
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
28 if (/login /)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
29 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
30 ($user) = /login (.*?)\s+/;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
31 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
32
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
33 if (/password /)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
34 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
35 ($pass) = /password (.*?)\s+/;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
36 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
37
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
38 if (/account /)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
39 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
40 ($account) = /account (.*?)\s+/;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
41 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
42 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
43
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
44 print_bookmark ();
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
45
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
46 close NRC;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
47 close BM;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
48
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
49 print "The contents of your .netrc file should now be stored in .gftp/bookmarks\n";
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
50
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
51
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
52 sub print_bookmark
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
53 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
54 my $i;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
55
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
56 return if !defined ($host);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
57
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
58 if (!defined ($bmhash{$host}))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
59 { $descr = $host; }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
60 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
61 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
62 for ($i=0; ; $i++)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
63 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
64 $descr = "$host ($i)";
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
65 last if !defined ($bmhash{$descr});
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
66 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
67 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
68
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
69
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
70 print BM "[$descr]\n";
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
71 print BM "hostname=$host\n";
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
72 print BM "port=21\n";
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
73 print BM "protocol=FTP\n";
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
74 print BM "remote directory=\n";
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
75 print BM "local directory=\n";
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
76 if (!defined ($user))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
77 { $user = "anonymous"; }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
78 print BM "username=$user\n";
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
79 if ($user eq "anonymous" || !defined ($pass))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
80 { $pass = "\@EMAIL\@"; }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
81 print BM "password=$pass\n";
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
82 if (!defined ($account))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
83 { $account = ""; }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
84 print BM "account=$account\n\n";
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
85
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
86 print "Added $descr = $user\@$host\n";
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
87
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
88 undef ($host);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
89 undef ($user);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
90 undef ($pass);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
91 undef ($account);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
92 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
93