xref: /freebsd/share/examples/ppp/chap-auth (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
11d8fe861SBrian Somers#! /usr/local/bin/wish8.0 -f
21d8fe861SBrian Somers#
31d8fe861SBrian Somers# Copyright (c) 1999 Brian Somers <brian@Awfulhak.org>
41d8fe861SBrian Somers# All rights reserved.
51d8fe861SBrian Somers#
61d8fe861SBrian Somers# Redistribution and use in source and binary forms, with or without
71d8fe861SBrian Somers# modification, are permitted provided that the following conditions
81d8fe861SBrian Somers# are met:
91d8fe861SBrian Somers# 1. Redistributions of source code must retain the above copyright
101d8fe861SBrian Somers#    notice, this list of conditions and the following disclaimer.
111d8fe861SBrian Somers# 2. Redistributions in binary form must reproduce the above copyright
121d8fe861SBrian Somers#    notice, this list of conditions and the following disclaimer in the
131d8fe861SBrian Somers#    documentation and/or other materials provided with the distribution.
141d8fe861SBrian Somers#
151d8fe861SBrian Somers# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
161d8fe861SBrian Somers# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
171d8fe861SBrian Somers# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
181d8fe861SBrian Somers# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
191d8fe861SBrian Somers# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
201d8fe861SBrian Somers# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
211d8fe861SBrian Somers# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
221d8fe861SBrian Somers# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
231d8fe861SBrian Somers# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
241d8fe861SBrian Somers# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
251d8fe861SBrian Somers# SUCH DAMAGE.
261d8fe861SBrian Somers#
271d8fe861SBrian Somers
281d8fe861SBrian Somers#
291d8fe861SBrian Somers# Display a window to request a users CHAP secret, accepting the relevant
301d8fe861SBrian Somers# values from ppp (``set authkey !thisprogram'') and passing the entered
311d8fe861SBrian Somers# ``authname'' and ``authkey'' back to ppp.
321d8fe861SBrian Somers#
331d8fe861SBrian Somers
341d8fe861SBrian Somersset pwidth 12;		# Prompt field width
351d8fe861SBrian Somersset vwidth 20;		# Value field width
361d8fe861SBrian Somersset fxpad 7;		# Value field width
371d8fe861SBrian Somersset fypad 3;		# Value field width
381d8fe861SBrian Somers
391d8fe861SBrian Somerswm title . "PPP Authentication";
401d8fe861SBrian Somers
411d8fe861SBrian Somers# We expect three lines of input from ppp
421d8fe861SBrian Somersset hostname [gets stdin];
431d8fe861SBrian Somersset challenge [gets stdin];
441d8fe861SBrian Somersset authname [gets stdin];
451d8fe861SBrian Somers
461d8fe861SBrian Somersproc mkhalfframe { n prompt } {
471d8fe861SBrian Somers  global pwidth;
481d8fe861SBrian Somers
491d8fe861SBrian Somers  frame .$n;
501d8fe861SBrian Somers  text  .$n.prompt -width $pwidth -height 1 -relief flat;
511d8fe861SBrian Somers        .$n.prompt insert 1.0 $prompt;
521d8fe861SBrian Somers  pack  .$n.prompt -side left;
531d8fe861SBrian Somers        .$n.prompt configure -state disabled;
541d8fe861SBrian Somers}
551d8fe861SBrian Somers
561d8fe861SBrian Somersproc mkframe { n prompt value entry } {
571d8fe861SBrian Somers  global vwidth fxpad fypad;
581d8fe861SBrian Somers
591d8fe861SBrian Somers  mkhalfframe $n $prompt;
601d8fe861SBrian Somers  text  .$n.value -width $vwidth -height 1;
611d8fe861SBrian Somers        .$n.value insert 1.0 $value;
621d8fe861SBrian Somers  pack  .$n.value -side right;
631d8fe861SBrian Somers  if ($entry) {
641d8fe861SBrian Somers    # Allow entry, but don't encourage it
651d8fe861SBrian Somers    .$n.value configure -state normal -takefocus 0;
661d8fe861SBrian Somers    bind .$n.value <Return> {done};
671d8fe861SBrian Somers  } else {
681d8fe861SBrian Somers    .$n.value configure -state disabled;
691d8fe861SBrian Somers  }
701d8fe861SBrian Somers  pack .$n -side top -padx $fxpad -pady $fypad;
711d8fe861SBrian Somers}
721d8fe861SBrian Somers
731d8fe861SBrian Somers# Dump our fields to stdout and exit
741d8fe861SBrian Somersproc done {} {
751d8fe861SBrian Somers  puts [.n.value get 1.0 {end - 1 char}];
761d8fe861SBrian Somers  puts [.k.value get];
771d8fe861SBrian Somers  exit 0;
781d8fe861SBrian Somers}
791d8fe861SBrian Somers
801d8fe861SBrian Somersmkframe h "Hostname:" $hostname 0;
811d8fe861SBrian Somersmkframe c "Challenge:" $challenge 0;
821d8fe861SBrian Somersmkframe n "Authname:" $authname 1;
831d8fe861SBrian Somers
841d8fe861SBrian Somersmkhalfframe k "Authkey:";
851d8fe861SBrian Somersentry .k.value -show "*" -width $vwidth;
861d8fe861SBrian Somerspack  .k.value -side right;
871d8fe861SBrian Somersbind  .k.value <Return> {done};
881d8fe861SBrian Somersfocus .k.value;
891d8fe861SBrian Somerspack  .k -side top -padx $fxpad -pady $fypad;
901d8fe861SBrian Somers
911d8fe861SBrian Somersframe  .b;
921d8fe861SBrian Somersbutton .b.ok -default active -text "Ok" -command {done};
931d8fe861SBrian Somerspack   .b.ok -side left;
941d8fe861SBrian Somersbutton .b.cancel -default normal -text "Cancel" -command {exit 1};
951d8fe861SBrian Somerspack   .b.cancel -side right;
961d8fe861SBrian Somerspack   .b -side top -padx $fxpad -pady $fypad;
97