diff --git a/bin/check.sh b/bin/check.sh index cf516e8d..487e906d 100755 --- a/bin/check.sh +++ b/bin/check.sh @@ -253,7 +253,15 @@ function run_sipp error_helper "Restart error" 16 fi capture - + + if [ -e ${SCEN_CHECK_DIR}/presence.sh ]; then + echo "$(date) - Presence xcap" + ${SCEN_CHECK_DIR}/presence.sh + if [ $? -ne 0 ]; then + error_helper "error in presence.sh" 17 + fi + fi + for res in $(find ${SCEN_CHECK_DIR} -type f -name 'sipp_scenario_responder[0-9][0-9].xml'| sort); do base=$(basename $res .xml) is_enabled $(basename $res) diff --git a/bin/presence.sh b/bin/presence.sh new file mode 100755 index 00000000..e54c9d23 --- /dev/null +++ b/bin/presence.sh @@ -0,0 +1,72 @@ +#!/bin/bash +# +# Copyright: 2013 Sipwise Development Team +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This package is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# On Debian systems, the complete text of the GNU General +# Public License version 3 can be found in "/usr/share/common-licenses/GPL-3". +# +BASE_DIR="${BASE_DIR:-/usr/share/kamailio-config-tests}" +BIN_DIR="${BASE_DIR}/bin" +LOG_DIR="${BASE_DIR}/log" +RESULT_DIR="${BASE_DIR}/result" +DOMAIN="spce.test" +DIR="${BASE_DIR}/scenarios" +error_flag=0 + +function clean +{ + find ${DIR} -type f -name 'presence_*.xml' -exec rm {} \; +} + +function usage +{ + echo "Usage: generate_tests.sh [-h] [-c] [-d directory] digest presence_file.xml" + echo "Options:" + echo -e "\tc: clean. Removes all generated presence files" + echo -e "\td: directory" + echo -e "\th: this help" + echo "Args:" + echo -e "\tdigest: testuserX@domain:password" +} + +while getopts 'hcd:' opt; do + case $opt in + h) usage; exit 0;; + c) clean; exit 0;; + d) DIR=$OPTARG;; + esac +done +shift $(($OPTIND - 1)) + +if [[ $# -ne 2 ]]; then + echo "Wrong number or arguments" + usage + exit 1 +fi + +if [ ! -e "${2}" ]; then + echo "No ${2} file found" + exit 1 +fi +# subscriber part +subs=$(echo ${1}|cut -f1 -d:) +curl -T ${2} -X PUT --digest -k -u ${1} \ + https://127.0.0.1:1080/xcap/pres-rules/users/sip:${subs}/presrules +if [ $? -ne 0 ]; then + echo "error sending xcap info" + exit 1 +fi +#EOF diff --git a/bin/scenario.pl b/bin/scenario.pl index ebc68999..97e6601a 100755 --- a/bin/scenario.pl +++ b/bin/scenario.pl @@ -29,6 +29,7 @@ use IO::File; use YAML; use Text::CSV; use Template; +use Data::Dumper; sub usage { @@ -58,6 +59,7 @@ if (exists $ENV{'BASE_DIR'}) $template_dir = File::Spec->catfile(abs_path($ENV{'BASE_DIR'}), 'scenarios', 'templates'); } our $template_reg = 'sipp_scenario_responder_reg.xml.tt2'; +our $template_presence = 'pres-rules.xml.tt2'; our $tt = Template->new({ INCLUDE_PATH => $template_dir, @@ -72,7 +74,7 @@ sub new_csv sub get_subs_info { - my ($data_sub, $data) = @_; + my ($data_sub, $data, $presence) = @_; if (defined($data_sub->{$data->{domain}})) { my $domain = $data->{domain}; @@ -81,7 +83,7 @@ sub get_subs_info my $username = $data->{username}; my $subs = $data_sub->{$domain}->{$username}; $data->{password} = $subs->{password}; - eval { $data->{number} = $subs->{cc}.$subs->{ac}.$subs->{sn}; }; + eval { $data->{number} = $subs->{cc}.$subs->{ac}.$subs->{sn}; } unless defined($presence); } else { @@ -155,4 +157,34 @@ sub generate_reg $tt->process($template_reg, $vars, $fn) or die($tt->error(), "\n"); } +sub generate_presence +{ + my @rules; + my ($data) = @_; + foreach (@{$data->{presence}}) + { + eval { get_subs_info($data->{subscribers}, $_); }; + $_->{password} = "" unless defined($_->{password}); + my $vars = { users => @{$_->{allow}} }; + my $fn = File::Spec->catfile($base_check_dir, "presence_".$_->{username}."_".$_->{domain}.".xml"); + $tt->process($template_presence, $vars, $fn) or die($tt->error(), "\n"); + undef $fn; + my $digest = $_->{username}."@".$_->{domain}.":".$_->{password}; + push @rules, "$bin_dir/presence.sh $digest $template_dir/$template_presence" + } + if(scalar(@rules)>0) + { + my $file = "$base_check_dir/presence.sh"; + my $fn = IO::File->new($file, "w") or die("can't create $file"); + print {$fn} "#!/bin/bash\n"; + foreach(@rules) + { + print {$fn} "$_\n"; + } + chmod(0755, $fn); + undef $fn; + } +} + generate($cf); +generate_presence($cf); diff --git a/debian/control b/debian/control index 8578c7dd..bb4d99c4 100644 --- a/debian/control +++ b/debian/control @@ -8,7 +8,8 @@ Homepage: http://www.sipwise.com/ Package: kamailio-config-tests Architecture: all -Depends: libgraphviz-perl, +Depends: curl, + libgraphviz-perl, libtemplate-perl, libtext-csv-perl, ngcp-ossbss-clients-perl, diff --git a/scenarios/templates/pres-rules.xml.tt2 b/scenarios/templates/pres-rules.xml.tt2 new file mode 100644 index 00000000..87c6792c --- /dev/null +++ b/scenarios/templates/pres-rules.xml.tt2 @@ -0,0 +1,22 @@ + + + + + [% FOREACH user IN users -%][% END -%] + + + allow + + + + + + + + + + + + + +