#!/usr/bin/perl -w


# Author is not held responsible for any damages by this script. 
# Feel free to redistribute and modify the script.
#
#
# Author: brian2004[at] hotmail[dot] com
#
# DynDNS Utility v1.0
# Feel free to modify and redistribute under GNU
# Obtain IP address from http://checkip.dyndns.org

$^W++;                            # Turn on debug warnings
use strict;                       # Strict Variables!
use IO::Socket;                   # Sock support
use MIME::Base64;                 # Base64 encoding support
use Data::Dumper;                 # Data Dumper

use Tk;
use Tk::Dialog;
use Tk::Entry;
use Tk::Label;
use Tk::Scrollbar;
use Tk::Text;
use Tk::Menu;
use Tk::Frame;
use Tk::DialogBox;
use Tk::Menubutton;
use Tk::Button;
use Tk::Radiobutton;
use Tk::Toplevel;
use Tk::Optionmenu;

my $local_proxy_port = "1080";
my $remote_proxy_port = "8080";
my $remote_address = "184.0.0.1";

# Create and Display GUI
my $mw = MainWindow->new();

$mw->title ("TinyProxy");
$mw->geometry('+500+300');

my $lbl1 = $mw->Label(
     -text         => "Local Port:",
)
     ->pack(
     -side         => 'top',
     -anchor       => 'nw'
);

my $txt1 = $mw->Entry(
     -textvariable => \$local_proxy_port,
     -background   => 'gray',
     -foreground   => 'black',
)
     ->pack(
     -side         => 'top',
     -anchor       => 'ne'
);

my $lbl2 = $mw->Label(
     -text         => "Remote Port:",
)
     ->pack(
  
   -side         => 'top',
     -anchor       => 'nw'
);

my $txt2 = $mw->Entry(
     -textvariable => \$remote_proxy_port,
     -background   => 'gray',
     -foreground   => 'black',
)
     ->pack(
     -side         => 'top',
     -anchor       => 'ne'
);

my $lbl3 = $mw->Label(
     -text         => "Remote Proxy Address:",
)
     ->pack(
  
   -side         => 'top',
     -anchor       => 'nw'
);

my $txt3 = $mw->Entry(
     -textvariable => \$remote_address,
     -background   => 'gray',
     -foreground   => 'black',
)
     ->pack(
     -side         => 'top',
     -anchor       => 'ne'
);

my $btn1 = $mw->Button(
     -text         => "Start",
     -command      => sub { &start_process }
)
     ->pack(
     -side         => 'left',
     -anchor       => 'nw',
);

my $btn2 = $mw->Button(
     -text         => "Done",
     -command      => sub { exit }
)
     ->pack(
     -side         => 'left',
     -anchor       => 'ne',
);

# Subroutine for staring process operation.
sub start_process{
use strict;
use warnings;

my $ProxyExe="proxy.exe $local_proxy_port $remote_address:$remote_proxy_port";
print "$ProxyExe \n";
print "Starting Proxy\n";
print for qx|$ProxyExe 2>&1|;
print "Program $ProxyExe Executed.\n";
}

# Initiate Main Loop where the Loop.
MainLoop();