143948Sbrian#! /usr/local/bin/wish8.0 -f
243948Sbrian#
343948Sbrian# Copyright (c) 1999 Brian Somers <brian@Awfulhak.org>
443948Sbrian# All rights reserved.
543948Sbrian#
643948Sbrian# Redistribution and use in source and binary forms, with or without
743948Sbrian# modification, are permitted provided that the following conditions
843948Sbrian# are met:
943948Sbrian# 1. Redistributions of source code must retain the above copyright
1043948Sbrian#    notice, this list of conditions and the following disclaimer.
1143948Sbrian# 2. Redistributions in binary form must reproduce the above copyright
1243948Sbrian#    notice, this list of conditions and the following disclaimer in the
1343948Sbrian#    documentation and/or other materials provided with the distribution.
1443948Sbrian#
1543948Sbrian# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1643948Sbrian# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1743948Sbrian# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1843948Sbrian# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1943948Sbrian# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2043948Sbrian# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2143948Sbrian# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2243948Sbrian# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2343948Sbrian# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2443948Sbrian# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2543948Sbrian# SUCH DAMAGE.
2643948Sbrian#
2750476Speter# $FreeBSD: releng/10.3/share/examples/ppp/chap-auth 50476 1999-08-28 00:22:10Z peter $
2843948Sbrian
2943948Sbrian#
3043948Sbrian# Display a window to request a users CHAP secret, accepting the relevant
3143948Sbrian# values from ppp (``set authkey !thisprogram'') and passing the entered
3243948Sbrian# ``authname'' and ``authkey'' back to ppp.
3343948Sbrian#
3443948Sbrian
3543948Sbrianset pwidth 12;		# Prompt field width
3643948Sbrianset vwidth 20;		# Value field width
3743948Sbrianset fxpad 7;		# Value field width
3843948Sbrianset fypad 3;		# Value field width
3943948Sbrian
4043948Sbrianwm title . "PPP Authentication";
4143948Sbrian
4243948Sbrian# We expect three lines of input from ppp
4343948Sbrianset hostname [gets stdin];
4443948Sbrianset challenge [gets stdin];
4543948Sbrianset authname [gets stdin];
4643948Sbrian
4743948Sbrianproc mkhalfframe { n prompt } {
4843948Sbrian  global pwidth;
4943948Sbrian
5043948Sbrian  frame .$n;
5143948Sbrian  text  .$n.prompt -width $pwidth -height 1 -relief flat;
5243948Sbrian        .$n.prompt insert 1.0 $prompt;
5343948Sbrian  pack  .$n.prompt -side left;
5443948Sbrian        .$n.prompt configure -state disabled;
5543948Sbrian}
5643948Sbrian
5743948Sbrianproc mkframe { n prompt value entry } {
5843948Sbrian  global vwidth fxpad fypad;
5943948Sbrian
6043948Sbrian  mkhalfframe $n $prompt;
6143948Sbrian  text  .$n.value -width $vwidth -height 1;
6243948Sbrian        .$n.value insert 1.0 $value;
6343948Sbrian  pack  .$n.value -side right;
6443948Sbrian  if ($entry) {
6543948Sbrian    # Allow entry, but don't encourage it
6643948Sbrian    .$n.value configure -state normal -takefocus 0;
6743948Sbrian    bind .$n.value <Return> {done};
6843948Sbrian  } else {
6943948Sbrian    .$n.value configure -state disabled;
7043948Sbrian  }
7143948Sbrian  pack .$n -side top -padx $fxpad -pady $fypad;
7243948Sbrian}
7343948Sbrian
7443948Sbrian# Dump our fields to stdout and exit
7543948Sbrianproc done {} {
7643948Sbrian  puts [.n.value get 1.0 {end - 1 char}];
7743948Sbrian  puts [.k.value get];
7843948Sbrian  exit 0;
7943948Sbrian}
8043948Sbrian
8143948Sbrianmkframe h "Hostname:" $hostname 0;
8243948Sbrianmkframe c "Challenge:" $challenge 0;
8343948Sbrianmkframe n "Authname:" $authname 1;
8443948Sbrian
8543948Sbrianmkhalfframe k "Authkey:";
8643948Sbrianentry .k.value -show "*" -width $vwidth;
8743948Sbrianpack  .k.value -side right;
8843948Sbrianbind  .k.value <Return> {done};
8943948Sbrianfocus .k.value;
9043948Sbrianpack  .k -side top -padx $fxpad -pady $fypad;
9143948Sbrian
9243948Sbrianframe  .b;
9343948Sbrianbutton .b.ok -default active -text "Ok" -command {done};
9443948Sbrianpack   .b.ok -side left;
9543948Sbrianbutton .b.cancel -default normal -text "Cancel" -command {exit 1};
9643948Sbrianpack   .b.cancel -side right;
9743948Sbrianpack   .b -side top -padx $fxpad -pady $fypad;
98