#!/usr/bin/perl # # rhwebimport # # Copyright (C) 2014-2015 Christian Pointner # Copyright (C) 2015 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 @clocks = (); 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 = 1; # ($result, $status, $errorstring) = RHRD::rddb::check_token($ctx, $username, $token); if($result == 1) { # TODO: check if user is allowed to read/edit music pools # TODO: dispatch command get,set $responsecode = 200; @clocks = RHRD::rddb::get_musicpools_clocks($ctx); if(!defined $clocks[0] && defined $clocks[1]) { $responsecode = 500; $status = $clocks[1]; $errorstring = $clocks[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"; # TODO: dispatch command get,set if($responsecode != 200) { print "\n"; print " " . xml_quote($responsecode) . "\n"; print " " . xml_quote($errorstring) . "\n"; print "\n"; } else { print "\n"; for my $href (@clocks) { print " {'DOW'}) . "\" hour=\"" . xml_quote($href->{'HOUR'}) . "\">\n"; print " " . xml_quote($href->{'NAME'}) . "\n"; print " " . xml_quote($href->{'COLOR'}) . "\n"; print " " . xml_quote($href->{'TITLE'}) . "\n"; print " \n"; } print "\n"; }