]> iEval git - app-remotegnokii.git/blame - lib/App/RemoteGnokii.pm
Bump version and update Changes
[app-remotegnokii.git] / lib / App / RemoteGnokii.pm
CommitLineData
832c594d
MG
1package App::RemoteGnokii;
2
3use 5.014000;
4use strict;
5use warnings;
c515cb22 6our $VERSION = '0.001';
832c594d
MG
7
8use Config::Any;
9use File::Copy qw/move/;
10use File::Temp qw/tempfile/;
11use Plack::Request;
12
13my $cfg;
14
ca8f39c8 15sub cfg ($){ ## no critic (ProhibitSubroutinePrototypes)
832c594d
MG
16 unless ($cfg) {
17 $cfg = Config::Any->load_stems({stems => [$ENV{RGCONFIG} // '/etc/rg'], use_ext => 1, flatten_to_hash => 1});
18 my @cfg = values %$cfg;
19 $cfg = $cfg[0];
20 }
21
22 $cfg->{$_[0]}
23}
24
25sub sendsms {
26 my ($number, $text) = @_;
27 my ($fh, $file) = tempfile 'smsXXXX', TMPDIR => 1;
ca8f39c8
MG
28 print $fh "$number\n$text" or warn "print: $!"; ## no critic (RequireCarping)
29 close $fh or warn "close: $!"; ## no critic (RequireCarping)
832c594d
MG
30 move $file, cfg 'spool';
31}
32
33##################################################
34
35sub action {
36 my ($number, $date, $text) = @_;
37 my $password = cfg 'password';
ca8f39c8 38 sendsms cfg 'number', <<"EOF"
832c594d
MG
39$password
40$number
41$date
42$text
43EOF
44}
45
46sub psgi {
47 my $correct_password = cfg 'password';
48 sub {
49 my $r = Plack::Request->new(shift);
ca8f39c8 50 my @numbers = split /,/s, $r->param('numbers');
832c594d
MG
51 my $password = $r->param('password');
52 return [403, ['Content-Type', 'text/plain'], ['Bad password']] unless $password eq $correct_password;
53 my $text = $r->param('text');
54
55 sendsms $_, $text for @numbers
56 }
57}
58
591;
60__END__
61
62=encoding utf-8
63
64=head1 NAME
65
66App::RemoteGnokii - Send SMS over the internet with gnokii-smsd
67
68=head1 SYNOPSIS
69
70 use App::RemoteGnokii;
71 my $config_option = App::RemoteGnokii::cfg 'name';
72 App::RemoteGnokii::sendsms '0755555555', 'Hello world';
73 App::RemoteGnokii::action('0755555555', '2014-02-01', 'Goodbye');
74
75=head1 DESCRIPTION
76
77RemoteGnokii is a set of scripts that add networking to gnokii-smsd. With them, all messages received are forwarded to a given phone number, and messages can be sent via the HTTP gateway provided by RemoteGnokii.
78
79=head1 CONFIGURATION OPTIONS
80
81See below for the location of the configuration file. The following options are recognised:
82
83=over
84
85=item number
86
87Forward incoming messages to this number (used by L<rg-action>).
88
89=item password
90
91The password needed to send a message with L<rg-psgi> and included in forwarded messages.
92
93=item spool
94
95The gnokii-smsd spool directory. Needs to be readable and writable by gnokii-smsd and L<rg-psgi>.
96
97=back
98
99=head1 ENVIRONMENT
100
101=over
102
103=item RGCONF
104
105The basename of the configuration file. For example, if the configuration file is '/srv/rg/config.yml', RGCONF should be set to '/srv/rg/config'. Defaults to '/etc/rg'.
106
107=back
108
109=head1 TODO
110
111=over
112
113=item Write a section 7 manpage explaining everything
114
115=item Add tests
116
117=item Add a way to store messages for later retrieval via the webapp, instead of sending them immediately via SMS
118
119=back
120
121=head1 AUTHOR
122
123Marius Gavrilescu E<lt>marius@ieval.roE<gt>
124
125=head1 COPYRIGHT AND LICENSE
126
127Copyright (C) 2014 by Marius Gavrilescu
128
129This library is free software: you can redistribute it and/or modify
130it under the terms of the GNU General Public License as published by
131the Free Software Foundation, either version 3 of the License, or (at
132your option) any later version.
133
134
135=cut
This page took 0.041498 seconds and 4 git commands to generate.