#!/usr/bin/perl

my($SOAP_URL_PREFIX) = "SOAP_URI: https://";
my($SOAP_URL_SUFFIX) = "/axis/services/IHostRegistrationService"; 

my($is_local) = defined($ARGV[0]) && ($ARGV[0] eq "true");
my($sid) = defined($ARGV[1]) ? $ARGV[1] : undef;

use lib '/opt/tnt/lib';
use tntdb;
use tntutil;

$dbconf = new TNTdbFile;

my($dbh) = getDatabaseConnection($dbconf->get("PTBASE"),
				$dbconf->get("PGHOST"),
				$dbconf->get("PGPORT"),
				$dbconf->get("DBUSER"),
				$dbconf->get("DBPASS"),
                        { PrintError => 1 });
my($values_ref) = $dbh->selectrow_arrayref("select inviteurl, activationcertificate from tnt_config.portalbase");
my($is_literal_ipv6) = ($$values_ref[0] =~ /\:/);

print STDOUT $SOAP_URL_PREFIX . ($is_literal_ipv6 ? "[" : "") . ($is_local ? "127.0.0.1" : $$values_ref[0]) . ($is_literal_ipv6 ? "]" : "") . $SOAP_URL_SUFFIX . "\n";
if (defined($sid)) {
	print STDOUT "SID: $sid\n";
}
print STDOUT $$values_ref[1];

$dbh->disconnect;
