summaryrefslogtreecommitdiff
path: root/rh-bin/listdropboxes.cgi
blob: a451dc720c54a0f2c127d15e34919c47b2a8a114 (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/perl
#
#  rhwebimport
#
#  Copyright (C) 2014-2015 Christian Pointner <equinox@helsinki.at>
#  Copyright (C) 2015 Peter Grassberger <petertheone@gmail.at>
#
#  This file is part of rhwebimport.
#
#  rhwebimport is free software: you can redistribute it and/or modify
#  it under the terms of the GNU Affero General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  any later version.
#
#  rhwebimport is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU Affero General Public License for more details.
#
#  You should have received a copy of the GNU Affero General Public License
#  along with rhwebimport. If not, see <http://www.gnu.org/licenses/>.
#

use strict;
use CGI;
use POSIX;
use XML::Quote;
use RHRD::rddb;

my $status = 'ERROR';
my $errorstring = 'unknown';
my $responsecode = 500;
my @dropboxes = ();

my $q = CGI->new;
my $username = $q->param('LOGIN_NAME');
my $token = $q->param('PASSWORD');

(my $ctx, $status, $errorstring) = RHRD::rddb::init();
if(defined $ctx) {
  my $result;
  ($result, $status, $errorstring) = RHRD::rddb::check_token($ctx, $username, $token);
  if($result == 1) {
    $responsecode = 200;
    @dropboxes = RHRD::rddb::get_dropboxes($ctx, $username);
    if(!defined $dropboxes[0] && defined $dropboxes[1]) {
      $responsecode = 500;
      $status = $dropboxes[1];
      $errorstring = $dropboxes[2];
    }
  } elsif($result == 0) {
    $responsecode = 401;
  } else {
    $responsecode = 500;
  }
  RHRD::rddb::destroy($ctx);
}

print "Content-type: application/xml; charset=UTF-8\n";
print "Status: $responsecode\n\n";

if($responsecode != 200) {
  print "<RDWebResult>\n";
  print "  <ResponseCode>" . xml_quote($responsecode) . "</ResponseCode>\n";
  print "  <ErrorString>" . xml_quote($errorstring) . "</ErrorString>\n";
  print "</RDWebResult>\n";
} else {
  print "<dropboxList>\n";
  for my $href (@dropboxes) {
    print "  <dropbox>\n";
    print "    <group>" . xml_quote($href->{'GROUP'}) . "</group>\n";
    print "    <group-description>" . xml_quote($href->{'GROUPDESC'}) . "</group-description>\n";
    print "    <group-low-cart>" . xml_quote($href->{'GROUPLOWCART'}) . "</group-low-cart>\n";
    print "    <group-high-cart>" . xml_quote($href->{'GROUPHIGHCART'}) . "</group-high-cart>\n";
    print "    <normalization-level>" . floor($href->{'NORMLEVEL'}/100) . "</normalization-level>\n";
    print "    <autotrim-level>" . floor($href->{'TRIMLEVEL'}/100) . "</autotrim-level>\n";
    print "    <parameters>" . xml_quote($href->{'PARAM'}) . "</parameters>\n";
    print "    <type>" . xml_quote($href->{'TYPE'}) . "</type>\n";
    if($href->{'TYPE'} eq "show") {
      my $dow = $href->{'SHOWDOW'};
      $dow = 0 unless $dow < 7;
      my $starttime = $href->{'SHOWSTARTTIME'};
      substr($starttime, 2, 0) = ':';
      print "    <show-id>" . xml_quote($href->{'SHOWID'}) . "</show-id>\n";
      print "    <show-title>" . xml_quote($href->{'SHOWTITLE'}) . "</show-title>\n";
      print "    <show-log>" . xml_quote($href->{'SHOWLOG'}) . "</show-log>\n";
      print "    <show-rhythm>" . xml_quote($href->{'SHOWRHYTHM'}) . "</show-rhythm>\n";
      print "    <show-dayofweek>" . xml_quote($dow) . "</show-dayofweek>\n";
      print "    <show-starttime>" . xml_quote($starttime) . "</show-starttime>\n";
      print "    <show-length>" . xml_quote($href->{'SHOWLEN'}) . "</show-length>\n";
    } elsif($href->{'TYPE'} eq "jingle") {
      print "    <jingle-title>" . xml_quote($href->{'JINGLETITLE'}) . "</jingle-title>\n";
    } elsif($href->{'TYPE'} eq "musicpool") {
      print "    <musicpool-title>" . xml_quote($href->{'MUSICPOOLTITLE'}) . "</musicpool-title>\n";
    }
    print "  </dropbox>\n";
  }
  print "</dropboxList>\n";
}