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