Browse Source

Auto-detect username+pass for RPC server on Unixy systems

master
Duke Leto 6 years ago
parent
commit
1b1ef7eda3
  1. 1
      Build.PL
  2. 4
      lib/Hush/List.pm
  3. 32
      lib/Hush/RPC.pm

1
Build.PL

@ -16,6 +16,7 @@ my $builder = Module::Build->new(
configure_requires => { 'Module::Build' => 0.38 },
requires => {
'perl' => '5.008',
'URL::Encode' => '0.03',
'Bitcoin::RPC::Client' => '0.07',
},
add_to_cleanup => [ 'Hush-*' ],

4
lib/Hush/List.pm

@ -12,8 +12,6 @@ use Hush::Contact;
use Data::Dumper;
use JSON;
my $VERSION = '0.02';
=head1 NAME
Hush::List - HushList Protocol Reference Implementation
@ -62,7 +60,7 @@ modify it under the GNU Public License Version 3.
my $MAX_RECIPIENTS = 54;
my $HUSH_CONFIG_DIR = $ENV{HUSH_CONFIG_DIR} || catdir($ENV{HOME},'.hush');
my $HUSHLIST_CONFIG_DIR = $ENV{HUSH_CONFIG_DIR} || catdir($HUSH_CONFIG_DIR, 'list');
our $VERSION = 20171031;
our $VERSION = 20180215;
my $rpc = Hush::RPC->new;
sub _sanity_checks {

32
lib/Hush/RPC.pm

@ -3,17 +3,36 @@ use strict;
use warnings;
use Bitcoin::RPC::Client;
use Hush::Util qw/barf/;
use File::Spec::Functions;
#use Carp::Always;
use URL::Encode qw/url_encode/;
sub new {
my $port = $ENV{HUSH_RPC_PORT} || 8822;
my $host = "127.0.0.1";
my $port = $ENV{HUSH_RPC_PORT} || 8822;
my $host = "127.0.0.1";
my $HOME = $ENV{HOME};
my $config = catfile($HOME, qw/.hush hush.conf/);
my ($user,$password) = ('','');
if (-e $config) {
open(my $fh, '<', $config) or die $!;
while(<$fh>) {
if (m!^rpcuser=(.*)$!) {
$user = $1;
}elsif (m!^rpcpassword=(.*)$!) {
# default Hush instructions use base62
$password = url_encode($1);
}
last if ($user && $password);
}
}
my $rpc = Bitcoin::RPC::Client->new(
port => $port, # set this to 18822 to use testnet
host => $host,
user => $ENV{HUSH_RPC_USERNAME} || "hush",
password => $ENV{HUSH_RPC_PASSWORD} || "hushmegently",
user => $ENV{HUSH_RPC_USERNAME} || $user,
password => $ENV{HUSH_RPC_PASSWORD} || $password,
# rpc calls, how do they work?
debug => 1,
debug => $ENV{HUSH_DEBUG} || 0,
);
my $info = $rpc->getinfo;
@ -23,12 +42,17 @@ sub new {
my $coins = {
8822 => 'HUSH',
18822 => 'TUSH',
7770 => 'KMD',
17770 => 'KMD-test',
8232 => 'ZEC',
18232 => 'TAZ',
1989 => 'BTCZ',
11989 => 'BTCZ-test',
};
my $sites = {
"HUSH" => 'https://myhush.org',
"TUSH" => 'https://myhush.org',
"KMD" => 'https://komodoplatform.com',
"ZEC" => 'https://z.cash',
"TAZ" => 'https://z.cash',
};

Loading…
Cancel
Save