mirror of https://github.com/sipwise/www_admin.git
parent
187aeb5abe
commit
9d35039b68
@ -1,226 +0,0 @@
|
|||||||
package admin::Controller::xmlctrl;
|
|
||||||
|
|
||||||
use strict;
|
|
||||||
use warnings;
|
|
||||||
use base 'Catalyst::Controller';
|
|
||||||
use Data::Dumper;
|
|
||||||
use UNIVERSAL 'isa';
|
|
||||||
|
|
||||||
|
|
||||||
=head1 NAME
|
|
||||||
|
|
||||||
admin::Controller::xmlctrl - Catalyst Controller
|
|
||||||
|
|
||||||
=head1 DESCRIPTION
|
|
||||||
|
|
||||||
Catalyst Controller.
|
|
||||||
|
|
||||||
=head1 METHODS
|
|
||||||
|
|
||||||
=head2 index
|
|
||||||
|
|
||||||
Display and edit XMLRPC control interfaces
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
sub index : Private {
|
|
||||||
my ( $self, $c ) = @_;
|
|
||||||
$c->stash->{template} = 'tt/xmlctrl.tt';
|
|
||||||
|
|
||||||
my $xmlhosts = undef;
|
|
||||||
return unless $c->model('Provisioning')->call_prov( $c, 'voip', 'get_xmlctrl_hosts',
|
|
||||||
undef,
|
|
||||||
\$xmlhosts
|
|
||||||
);
|
|
||||||
$c->stash->{xmlhosts} = $xmlhosts if eval { @$xmlhosts };
|
|
||||||
|
|
||||||
my $xmlgroups = undef;
|
|
||||||
return unless $c->model('Provisioning')->call_prov( $c, 'voip', 'get_xmlctrl_groups',
|
|
||||||
undef,
|
|
||||||
\$xmlgroups
|
|
||||||
);
|
|
||||||
$c->stash->{xmlgroups} = $xmlgroups if eval { @$xmlgroups };
|
|
||||||
|
|
||||||
|
|
||||||
$c->stash->{edit_host} = $c->request->params->{edit_host};
|
|
||||||
|
|
||||||
if(exists $c->session->{crefill}) {
|
|
||||||
$c->stash->{crefill} = $c->session->{crefill};
|
|
||||||
delete $c->session->{crefill};
|
|
||||||
}
|
|
||||||
if(exists $c->session->{erefill}) {
|
|
||||||
$c->stash->{erefill} = $c->session->{erefill};
|
|
||||||
delete $c->session->{erefill};
|
|
||||||
} elsif($c->request->params->{edit_host}) {
|
|
||||||
foreach my $host (eval { @$xmlhosts }) {
|
|
||||||
if($$host{id} == $c->request->params->{edit_host}) {
|
|
||||||
$c->stash->{erefill} = $host;
|
|
||||||
last;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
=head2 do_create_host
|
|
||||||
|
|
||||||
Create a new xmlctrl interface in the database.
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
sub do_create_host : Local {
|
|
||||||
my ( $self, $c ) = @_;
|
|
||||||
|
|
||||||
my %messages;
|
|
||||||
my %settings;
|
|
||||||
|
|
||||||
$settings{ip} = $c->request->params->{ip};
|
|
||||||
$settings{port} = $c->request->params->{port};
|
|
||||||
$settings{path} = $c->request->params->{path};
|
|
||||||
$settings{description} = $c->request->params->{description}
|
|
||||||
if length $c->request->params->{description};
|
|
||||||
|
|
||||||
unless(isa($c->request->params->{groups}, 'ARRAY')) {
|
|
||||||
my @tmp = ($c->request->params->{groups});
|
|
||||||
$settings{groups} = \@tmp;
|
|
||||||
} else {
|
|
||||||
$settings{groups} = $c->request->params->{groups};
|
|
||||||
}
|
|
||||||
|
|
||||||
$messages{chosterr} = 'Client.Voip.InputErrorFound'
|
|
||||||
unless(length $settings{ip} && $settings{ip} =~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/ &&
|
|
||||||
length $settings{port} && $settings{port} =~ /^[0-9]+$/ &&
|
|
||||||
defined $settings{groups} &&
|
|
||||||
defined $settings{path}
|
|
||||||
);
|
|
||||||
|
|
||||||
unless(keys %messages) {
|
|
||||||
if($c->model('Provisioning')->call_prov( $c, 'voip', 'create_xmlctrl_host',
|
|
||||||
\%settings,
|
|
||||||
undef))
|
|
||||||
{
|
|
||||||
$messages{chostmsg} = 'Server.Voip.SavedSettings';
|
|
||||||
$c->session->{messages} = \%messages;
|
|
||||||
$c->response->redirect("/xmlctrl#create_host");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$messages{chosterr} = 'Client.Voip.InputErrorFound';
|
|
||||||
$c->session->{messages} = \%messages;
|
|
||||||
$c->session->{crefill} = \%settings;
|
|
||||||
$c->response->redirect("/xmlctrl#create_host");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
=head2 do_update_host
|
|
||||||
|
|
||||||
Update settings of an xmlctrl interface in the database.
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
sub do_update_host : Local {
|
|
||||||
my ( $self, $c ) = @_;
|
|
||||||
|
|
||||||
my %messages;
|
|
||||||
my %settings;
|
|
||||||
|
|
||||||
|
|
||||||
$settings{id} = $c->request->params->{host};
|
|
||||||
$settings{ip} = $c->request->params->{ip};
|
|
||||||
$settings{port} = $c->request->params->{port};
|
|
||||||
$settings{path} = $c->request->params->{path};
|
|
||||||
$settings{description} = $c->request->params->{description}
|
|
||||||
if length $c->request->params->{description};
|
|
||||||
unless(isa($c->request->params->{groups}, 'ARRAY')) {
|
|
||||||
my @tmp = ($c->request->params->{groups});
|
|
||||||
$settings{groups} = \@tmp;
|
|
||||||
} else {
|
|
||||||
$settings{groups} = $c->request->params->{groups};
|
|
||||||
}
|
|
||||||
|
|
||||||
$messages{ehosterr} = 'Client.Voip.InputErrorFound'
|
|
||||||
unless(length $settings{id} && $settings{id} =~ /^\d+$/ &&
|
|
||||||
length $settings{ip} && $settings{ip} =~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/ &&
|
|
||||||
length $settings{port} && $settings{port} =~ /^[0-9]+$/ &&
|
|
||||||
defined $settings{groups} &&
|
|
||||||
defined $settings{path}
|
|
||||||
);
|
|
||||||
|
|
||||||
unless(keys %messages) {
|
|
||||||
if($c->model('Provisioning')->call_prov( $c, 'voip', 'update_xmlctrl_host',
|
|
||||||
\%settings,
|
|
||||||
undef))
|
|
||||||
{
|
|
||||||
$messages{ehostmsg} = 'Server.Voip.SavedSettings';
|
|
||||||
$c->session->{messages} = \%messages;
|
|
||||||
$c->response->redirect("/xmlctrl");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$c->response->redirect("/xmlctrl?edit_host=$settings{id}");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$messages{ehosterr} = 'Client.Voip.InputErrorFound';
|
|
||||||
$c->session->{messages} = \%messages;
|
|
||||||
$c->response->redirect("/xmlctrl?edit_level=$settings{id}");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
=head2 do_delete_host
|
|
||||||
|
|
||||||
Delete an xmlrpc control interface from the database.
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
sub do_delete_host : Local {
|
|
||||||
my ( $self, $c ) = @_;
|
|
||||||
|
|
||||||
my %settings;
|
|
||||||
|
|
||||||
$settings{id} = $c->request->params->{host};
|
|
||||||
unless(length $settings{id}) {
|
|
||||||
$c->response->redirect("/xmlctrl");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if($c->model('Provisioning')->call_prov( $c, 'voip', 'delete_xmlctrl_host',
|
|
||||||
\%settings,
|
|
||||||
undef))
|
|
||||||
{
|
|
||||||
$c->session->{messages} = { ehostmsg => 'Server.Voip.SavedSettings' };
|
|
||||||
$c->response->redirect("/xmlctrl");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$c->response->redirect("/xmlctrl");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
=head1 BUGS AND LIMITATIONS
|
|
||||||
|
|
||||||
=over
|
|
||||||
|
|
||||||
=item none
|
|
||||||
|
|
||||||
=back
|
|
||||||
|
|
||||||
=head1 SEE ALSO
|
|
||||||
|
|
||||||
Provisioning model, Sipwise::Provisioning::Billing, Catalyst
|
|
||||||
|
|
||||||
=head1 AUTHORS
|
|
||||||
|
|
||||||
Andreas Granig <agranig@sipwise.com>
|
|
||||||
|
|
||||||
=head1 COPYRIGHT
|
|
||||||
|
|
||||||
The xmlctrl controller is Copyright (c) 2010 Sipwise GmbH, Austria. All
|
|
||||||
rights reserved.
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
# ende gelaende
|
|
||||||
1;
|
|
@ -1,145 +0,0 @@
|
|||||||
<h3>XMLRPC Control Interfaces</h3>
|
|
||||||
|
|
||||||
<div class="p1">
|
|
||||||
[% IF messages.ehostmsg %]<div class="goodmsg">[% messages.ehostmsg %]</div>[% END %]
|
|
||||||
[% IF messages.ehosterr %]<div class="errormsg">[% messages.ehosterr %]</div>[% END %]
|
|
||||||
|
|
||||||
[% IF xmlhosts %]
|
|
||||||
<table class="ncoslevels">
|
|
||||||
<tr class="table_header">
|
|
||||||
<td>IP</td>
|
|
||||||
<td>Port</td>
|
|
||||||
<td>Path</td>
|
|
||||||
<td>Roles</td>
|
|
||||||
<td>Description</td>
|
|
||||||
<td/>
|
|
||||||
<td/>
|
|
||||||
</tr>
|
|
||||||
[% FOREACH host = xmlhosts %]
|
|
||||||
[% IF host.id == edit_host %]
|
|
||||||
<tr>
|
|
||||||
<form action="/xmlctrl/do_update_host" method="post">
|
|
||||||
<input type="hidden" name="host" value="[% host.id %]" />
|
|
||||||
<td><input type="text" title="IP Address" size="15"
|
|
||||||
name="ip" value="[% host.ip %]" />
|
|
||||||
</td>
|
|
||||||
<td><input type="text" title="Port" size="5"
|
|
||||||
name="port" value="[% host.port %]" />
|
|
||||||
</td>
|
|
||||||
<td><input type="text" title="Port" size="10"
|
|
||||||
name="path" value="[% host.path %]" />
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<select size="[% xmlgroups.size %]" name="groups" multiple="multiple">
|
|
||||||
[% FOREACH grp = xmlgroups %]
|
|
||||||
<option value="[% grp.id %]">[% grp.name %]</option>
|
|
||||||
[% END %]
|
|
||||||
</select>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<input type="text" size="20" title="free-form description string"
|
|
||||||
name="description" value="[% host.description %]" />
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<div class="postlink">
|
|
||||||
<label for="hostsave[% host.id %]">save</label>
|
|
||||||
<input type="image" class="hidden" src="/static/images/dot_trans.gif" alt="" id="hostsave[% host.id %]" />
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
</form>
|
|
||||||
<td><a href="/xmlctrl" class="aaction">cancel</a></td>
|
|
||||||
</tr>
|
|
||||||
[% IF messages.ehost %]
|
|
||||||
<tr><td colspan="5"><div class="errormsg">[% messages.ehost %]</div></td></tr>
|
|
||||||
[% END %]
|
|
||||||
[% ELSE %]
|
|
||||||
<tr>
|
|
||||||
<td>[% host.ip %]</a></td>
|
|
||||||
<td>[% host.port %]</td>
|
|
||||||
<td>[% host.path %]</td>
|
|
||||||
<td>
|
|
||||||
<select size="[% host.groups.size %]" name="groups">
|
|
||||||
[% FOREACH grp = host.groups %]
|
|
||||||
<option value="[% grp.id %]">[% grp.name %]</option>
|
|
||||||
[% END %]
|
|
||||||
</select>
|
|
||||||
</td>
|
|
||||||
<td>[% host.description %]</td>
|
|
||||||
<td>
|
|
||||||
[% UNLESS Catalyst.session.admin.read_only %]
|
|
||||||
<a href="/xmlctrl?edit_host=[% host.id %]" class="aaction">edit</a>
|
|
||||||
[% END %]
|
|
||||||
</td>
|
|
||||||
<form action="/xmlctrl/do_delete_host" method="post">
|
|
||||||
<input type="hidden" name="host" value="[% host.id %]" />
|
|
||||||
<td>
|
|
||||||
[% UNLESS Catalyst.session.admin.read_only %]
|
|
||||||
<div class="postlink">
|
|
||||||
<label for="hostdel[% host.id %]">delete</label>
|
|
||||||
<input type="image" class="hidden" src="/static/images/dot_trans.gif" alt="" id="hostdel[% host.id %]" />
|
|
||||||
</div>
|
|
||||||
[% END %]
|
|
||||||
</td>
|
|
||||||
</form>
|
|
||||||
</tr>
|
|
||||||
[% END %]
|
|
||||||
[% END %]
|
|
||||||
</table>
|
|
||||||
[% ELSE %]
|
|
||||||
No XMLRPC Control Interfaces found.
|
|
||||||
[% END %]
|
|
||||||
</div>
|
|
||||||
|
|
||||||
[% UNLESS Catalyst.session.admin.read_only %]
|
|
||||||
<h3 id="create_host">Create XMLRPC Control Interface</h3>
|
|
||||||
|
|
||||||
<div class="p1">
|
|
||||||
[% IF messages.chostmsg %]<div class="goodmsg">[% messages.chostmsg %]</div>[% END %]
|
|
||||||
[% IF messages.chosterr %]<div class="errormsg">[% messages.chosterr %]</div>[% END %]
|
|
||||||
|
|
||||||
<form action="/xmlctrl/do_create_host" method="post">
|
|
||||||
<table class="ncoslevels">
|
|
||||||
<tr class="table_header">
|
|
||||||
<td>IP</td>
|
|
||||||
<td>Port</td>
|
|
||||||
<td>Path</td>
|
|
||||||
<td>Roles</td>
|
|
||||||
<td>Description</td>
|
|
||||||
<td/>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><input type="text" title="IP Address" size="15"
|
|
||||||
name="ip" value="[% crefill.ip %]" />
|
|
||||||
</td>
|
|
||||||
<td><input type="text" title="Port" size="5"
|
|
||||||
name="port" value="[% crefill.port %]" />
|
|
||||||
</td>
|
|
||||||
<td><input type="text" title="Path" size="10"
|
|
||||||
name="path" value="[% crefill.path %]" />
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<select size="[% xmlgroups.size %]" name="groups" multiple="multiple">
|
|
||||||
[% FOREACH grp = xmlgroups %]
|
|
||||||
<option value="[% grp.id %]">[% grp.name %]</option>
|
|
||||||
[% END %]
|
|
||||||
</select>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<input type="text" size="20" title="free-form description string"
|
|
||||||
name="description" value="[% crefill.description %]" />
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<div class="postlink">
|
|
||||||
<label for="hostadd">add</label>
|
|
||||||
<input type="image" class="hidden" src="/static/images/dot_trans.gif" alt="" id="hostadd" />
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
<td />
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</form>
|
|
||||||
[% IF crefill && prov_error %]<div class="errormsg">[% prov_error %]</div>[% END %]
|
|
||||||
|
|
||||||
</div>
|
|
||||||
[% END %]
|
|
||||||
|
|
Loading…
Reference in new issue