parent
75fccd3920
commit
b88d36bdf0
@ -0,0 +1,76 @@
|
||||
package NGCP::Panel::Form::Subscriber::Webfax;
|
||||
|
||||
use HTML::FormHandler::Moose;
|
||||
extends 'HTML::FormHandler';
|
||||
use Moose::Util::TypeConstraints;
|
||||
|
||||
use HTML::FormHandler::Widget::Block::Bootstrap;
|
||||
|
||||
has '+widget_wrapper' => ( default => 'Bootstrap' );
|
||||
has '+enctype' => ( default => 'multipart/form-data');
|
||||
has_field 'submitid' => ( type => 'Hidden' );
|
||||
sub build_render_list {[qw/submitid fields actions/]}
|
||||
sub build_form_element_class {[qw(form-horizontal)]}
|
||||
|
||||
has_field 'destination' => (
|
||||
type => 'Text',
|
||||
label => 'Destination Number',
|
||||
required => 1,
|
||||
element_attr => {
|
||||
rel => ['tooltip'],
|
||||
title => ['The number to send the fax to']
|
||||
},
|
||||
);
|
||||
|
||||
has_field 'data' => (
|
||||
type => 'TextArea',
|
||||
label => 'Content',
|
||||
cols => 200,
|
||||
rows => 10,
|
||||
maxlength => '1048576', # 1MB
|
||||
element_class => [qw/ngcp-autoconf-area/],
|
||||
);
|
||||
|
||||
has_field 'faxfile' => (
|
||||
type => 'Upload',
|
||||
max_size => 67108864,
|
||||
label => 'or File',
|
||||
element_attr => {
|
||||
rel => ['tooltip'],
|
||||
title => ['Supported File Types are TXT, PDF, PS, TIFF']
|
||||
},
|
||||
);
|
||||
|
||||
has_field 'save' => (
|
||||
type => 'Submit',
|
||||
value => 'Send',
|
||||
element_class => [qw/btn btn-primary/],
|
||||
label => '',
|
||||
);
|
||||
|
||||
has_block 'fields' => (
|
||||
tag => 'div',
|
||||
class => [qw/modal-body/],
|
||||
render_list => [qw/destination data faxfile/],
|
||||
);
|
||||
|
||||
has_block 'actions' => (
|
||||
tag => 'div',
|
||||
class => [qw/modal-footer/],
|
||||
render_list => [qw/save/],
|
||||
);
|
||||
|
||||
sub validate {
|
||||
my $self = shift;
|
||||
my $data = $self->field('data')->value;
|
||||
my $upload = $self->field('faxfile')->value;
|
||||
|
||||
use Data::Printer; print ">>>>>>>>>>>>>>>>>>>>>> upload\n"; p $data; p $upload; p $self->fields;
|
||||
|
||||
unless($data || $upload) {
|
||||
$self->field('faxfile')->add_error("You need to specify a file to fax, if no text is entered in the content field");
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
# vim: set tabstop=4 expandtab:
|
@ -0,0 +1,89 @@
|
||||
package NGCP::Panel::Utils::Hylafax;
|
||||
|
||||
use Sipwise::Base;
|
||||
use File::Temp qw/tempfile/;
|
||||
use TryCatch;
|
||||
|
||||
use Data::Dumper;
|
||||
|
||||
sub send_fax {
|
||||
my (%args) = @_;
|
||||
|
||||
my $c = $args{c};
|
||||
my $subscriber = $args{subscriber};
|
||||
my $prov_subscriber = $subscriber->provisioning_voip_subscriber;
|
||||
|
||||
my $sendfax = $c->config->{faxserver}->{sendfax} // '/usr/bin/sendfax';
|
||||
my @sendfax_args = ();
|
||||
|
||||
my $sender = 'webfax';
|
||||
my $number;
|
||||
if($subscriber->primary_number) {
|
||||
$number = $subscriber->primary_number->cc .
|
||||
($subscriber->primary_number->ac // '').
|
||||
$subscriber->primary_number->sn;
|
||||
} else {
|
||||
$number = $sender;
|
||||
}
|
||||
if($prov_subscriber->voip_fax_preference) {
|
||||
$sender = $prov_subscriber->voip_fax_preference->name;
|
||||
if($prov_subscriber->voip_fax_preference->password) {
|
||||
push @sendfax_args, '-o '.$number.':'.$prov_subscriber->voip_fax_preference->password;
|
||||
} else {
|
||||
push @sendfax_args, '-o '.$number;
|
||||
}
|
||||
} else {
|
||||
push @sendfax_args, '-o '.$number;
|
||||
}
|
||||
|
||||
push @sendfax_args, '-h '.($c->config->{faxserver}->{ip} // '127.0.0.1');
|
||||
if($args{notify}) {
|
||||
push @sendfax_args, '-D';
|
||||
push @sendfax_args, "-f '$sender <$args{notify}>'";
|
||||
} else {
|
||||
push @sendfax_args, "-f '$sender'";
|
||||
}
|
||||
unless($args{coverpage}) {
|
||||
push @sendfax_args, '-n';
|
||||
}
|
||||
if($args{resolution}) {
|
||||
if($args{resolution} eq 'low') {
|
||||
push @sendfax_args, '-l';
|
||||
} elsif($args{resolution} eq 'medium') {
|
||||
push @sendfax_args, '-m';
|
||||
} elsif($args{resolution} eq 'extended') {
|
||||
push @sendfax_args, '-G';
|
||||
}
|
||||
}
|
||||
|
||||
push @sendfax_args, '-d '.$args{destination};
|
||||
|
||||
my ($fh, $filename);
|
||||
if($args{data}) {
|
||||
($fh, $filename) = tempfile;
|
||||
unless(print $fh $args{data}) {
|
||||
my $err = $!;
|
||||
close $fh;
|
||||
unlink $filename;
|
||||
die $c->loc("Failed to write fax data to temporary file: [_1]", $err);
|
||||
}
|
||||
close $fh;
|
||||
} else {
|
||||
$filename = eval { $args{upload}->tempname };
|
||||
}
|
||||
push @sendfax_args, $filename;
|
||||
|
||||
my $sa = join(' ', @sendfax_args);
|
||||
my $output = `$sendfax $sa 2>&1`;
|
||||
my $exit = $?;
|
||||
unlink $filename;
|
||||
|
||||
if($exit ne '0') {
|
||||
chomp $output;
|
||||
die $output."\n";
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
# vim: set tabstop=4 expandtab:
|
@ -0,0 +1,19 @@
|
||||
[% site_config.title = c.loc('Fax Journal for [_1]@[_2]', subscriber.username, subscriber.domain.domain) -%]
|
||||
|
||||
[%
|
||||
helper.name = c.loc('Fax');
|
||||
helper.dt_columns = fax_dt_columns;
|
||||
helper.column_sort = 'the_timestamp';
|
||||
helper.form_object = form;
|
||||
helper.create_flag = create_flag;
|
||||
helper.ajax_uri = c.uri_for_action('/subscriber/webfax_ajax', [c.req.captures.0]);
|
||||
helper.messages = messages;
|
||||
|
||||
helper.top_buttons = [
|
||||
{ name = c.loc('Send Fax'), uri = c.uri_for_action('/subscriber/webfax_send', [ subscriber.id ]), icon = 'icon-print' },
|
||||
];
|
||||
|
||||
PROCESS 'helpers/datatables.tt';
|
||||
%]
|
||||
|
||||
[% # vim: set tabstop=4 syntax=html expandtab: -%]
|
Loading…
Reference in new issue