blob: b6503ba517c25c026027d4e13df10fbb8614e289 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
package FS::UI::REST;
use base qw( Exporter );
use strict;
use vars qw( @EXPORT_OK );
use JSON::XS;
use FS::UID qw( adminsuidsetup );
use FS::Conf;
@EXPORT_OK = qw( rest_auth rest_uri_remain encode_rest );
sub rest_auth {
my $cgi = shift;
adminsuidsetup('fs_api');
my $conf = new FS::Conf;
die 'Incorrect shared secret'
unless $cgi->param('secret') eq $conf->config('api_shared_secret');
}
sub rest_uri_remain {
my($r, $m) = @_;
#wacky way to get this... surely there must be a better way
my $path = $m->request_comp->path;
$r->uri =~ /\Q$path\E\/?(.*)$/ or die "$path not in ". $r->uri;
$1;
}
sub encode_rest {
#XXX HTTP Accept header to send other formats besides JSON
encode_json(shift);
}
1;
|