#!/usr/bin/perl use strict; use warnings; use Config::IniFiles; use DBI; sub get_token { my $username = shift; my $RD_CONF = "/etc/rd.conf"; my $cfg = Config::IniFiles->new(-file => $RD_CONF) or return ('ERROR', "Config File Error: " . join("\n", @Config::IniFiles::errors), ''); my $dbhost = $cfg->val('mySQL', 'Hostname'); my $dbname = $cfg->val('mySQL', 'Database'); my $dbuser = $cfg->val('mySQL', 'Loginname'); my $dbpasswd = $cfg->val('mySQL', 'Password'); my $dbh = DBI->connect("DBI:mysql:$dbname:$dbhost","$dbuser","$dbpasswd") or return ('ERROR', "Database Error: $DBI::errstr", ''); return ('OK', 'success', 'this is still not the right token but we will get to it!!'); } my $status = 'ERROR'; my $errorstring = 'unknown'; my $username = ''; my $token = ''; if(defined $ENV{REMOTE_USER}) { ($status, $errorstring, $token) = get_token($ENV{REMOTE_USER}); $username = $ENV{REMOTE_USER}; } else { $errorstring = 'no username defined'; } print "Content-type: application/json\n\n"; print "{\n"; print " 'status': '" . $status . "',\n"; print " 'errorstring': '" . $errorstring . "',\n"; print " 'username': '" . $username . "',\n"; print " 'token': '" . $token . "'\n"; print "}\n";