#!/usr/bin/perl # # rhwebimport # # Copyright (C) 2014-2016 Christian Pointner # Copyright (C) 2015-2016 Peter Grassberger # # 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 . # 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 $type = $q->param('TYPE'); if(!defined $username) { $responsecode = 400; $errorstring = "mandatory field LOGIN_NAME is missing" } elsif(!defined $token) { $responsecode = 400; $errorstring = "mandatory field PASSWORD is missing" } else { (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, undef, $type); 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 "\n"; print " " . xml_quote($responsecode) . "\n"; print " " . xml_quote($errorstring) . "\n"; print "\n"; } else { print "\n"; for my $href (@dropboxes) { print " \n"; print " " . xml_quote($href->{'GROUP'}) . "\n"; print " " . xml_quote($href->{'GROUPDESC'}) . "\n"; print " " . xml_quote($href->{'GROUPLOWCART'}) . "\n"; print " " . xml_quote($href->{'GROUPHIGHCART'}) . "\n"; print " " . floor($href->{'NORMLEVEL'}/100) . "\n"; print " " . floor($href->{'TRIMLEVEL'}/100) . "\n"; print " " . xml_quote($href->{'PARAM'}) . "\n"; print " " . xml_quote($href->{'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 " " . xml_quote($href->{'SHOWID'}) . "\n"; print " " . xml_quote($href->{'SHOWTITLE'}) . "\n"; print " " . xml_quote($href->{'SHOWLOG'}) . "\n"; print " " . xml_quote($href->{'SHOWRHYTHM'}) . "\n"; print " " . xml_quote($dow) . "\n"; print " " . xml_quote($starttime) . "\n"; print " " . xml_quote($href->{'SHOWLEN'}) . "\n"; } elsif($href->{'TYPE'} eq "jingle") { print " " . xml_quote($href->{'JINGLETITLE'}) . "\n"; } elsif($href->{'TYPE'} eq "musicpool") { print " " . xml_quote($href->{'MUSICPOOLTITLE'}) . "\n"; print " " . xml_quote($href->{'MUSICPOOLCLOCK'}) . "\n"; } print " \n"; } print "\n"; }