File: g2netfind.gd

package info (click to toggle)
gopher 2.3-2
  • links: PTS
  • area: non-free
  • in suites: hamm
  • size: 2,364 kB
  • ctags: 2,030
  • sloc: ansic: 22,451; perl: 1,950; sh: 1,510; makefile: 397; asm: 1
file content (119 lines) | stat: -rwxr-xr-x 2,647 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/local/bin/perl
#
# This script allows you to add 'netfind' as a gopher menu item. To use
# this, make a link like this in your gopher tree:
#
#  Type=1?
#  Name=Netfind Search
#  Host=+
#  Port=+
#  Path=0/bin/gateways/g2netfind
#
# If you need to support old-stype clients you can do this instead
#
#  Type=7
#  Name=Netfind (non-gopher+)
#  Host=+
#  Port=+
#  Path=7/bin/gatewasy/g2netfind.gd
#
# You will need the netfind software, which you can get by ftp'ing to
# ftp.cs.colorado.edu
#
#----------------------------------------------------------------------
# variables you should change:

$dblookupcmd   = "/home/mudhoney/netfind/nf/dblookup";
$netfindcmd    = "/home/mudhoney/netfind/nf/netfind";

#----------------------------------------------------------------------
# gateway from gopher to netfind, requires netfind 3.46 or above

$SIG{'INT'}  = 'Ourabort';
$SIG{'TERM'} = 'Ourabort';
$SIG{'HUP'}  = 'Ourabort';
$SIG{'QUIT'} = 'Ourabort';
$SIG{'PIPE'} = 'Ourabort';
$SIG{'ALRM'} = 'Ourabort';

$| = 1;

if ($0 =~ /.gpd/) {
    # We have gopher+ directory...
    $gplus = 1;
}

if ($#ARGV > 0) {
    $name = shift;
    $domain = join(" ",  @ARGV);
} else {
    $name = <>; chop($query);
    $domain = <>; chop($domains);
}

if ((length($name) < 1) || (length($domain) < 1) ) {
    print "+INFO: " if ($gplus);
    print "0Please fill in both fields...\tmoo\tmoo\t70\n";
}

if ($name =~ /^\@\@/) {
    $cmd = "netfind";
    $name = substr($name, 2);;
} else {
    $cmd = "dblookup";
}

if ($cmd =~ /^dblookup/) {
    $name  =~ s/([^A-Za-z0-9])//g;
    $domain =~ s/([^A-Za-z0-9 ])//g;

    $script = $ENV{'SCRIPT_NAME'};
    $script = "$script.gd" if (!($script =~ /.gd$/));
    
    $dbcmd = "$dblookupcmd \"$domain\"";
    $pid = open(Dbfd, "$dbcmd |") || die "Cannot execute $dbcmd command...\n";

    select (DBfd);
    $| = 1;
    select(STDOUT);

    while (<Dbfd>) {
	chop;
	$title = $_;
	/^([^ ]+) .*/;
	$domain = $1;
	print "+INFO: " if ($gplus);
	print "0$title\texec:@@$name $domain:$script\t$ENV{'SERVER_NAME'}\t$ENV{'SERVER_PORT'}\n";
    }
    close(Dbfd);
} 

if ($cmd =~ /^netfind/) {
    
    $brokendomain = $domain;
    $brokendomain =~ s/\./ /g;
    
    print "Domain is $domain.., user is $name\n";
    $nfcmd = "$netfindcmd -L $domain $name $brokendomain </dev/null 2>&1";
    $pid = open(nffd, "$nfcmd|") || die "Unable to execute $nfcmd...\n";

    ### Make the output line-buffered
    select (nffd);
    $|=1;
    select (STDOUT);

    while (<nffd>) {
	chop;
	print "$_\r\n";
    }
    print "\r\n";
    close(nffd);
}



sub Ourabort {
    kill(SIGINT, $pid);
    kill(SIGKILL, $pid);
    exit(0);
}