Browse Source

Start adding hust contacts and list-specific config files, since that seems forward-thinking TM

master
Jonathan "Duke" Leto 7 years ago
parent
commit
e2cac3e27b
  1. 27
      bin/hushlist
  2. 31
      lib/Hush/List.pm

27
bin/hushlist

@ -6,26 +6,37 @@ use lib 'lib';
use Hush::List;
use Data::Dumper;
my $command = shift || help();
# we only need one
my $list = Hush::List->new;
my $list = Hush::List->new;
my $command = shift || help();
my $COMMANDS = {
"add" => \&add,
"new" => \&new,
"remove" => \&remove,
"send" => \&send,
"add" => \&add,
"contact" => \&contact,
"new" => \&new,
"remove" => \&remove,
"send" => \&send,
};
run();
sub help {
print "It would be nice to give some help\n";
}
sub contact {
my $cmd = shift || '';
if ($cmd eq 'new') {
# add a hust contact, yay
my ($name,$zaddr) = @ARGV;
die Dumper [ $name, $zaddr ];
}
}
sub new {
my $name = shift || '';
die "Invalid hushlist name '$name' !" unless $name;
#TODO: better validation and allow safe unicode stuff
die "Invalid hushlist name '$name' !" unless $name && ($name =~ m/^[A-z0-9_-]{0,64}/);
$list->new_list($name);
print "hushlist '$name' created, enjoy your private comms :)\n";
}

31
lib/Hush/List.pm

@ -4,6 +4,9 @@ use warnings;
use Hush::RPC;
use Try::Tiny;
use File::Spec::Functions;
use Carp qw/longmess/;
sub barf { die longmess(@_) }
our $VERSION = 20171031;
@ -68,13 +71,37 @@ sub new {
}
sub new_list {
my ($self,$name) = @_;
my $lists = $self->{lists};
my ($self,$name) = @_;
my $lists = $self->{lists};
# a list is simply a list of addresses, which can be looked up by name, and maybe some other metadata
$lists->{$name} = { recipients => {} };
my $list_dir = catdir($HUSHLIST_CONFIG_DIR,$name);
if (!-e $list_dir) {
# create the config dir for the list for the first time
mkdir $list_dir;
if ($!) {
barf "Could not create directory $list_dir !";
}
}
my $list_specific_conf = catfile($HUSHLIST_CONFIG_DIR,$name,'list.conf');
my $time = time;
open my $fh, '>', $list_specific_conf or barf "Could not open $list_specific_conf for writing";
print $fh "# hushlist $name config\n";
print $fh "generated=$time\n";
print $fh "generated_by=Hush::List $Hush::List::VERSION\n";
close $fh;
# We consider members.txt the oracle, so users can simply maintain a list
# of zaddrs into a file, if they want. We sync/serialize to list.json
# each time we run
# hust list contacts?
# TODO: still in flux
# ~/.hush/list/LIST_NAME/
# ~/.hush/list/LIST_NAME/list.conf - list-specific config items
# ~/.hush/list/LIST_NAME/members.txt - list member zaddrs, one per line
# ~/.hush/list/LIST_NAME/list.json - list data, in JSON
# ~/.hush/list/LIST_NAME/list.png - user-specified image for list
return $self;

Loading…
Cancel
Save