Changeset 262

Show
Ignore:
Timestamp:
11/16/06 21:01:07 (7 years ago)
Author:
lincoln
Message:

Tor support for engine/dog

Files:
2 modified

Legend:

Unmodified
Added
Removed
  • engines/dog

    r254 r262  
    33my $myprogname = 'dog'; 
    44my $progname = 'shepherd'; 
    5 my $version = '0.3.9'; 
     5my $version = '0.3.10'; 
    66 
    77# 'dog' 
     
    148148 
    149149&calc_date_range; 
     150&start_tor; 
    150151&grab_data; 
    151152&reconcile_data; 
     
    153154&output_data; 
    154155&write_config_file; 
     156&stop_tor; 
    155157 
    156158# --------------------------------------------------------------------------- 
     
    232234            $comm .= " --channels_file $channels_file"; 
    233235        } 
     236 
     237        if ((defined $plugin_data->{tor_pid}) && 
     238            (query_config($grabber, 'option_anon_socks'))) { 
     239            $comm .= " ".query_config($grabber, 'option_anon_socks')." ".$plugin_data->{tor_address}; 
     240        } 
     241 
    234242        $comm .= " --debug" if ($debug); 
    235243        $comm .= " @ARGV" if (@ARGV); 
     
    14451453 
    14461454# ----------------------------------------- 
     1455# Subs: Tor support 
     1456# ----------------------------------------- 
     1457 
     1458sub start_tor 
     1459{ 
     1460    # do we have any components requesting the use of tor? 
     1461    my $want_tor = 0; 
     1462    foreach (query_grabbers()) { 
     1463        unless ($components->{$_}->{disabled}) { 
     1464            $want_tor++ if (query_config($_, 'option_anon_socks')); 
     1465        } 
     1466    } 
     1467 
     1468    return if ($want_tor == 0); 
     1469 
     1470    # try to find tor 
     1471    my $searchpath = ".:".$ENV{PATH}; 
     1472    my $found_tor; 
     1473    foreach my $dir (split(/:/,$searchpath)) { 
     1474        if (-x "$dir/tor") { 
     1475            $found_tor = "$dir/tor"; 
     1476            last; 
     1477        } 
     1478    } 
     1479 
     1480    if (!defined $found_tor) { 
     1481        printf "WARNING: $want_tor components wanted to use Tor but could not find it.\n"; 
     1482        printf "This may cause data collection to run slower than it otherwise would.\n\n"; 
     1483        return; 
     1484    } 
     1485 
     1486    printf "Starting Tor ($found_tor) in the background (wanted by $want_tor components).\n"; 
     1487    my $pid = fork; 
     1488    if (!defined $pid) { 
     1489        # failed 
     1490        printf "Failed to start $found_tor: $!\n"; 
     1491        return; 
     1492    } elsif ($pid > 0) { 
     1493        # parent 
     1494        sleep 2; # wait a few seconds for Tor to start 
     1495 
     1496        # test that it is running 
     1497        if (!kill 0, $pid) { 
     1498            printf "Tor doesn't seem to be running on pid $pid anymore, ignoring Tor option.\n"; 
     1499        } else { 
     1500            printf "Tor appears to have successfully started (pid $pid).\n"; 
     1501            $plugin_data->{tor_address} = "127.0.0.1:9050"; 
     1502            $plugin_data->{tor_pid} = $pid; 
     1503        } 
     1504    } else { 
     1505        # child 
     1506        exec $found_tor "MaxCircuitDirtiness 30 SocksListenAddress 127.0.0.1:9050"; 
     1507        exit(1); # we won't reach this 
     1508    } 
     1509} 
     1510 
     1511 
     1512sub stop_tor 
     1513{ 
     1514    if (defined $plugin_data->{tor_pid}) { 
     1515        # INTR sig stops tor 
     1516        kill 2,$plugin_data->{tor_pid}; 
     1517    } 
     1518} 
     1519 
     1520# ----------------------------------------- 
    14471521# Subs: Utilities 
    14481522# ----------------------------------------- 
  • status

    r255 r262  
    11application     shepherd            0.3.21 
    2 engine          dog                 0.3.9 
     2engine          dog                 0.3.10 
    33grabber         yahoo7widget        1.58 
    44grabber         rex                 3.3.6