[Spce-user] ngcp-create_subscriber?

Daniel Tiefnig dtiefnig at sipwise.com
Wed Nov 21 09:43:44 EST 2012


On 11/21/2012 08:25 AM, Jirka Jirout wrote:
> I do not use a client app at the moment, I am typing the command
> from console:
> 
> /usr/bin/ngcp-create_subscriber -v 5 -u 123456 -p OMYXM9R7 -d 
> my.domain.cz

Oh, that's something completely different then of course. :)
The problem here is, that the parameters for cc, ac and sn are mandatory
for the script. So the error actually is a usage information for the
script. You may change the behaviour if you know some Perl, or just use
the modified version attached to this mail. (Will also be included in
upcoming versions of the platform.)

Please note that the command line scripts are just provided as sample
implementations and can not be used (yet) as a full replacement for the
web and SOAP/XML-RPC interfaces.

>> even though IIRC it is required for some parts of the system, like 
>> the voicebox.
> Should I perhaps explicitly disable the voicebox somehow then?

No, it shouldn't cause any problems initially, it just will not be
possible to forward calls to the voicebox in this case.

br,
daniel
-------------- next part --------------
#!/usr/bin/perl
use strict;

use Getopt::Std;
use Sipwise::Provisioning::Billing;
use Sipwise::Provisioning::Config;

my %CONFIG = (admin => 'cmd');

my $config = Sipwise::Provisioning::Config->new()->get_config();

unless ($CONFIG{password} = $config->{acl}->{$CONFIG{admin}}->{password}) {
  die "Error: No provisioning password found for user $CONFIG{admin}\n";
}

my %BILLING = (
                billing_profile => 'default',
# not needed, but may be set if desired
#                product         => 'handle',
              );

sub main;
sub usage;
sub call_prov;

my %opts;
getopts('v:u:d:p:c:a:n:s:', \%opts);

die usage() unless defined $opts{u} and defined $opts{d} and defined $opts{p};
die usage() unless (defined $opts{c} and defined $opts{a} and defined $opts{n})
                or (!defined $opts{c} and !defined $opts{a} and !defined $opts{n});

my $bprov = Sipwise::Provisioning::Billing->new();

main;

sub main {
    my $subscriber = { username => $opts{u},
                       domain   => $opts{d},
                       password => $opts{p},
                       admin    => $opts{s} ? 1 : 0,
                     };
    $$subscriber{cc} = $opts{c} if defined $opts{c};
    $$subscriber{ac} = $opts{a} if defined $opts{a};
    $$subscriber{sn} = $opts{n} if defined $opts{n};

    if(defined $opts{v}) {
        my $account = call_prov( 'get_voip_account_by_id', { id => $opts{v} });
        call_prov( 'add_voip_account_subscriber',
                   {
                     id         => $$account{id},
                     subscriber => $subscriber,
                   }
                 );
        print "Added subscriber to VoIP account $$account{id}.\n";
    } else {
        my $id = call_prov( 'create_voip_account',
                            {
                              data => {
                                        %BILLING,
                                        subscribers => [ $subscriber ],
                                      },
                            }
                          );
        print "Created VoIP account $id with one subscriber.\n";
    }

    exit;
}


sub call_prov {
    #   scalar,    hash-ref
    my ($function, $parameter) = @_;
    my $result;

    eval {
        $result = $bprov->handle_request( $function,
                                          {
                                            authentication => {
                                                                type     => 'system',
                                                                username => $CONFIG{admin},
                                                                password => $CONFIG{password},
                                                              },
                                            parameters => $parameter,
                                        });
    };

    if($@) {
        if(ref $@ eq 'SOAP::Fault') {
            die "Billing\::$function failed: ". $@->faultstring ."\n";
        } else {
            die "Billing\::$function failed: $@\n";
        }
    }

    return $result;
}

sub usage {
    die "Usage:\n$0 [-v account_id] -u <username> -d <domain> -p <password> [-c <cc> -a <ac> -n <number>] [-s {1|0}]\n\n".
        "e.g.: $0 -u test -d sip.sipwise.com -p secret -c 43 -a 720 -n 555000\n\n".
        "Options:\n".
        "  -v <account_id>  the unique ID of an existing account, the\n".
        "                   script will create a new one if unspecified\n".
        "  -u <username>    new SIP username\n".
        "  -d <domain>      existing domain for subscriber\n".
        "  -p <password>    unencrypted password for subscriber\n".
        "  -c <cc>          country code of subscriber number\n".
        "  -a <ac>          area code of subscriber number\n".
        "  -n <number>      local part of subscriber number\n".
        "  -s {1|0}         whether or not to set the administrative flag\n".
        "                   for the subscriber; defaults to 0 (no)\n".
        "";
}


More information about the Spce-user mailing list