📄 provactions.pm
字号:
#!/usr/bin/perl# ====================================================================# The Vovida Software License, Version 1.0 # # Copyright (c) 2002-2003 Vovida Networks, Inc. All rights reserved.# # Redistribution and use in source and binary forms, with or without# modification, are permitted provided that the following conditions# are met:# # 1. Redistributions of source code must retain the above copyright# notice, this list of conditions and the following disclaimer.# # 2. Redistributions in binary form must reproduce the above copyright# notice, this list of conditions and the following disclaimer in# the documentation and/or other materials provided with the# distribution.# # 3. The names "VOCAL", "Vovida Open Communication Application Library",# and "Vovida Open Communication Application Library (VOCAL)" must# not be used to endorse or promote products derived from this# software without prior written permission. For written# permission, please contact vocal@vovida.org.# # 4. Products derived from this software may not be called "VOCAL", nor# may "VOCAL" appear in their name, without prior written# permission of Vovida Networks, Inc.# # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND# NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA# NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES# IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH# DAMAGE.# # ====================================================================# # This software consists of voluntary contributions made by Vovida# Networks, Inc. and many individuals on behalf of Vovida Networks,# Inc. For more information on Vovida Networks, Inc., please see# <http://www.vovida.org/>.# $Id: provactions.pm,v 1.21.2.5 2003/02/28 20:27:38 bko Exp $package provactions;use Exporter;use vprov::vpp;use vprov::cplxml;use vprov::serverxml;use vprov::userxml;BEGIN {# our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); # if using RCS/CVS, this may be preferred $VERSION = do { my @r = (q$Revision: 1.21.2.5 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; # must be all one line, for MakeMaker @ISA = qw(Exporter); @EXPORT = qw( &set_user_pass &get_account_list &get_vm_box &get_data_one_user &create_new_user &validate_input &print_input &update_one_user &get_gw_data &update_gw &delete_one_user &set_vm_dialplan &verify_active &u_create_user &u_delete_user &u_login &u_print_user @user_parameter_list ); %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ], # your exported package globals go here, # as well as any optionally exported functions @EXPORT_OK = qw();}#our @EXPORT_OK;@user_parameter_list = ( { name => "user", type => "label", desc => "User ID" }, { name => "use_passwd", type => "checkbox", desc => "Use Password" }, { name => "passwd", type => "password", desc => "Password" },# { name => "allow_local", type => "checkbox", desc => "Allow local calls" },# { name => "allow_gw", type => "checkbox", desc => "Allow gateway calls" }, { name => "enable_vm", type => "checkbox", desc => "Enable Voicemail" }, { name => "voicemail_addr", type => "text", desc => "Voicemail Email Address (voicemail sent to this address)" }, { name => "use_custom", type => "checkbox", desc => "Use custom greeting" }, { name => "uploaded_greeting", type => "filefield", desc => "Upload custom greeting" });my $errmsg;&psdebug("started loading provactions.pm: ".time() . "\n");$VOCAL_BASE = "/usr/local/vocal"; # VOCAL_BASE$VOCAL_BASE_CONFIGURED = '@prefix@';if($VOCAL_BASE_CONFIGURED ne '@'.'prefix@') { $VOCAL_BASE = $VOCAL_BASE_CONFIGURED;}$vmhome_dir = "$VOCAL_BASE/var/vmhome";chomp($hostname = `hostname`);($junk1,$junk2,$junk3,$junk4,@addr) = gethostbyname($hostname);($a,$b,$c,$d) = unpack('C4', $addr[0]);$local_ip = "$a.$b.$c.$d";$pserver_hostname;sub set_user_pass { my ($username, $password) = @_; my ($data); if(defined(&u_login($username, $password, "localhost", 6005))) { return 1; } else { return 0; }}sub verify_active { # verify that provisioning system is active my $data = &get_data($pserver_hostname, "SystemConfiguration", "GlobalConfigData"); if(defined($data)) { return 1; } else { return 0; }}sub get_account_list { my($users) = []; @$users = split(/,/, &list_data($pserver_hostname, "Accounts")); pop(@$users); return $users;}sub get_vm_box { my($params) = @_; open(CONFIG, "$vmhome_dir/$$params{user}/config") || return -1; while(<CONFIG>) { chomp; if(s/^SendTo\s+string\s+//) { $$params{voicemail_addr} = $_; } if(s/^Greeting\s+string\s+//) { if(/custom\.wav/ && -f "$vmhome_dir/$$params{user}/custom.wav") { $$params{use_custom} = 1; } } } close(CONFIG) || return -1; return;}sub get_data_one_user { my($userid) = @_; my($data) = &get_data($pserver_hostname, "Accounts", $userid); my($parameters); if($data) { $parameters = &parse_parameters_user($data); $$parameters{user} = $userid; # get vm data &get_vm_box($parameters); return $parameters; } else { return undef; }}sub put_data_one_user { my($userid, $account, $called, $calling, $fna) = @_; my $ret; my $totalret = 1; my $errmsg; $ret = &put_data($pserver_hostname, "Accounts", $userid, $account); if($ret) { $errmsg .= "\ncould not write Account data\n"; $totalret = undef; } $ret = &put_data($pserver_hostname, "Contact_Lists_Called", $userid, $called); if($ret) { $errmsg .= "\ncould not write Contact_Lists_Called data\n"; $totalret = undef; } $ret = &put_data($pserver_hostname, "Contact_Lists_Calling", $userid, $calling); if($ret) { $errmsg .= "\ncould not write Contact_Lists_Calling data\n"; $totalret = undef; } $ret = &put_data($pserver_hostname, "Features_${local_ip}_5105_Called", "$userid.cpl", $fna); if($ret) { $errmsg .= "\ncould not write Features 5105 data\n"; $totalret = undef; } return ($totalret, $errmsg);}sub validate_user { my($user) = @_; if(($user =~ /^[0-9]{4,16}$/ || $user =~ /^test[0-9]{4,16}/) && $user ne "7000" && $user ne "8000" ) { return 1; } else { return 0; }}sub u_create_user { my($userid, $novm) = @_; my($params) = {}; $params->{user} = $userid; return &i_create_user($params, $novm);}sub u_delete_user { my($userid) = @_; my($params) = {}; $params->{user} = $userid; return &i_delete_user($params);}sub u_login { my($username, $password, $host, $port) = @_; my($retval, $output); $retval = undef; if ($#_ != 3) { $output = "wrong number of arguments"; $retval = undef; } else { $pserver_hostname = "$username:$password\@$host:$port"; my ($data); $data = &login($pserver_hostname); &psdebug("Username: $username\nPassword: $password\nHost: $host\nPort: $port\n"); if(defined($data)) { &psdebug("Username: $username\nPassword: $password login succeeded\n"); $retval = 1; $output = "login succeeded"; } else { &psdebug("Username: $username\nPassword: $password\n login FAILED\n"); $retval = undef; $output = "login failed"; } } return wantarray ? ($retval, $output) : $retval;}sub u_print_user { my($userid) = @_; my($params) = &get_data_one_user($userid); return &i_print_user($params);}sub i_print_user { my($params) = @_; my($retval); my($output); my($single); if($params) { # now, print based on this foreach $single (sort keys %$params) { $output .= "$single: $$params{$single}\n"; } $retval = 1; } else { $retval = undef; $output = "could not get data for user"; } return wantarray ? ($retval, $output) : $retval;}sub i_create_user { my($params, $novm) = @_; my($output); my($params_clean) = {}; my($retval); # print "xxx: $$params{user} xxx\n\n"; # need to verify that user does not already exist # need to verify that user has "safe" userid if(&validate_user($$params{user})) { $$params_clean{user} = $$params{user}; $$params_clean{passwd} = "password"; my($user, $user_errmsg) = &update_one_user_entry($params_clean); my($vm, $vm_errmsg); if($user) { ($vm, $vm_errmsg) = &create_vm_box($params_clean); if($vm || $novm) { $output .= "Created user \"$$params{user}\" successfully";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -