summaryrefslogtreecommitdiff
blob: d7bf899b60b2d510ebc8db7d3d6135eea2827f1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#!/usr/bin/perl -w
#
#   xpptp_fe.pl.pl, graphical user interface for PPTP configuration
#   Copyright (C) 2001  Smoot Carl-Mitchell (smoot@tic.com)
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program 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 General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

use Tk;
use Tk::DirTree;

=pod
TK driver for pptp_fe.pl command script
=cut

=pod
Global flags which correspnd to the pptp_fe.pl flags and options
=cut

my $Debug = 0;
my $Debug_Flag = "";
my $Network = "";
my $Server = "";
my $Routes = "";
my $Get_Current_Config = 0;

=pod

Start up pptp_fe.pl and connect its input and output to the TK frontend.
All I/O is done in raw mode, so the reads and writes are atomic and
unbuffered.

=cut

pipe OUTPUT_READ, OUTPUT_WRITE;
pipe COMMAND_READ, COMMAND_WRITE;

my $Child_Pid = fork();
die "cannot fork - $!\n" if $Child_Pid == -1;

if ($Child_Pid) { # parent
	close OUTPUT_WRITE;
	close COMMAND_READ;
}
else { # child
	close OUTPUT_READ;
	close COMMAND_WRITE;

	open(STDIN, "<&COMMAND_READ");
	open(STDOUT, ">&OUTPUT_WRITE");
	
	exec("pptp_fe.pl -p");
}

=pod
The main window which present the various pptp_fe.pl options.

The window is composed of:

		Server name
		Network number
		Routes
Connect Button Disconnect Button Write Config Button Quit Button
=cut

my $Main = MainWindow->new();
$Main->Label(-text => "PPTP")->pack;

my $Server_Frame = $Main->Frame->pack(-fill => 'x',
	-padx => 5,
	-pady => 5);

$Server_Frame->Label(-text => "Remote PPTP Host")->pack(-side => "left");
$Server_Frame->Entry(
	-text => "Host",
	-width => 30,
	-textvariable => \$Server,
	)->pack(-side => "left");


my $Net_Frame = $Main->Frame->pack(-fill => 'x',
	-padx => 5,
	-pady => 5);

=pod
Network number entry box.  This is the argument to the the -n flag
=cut

$Net_Frame->Label(-text => "Network Number")->pack(-side => "left");
$Net_Frame->Entry(
	-text => "Network",
	-width => 15,
	-textvariable => \$Network,
	)->pack(-side => "left");

=pod
Additional static routes (-r) flag
=cut

my $Route_Frame = $Main->Frame->pack(
	-fill => 'x',
	-padx => 5,
	-pady => 5);

$Route_Frame->Label(-text => "Routes")->pack(-side => "left");

$Route_Frame->Entry(
	-text => "Routes",
	-width => 30,
	-textvariable => \$Routes
	)->pack(
		-side => "left",
		-padx => 5,
		-pady => 5);

=pod
Buttons

Connect - Connect to a remote PPTP server

Disconnect - Disconnect from the remote PPTP server

Write - Write a configuration file

Quit - Terminates the running pptp daemon and pptp_fe.pl program.
=cut

my $Button_Frame = $Main->Frame->pack(-fill => 'x', -pady => 5);
 
my $Disconnect_Button;
my $Connect_Button;
my $Read_Button;
my $Write_Button;
my $Quit_Button;

$Connect_Button = $Button_Frame->Button(
	-text => "Connect",
	-command =>
		sub {
			update_config();
			syswrite(COMMAND_WRITE, "c\n");

			$Connect_Button->configure(-state => "disabled");
			$Disconnect_Button->configure(-state => "normal");
		},
	)->pack(-side => "left", -pady => 5, -padx => 5);

$Disconnect_Button = $Button_Frame->Button(
	-text => "Disconnect",
	-state => "disabled",
	-command =>
		sub {
			syswrite(COMMAND_WRITE, "d\n");

			$Connect_Button->configure(-state => "normal");
			$Disconnect_Button->configure(-state => "disabled");
		}
	)->pack(-side => "left", -pady => 5, -padx => 5);

$Write_Button = $Button_Frame->Button(
	-text => "Write Config",
	-command =>
		sub {
			syswrite(COMMAND_WRITE, "w\n");

		}
	)->pack(-side => "left", -pady => 5, -padx => 5);

$Quit_Button = $Button_Frame->Button(
	-text => "Quit",
	-command =>
		sub {
			syswrite(COMMAND_WRITE, "q\n");

			$Connect_Button->configure(-state => "disabled");
			$Disconnect_Button->configure(-state => "disabled");
			$Quit_Button->configure(-state => "disabled");
		}
	)->pack(-side => "left", -pady => 5, -padx => 5);

my $Log_Window = $Main->Toplevel;
$Log_Window->title("PPTP Log");

my $Log_Widget = $Log_Window->Text(
	-height => 20,
	-width => 80,
	)->pack;


$Log_Widget->fileevent(OUTPUT_READ, "readable", sub {
	my $in = "";
	my $n = sysread(OUTPUT_READ, $in, 1024);
	if ($n == 0) {
		close OUTPUT_READ;
		$Main->destroy;
		exit 0;
	}

	if (!$Get_Current_Config) {
		$Log_Widget->insert("end", $in);
		$Log_Widget->see("end");
	}
	else {
		$Get_Current_Config = 0;

		for my $line (split("\n", $in)) {
			next unless $line =~ /\S/;

			my ($variable, $value) = split(/\s*=\s*/, $line);
			$variable = "\L$variable";

			if ($variable eq "server") {
				$Server = $value;
			}
			elsif ($variable eq "network") {
				$Network = $value;
			}
			elsif ($variable eq "routes") {
				$Routes = $value;
			}
			elsif ($variable eq "debug") {
				$Debug = $value;
			}
		}
	}

	return 1;
});

syswrite(COMMAND_WRITE, "l\n");
$Get_Current_Config = 1;

MainLoop;

sub update_config {

	syswrite(COMMAND_WRITE, "s server = $Server\n");
	syswrite(COMMAND_WRITE, "s network = $Network\n");
	syswrite(COMMAND_WRITE, "s routes = $Routes\n");
	syswrite(COMMAND_WRITE, "s debug = $Debug_Flag\n");
}