From c7e5ed12bccc90e1b59d8db981f7e5f7d2e4d64b Mon Sep 17 00:00:00 2001 From: Christian Veigl Date: Fri, 15 Jun 2012 07:18:52 +0000 Subject: [PATCH] support for sound sets --- debian/control | 2 +- lib/admin/Controller/domain.pm | 12 ++ lib/admin/Controller/peering.pm | 12 ++ lib/admin/Controller/sound.pm | 227 +++++++++++++++++++++++++++++ lib/admin/Controller/subscriber.pm | 11 ++ root/layout/menu | 3 + root/tt/domain_preferences.tt | 18 +++ root/tt/peering_preferences.tt | 18 +++ root/tt/sound.tt | 109 ++++++++++++++ root/tt/subscriber_preferences.tt | 18 +++ 10 files changed, 429 insertions(+), 1 deletion(-) create mode 100644 lib/admin/Controller/sound.pm create mode 100644 root/tt/sound.tt diff --git a/debian/control b/debian/control index 2baa1ec..0d6f1ef 100644 --- a/debian/control +++ b/debian/control @@ -26,7 +26,7 @@ Description: Configuration templates for the web-based admin interface Package: ngcp-www-admin Architecture: all -Depends: ${shlibs:Depends}, ${misc:Depends}, ngcp-ossbss-billing (>= 2.1.1), ngcp-ossbss-voip (>= 3.1.0), libcatalyst-perl, libcatalyst-modules-perl, libcatalyst-engine-apache-perl, ngcp-templates-www-admin, libgd-gd2-perl +Depends: ${shlibs:Depends}, ${misc:Depends}, ngcp-ossbss-billing (>= 2.1.1), ngcp-ossbss-voip (>= 3.1.0), libcatalyst-perl, libcatalyst-modules-perl, libcatalyst-engine-apache-perl, ngcp-templates-www-admin, libgd-gd2-perl, libfile-type-perl Description: administration framework to configure the Sipwise NGCP This package provides an administration framework which is used to configure the Sipwise NGCP. diff --git a/lib/admin/Controller/domain.pm b/lib/admin/Controller/domain.pm index d8eb31f..bd74cdb 100644 --- a/lib/admin/Controller/domain.pm +++ b/lib/admin/Controller/domain.pm @@ -154,6 +154,18 @@ sub preferences : Local { options => $enum_options, } if eval { @$enum_options }; } + elsif ($$pref{preference} eq 'sound_set') { + my $sound_sets; + return unless $c->model('Provisioning')->call_prov( $c, 'voip', 'get_sound_sets_flat', + {}, + \$sound_sets ); + + $$preferences{$$pref{preference}} = { + selected => $$preferences{$$pref{preference}}, + options => $sound_sets, + } if eval { @$sound_sets }; + } + } diff --git a/lib/admin/Controller/peering.pm b/lib/admin/Controller/peering.pm index ef95834..a7ec83b 100644 --- a/lib/admin/Controller/peering.pm +++ b/lib/admin/Controller/peering.pm @@ -573,6 +573,18 @@ sub preferences : Local { options => $enum_options, } if eval { @$enum_options }; } + elsif ($$pref{preference} eq 'sound_set') { + my $sound_sets; + return unless $c->model('Provisioning')->call_prov( $c, 'voip', 'get_sound_sets_flat', + {}, + \$sound_sets ); + + $$preferences{$$pref{preference}} = { + selected => $$preferences{$$pref{preference}}, + options => $sound_sets, + } if eval { @$sound_sets }; + } + } if(eval { @$db_prefs }) { diff --git a/lib/admin/Controller/sound.pm b/lib/admin/Controller/sound.pm new file mode 100644 index 0000000..1a9bbe2 --- /dev/null +++ b/lib/admin/Controller/sound.pm @@ -0,0 +1,227 @@ +package admin::Controller::sound; + +use strict; +use warnings; +use base 'Catalyst::Controller'; + +=head1 NAME + +admin::Controller::sound - Catalyst Controller + +=head1 DESCRIPTION + +Catalyst Controller. + +=head1 METHODS + +=head2 index + +Edit sound sets. + +=cut + +sub base : Chained('/') PathPrefix CaptureArgs(0) { + my ($self, $c) = @_; + return unless ( $c->stash->{sets} = $c->forward ('load_sets')); + + if (defined $c->session->{refill}) { + foreach my $s (@{$c->stash->{sets}}) { + next if ($s->{id} ne $c->session->{refill}->{set_id}); + foreach my $h (@{$s->{handles}}) { + next if ($h->{id} ne $c->session->{refill}->{handle_id}); + $h->{filename} = $c->session->{refill}->{filename}; + $h->{err} = 1; + } + } + $c->session->{refill} = undef; + } + + $c->stash->{template} = 'tt/sound.tt'; +} + +sub list : Chained('base') PathPart('') Args(0) { + my ($self, $c) = @_; + $c->stash->{template} = 'tt/sound.tt'; +} + +sub set_get : Chained('base') PathPart('set') CaptureArgs(1) { + my ($self, $c, $set_id) = @_; + $c->stash->{set_id} = $set_id if ($set_id != 0); +} + +sub set_add : Chained('base') PathPart('set') CaptureArgs(0) { + my ($self, $c, $set_id) = @_; +} + +sub handle_get : Chained('set_get') PathPart('handle') CaptureArgs(1) { + my ($self, $c, $handle_id) = @_; + $c->stash->{handle_id} = $handle_id; +} + +sub upload_soundfile : Chained('handle_get') PathPart('soundfile/upload') Args(0) { + my ($self, $c) = @_; + my %messages; + + my $upload = $c->req->upload('soundfile'); + my ($file, $filename); + if (defined $upload) { + $file = eval { $upload->slurp }; + $filename = eval { $upload->filename }; + } + +# ne radi :( +# my $checkresult; +# return unless $c->model('Provisioning')->call_prov( $c, 'voip', +# 'check_filetype', +# { filetype => 'audio/x-wav', +# file => $file, +# }, +# \$checkresult +# ); + + # if ($checkresult) { + use File::Type; + my $ft = File::Type->new(); + if ($ft->checktype_contents($file) eq 'audio/x-wav') { + + if ($c->model('Provisioning')->call_prov($c, 'voip', + 'add_sound_file', + { set_id => $c->stash->{set_id}, + handle_id => $c->stash->{handle_id}, + soundfile => $file, + filename => $filename, + }, + undef)) + { + $messages{topmsg} = 'Server.Voip.SavedSettings'; + } else { + $messages{toperr} = 'Client.Voip.InputErrorFound'; + } + } + else { + $messages{file_err} = 'Client.Syntax.InvalidFileType'; + $c->session->{refill} = { set_id => $c->stash->{set_id}, handle_id => $c->stash->{handle_id}, filename => $filename }; + } + + $c->session->{messages} = \%messages; + $c->response->redirect('/sound/set/' . $c->stash->{set_id} . '/edit#set_' . $c->stash->{set_id}); +} + +sub get_soundfile : Chained('handle_get') PathPart('soundfile/get') Args(0) { + my ($self, $c) = @_; + + my $soundfile; + if ($c->model('Provisioning')->call_prov($c, 'voip', + 'get_sound_file', + { set_id => $c->stash->{set_id}, + handle_id => $c->stash->{handle_id}, + }, + \$soundfile)) + {} + + $c->response->header ('Content-Disposition' => 'attachment; filename="' . $soundfile->{filename} . '"'); + $c->response->body($soundfile->{data}); +} + +sub edit_set : Chained('set_get') PathPart('edit') Args(0) { + my ($self, $c) = @_; + $c->stash->{edit_set_id} = $c->stash->{set_id}; # meh + $c->stash->{template} = 'tt/sound.tt'; +} + +sub delete_set : Chained('set_get') PathPart('delete') Args(0) { + my ($self, $c) = @_; + $c->stash->{template} = 'tt/sound.tt'; + my %messages; + + if ($c->model('Provisioning')->call_prov($c, 'voip', + 'delete_sound_set', + { id => $c->stash->{set_id} }, + undef)) + { + $messages{topmsg} = 'Server.Voip.SoundsetDeleted'; + } + else { + $messages{toperr} = 'Client.Voip.InputErrorFound'; + } + + $c->response->redirect("/sound"); +} + +# deletes an sound file, not the handle +# usage of 'handle' here is from users perspective +sub delete_handle : Chained('handle_get') PathPart('delete') Args(0) { + my ($self, $c) = @_; + $c->stash->{template} = 'tt/sound.tt'; + my %messages; + + if ($c->model('Provisioning')->call_prov($c, 'voip', + 'delete_sound_file', + { set_id => $c->stash->{set_id}, + handle_id => $c->stash->{handle_id} + }, + undef)) + { + $messages{topmsg} = 'Server.Voip.SoundHandleDeleted'; + } + else { + $messages{toperr} = 'Client.Voip.InputErrorFound'; + } + + $c->response->redirect('/sound/set/' . $c->stash->{set_id} . '/edit#set_' . $c->stash->{set_id}); +} + +sub save_set : Chained('set_get') PathPart('save') Args(0) { + my ($self, $c) = @_; + $c->stash->{template} = 'tt/sound.tt'; + + my %messages; + $c->stash->{set_name} = $c->request->params->{set_name}; + + if ($c->stash->{set_id}) { + if ($c->model('Provisioning')->call_prov($c, 'voip', + 'update_sound_set', + { id => $c->stash->{set_id}, + set_name => $c->stash->{set_name}, + }, + undef)) + { + $messages{topmsg} = 'Server.Voip.SavedSettings'; + } + } + else { + if ($c->model('Provisioning')->call_prov($c, 'voip', + 'create_sound_set', + { set_name => $c->request->params->{set_name} }, + undef )) + + { + $messages{topmsg} = 'Server.Voip.SavedSettings'; + } + } + + $messages{toperr} = 'Client.Voip.InputErrorFound'; + $c->response->redirect("/sound"); +} + +sub load_sets :Private { + my ( $self, $c, $params) = @_; + + my $sets; + return unless $c->model('Provisioning')->call_prov( + $c, + 'voip', + 'get_sound_sets', + # TODO: remove comment + # handle_request (called from call_prov) will add + # reseller_id + # { reseller_id => $params->{reseller_id} }, + undef, # parameters + \$sets, + ); + + return $sets; +} + +# Ends, some people will rob their mothers for the ends ... +1 diff --git a/lib/admin/Controller/subscriber.pm b/lib/admin/Controller/subscriber.pm index 227df3f..d9ae3d5 100644 --- a/lib/admin/Controller/subscriber.pm +++ b/lib/admin/Controller/subscriber.pm @@ -824,6 +824,17 @@ sub preferences : Local { options => $enum_options, } if eval { @$enum_options }; } + elsif ($$pref{preference} eq 'sound_set') { + my $sound_sets; + return unless $c->model('Provisioning')->call_prov( $c, 'voip', 'get_sound_sets_flat', + {}, + \$sound_sets ); + + $$preferences{$$pref{preference}} = { + selected => $$preferences{$$pref{preference}}, + options => $sound_sets, + } if eval { @$sound_sets }; + } push @stashprefs, { key => $$pref{preference}, diff --git a/root/layout/menu b/root/layout/menu index f0d2509..63b25e6 100644 --- a/root/layout/menu +++ b/root/layout/menu @@ -39,6 +39,9 @@
  • SIP Peerings
  • [% END %]
  • Rewrite Rule Sets
  • + [% IF Catalyst.config.domain.audiofile_features %] +
  • Sound sets
  • + [% END %] diff --git a/root/tt/domain_preferences.tt b/root/tt/domain_preferences.tt index 07a0213..3991102 100644 --- a/root/tt/domain_preferences.tt +++ b/root/tt/domain_preferences.tt @@ -145,6 +145,24 @@ [% END %] + [% ELSIF preference.key == "sound_set" AND Catalyst.config.domain.audiofile_features %] +
  • +
    [% preference.key %]:
    +
    +
    + +
    +
  • [% ELSIF preference.data_type == "boolean" %]
  • [% preference.key %]:
    diff --git a/root/tt/peering_preferences.tt b/root/tt/peering_preferences.tt index 25fb3f1..220f2f2 100644 --- a/root/tt/peering_preferences.tt +++ b/root/tt/peering_preferences.tt @@ -142,6 +142,24 @@ [% END %]
  • + [% ELSIF preference.key == "sound_set" AND Catalyst.config.domain.audiofile_features %] +
  • +
    [% preference.key %]:
    +
    +
    + +
    +
  • [% ELSIF preference.data_type == "boolean" %]
  • [% preference.key %]:
    diff --git a/root/tt/sound.tt b/root/tt/sound.tt new file mode 100644 index 0000000..cebe086 --- /dev/null +++ b/root/tt/sound.tt @@ -0,0 +1,109 @@ +

    Manage sound sets

    + + + +
    + diff --git a/root/tt/subscriber_preferences.tt b/root/tt/subscriber_preferences.tt index 1d06754..ca8111a 100644 --- a/root/tt/subscriber_preferences.tt +++ b/root/tt/subscriber_preferences.tt @@ -93,6 +93,24 @@ [% END %]
  • + [% ELSIF preference.key == "sound_set" AND Catalyst.config.domain.audiofile_features %] +
  • +
    [% preference.key %]:
    +
    +
    + +
    +
  • [% ELSIF preference.data_type == "boolean" %]
  • [% preference.key %]: