CHAT (接続) スクリプトは、リンク確立フェーズのときに、各エンドポイント間の情報交換を定義します。デフォルトでは、CHAT スクリプトはディレクトリ /etc/opt/SUNWconn/ppp/script に存在します。ファイル link.conf にある位置定義を編集してファイルを移動することによって、スクリプトの位置を変更することができます。
ローカルホストからの発信先の各リモートホストに、CHAT スクリプトを 1 つ作成する必要があります。CHAT スクリプトには、リモートマシン上のユーザーアカウントを示す一意のログイン識別子を定義します。リモートホストが Solstice PPP を実装している場合、そのログイン識別子は、パラメータ expect_login_id の値としても定義されている必要があります。このパラメータは、マシン上のファイル ppp.conf のダイヤルアップパスのいずれかと関連付けられています。
CHAT スクリプトには、非対話型 (交換すべき情報すべてがスクリプトにある) と対話型 (スクリプトがユーザー入力をプロンプトする) の 2 種類があります。
以下は、Solaris オペレーティングシステムを実装するリモートホストにログインするための簡単な CHAT スクリプトです。この例は、Solstice PPP に添付されている CHAT テンプレートスクリプトをもとに作成されています。
# Chat script for ppp login # # Set the line regarding the remote site configuration # Due to UUCP limitations some systems only accept cs7 # setline cs7 parodd # Start dialog with the remote host send RETURN # Set expected response, retry 3 times at 10 second intervals expect "ogin:" 10 onerror send BREAK repeat 3 # Set login id sent to remote host send "ppp1" # Set response expected from remote host expect "word: " 40 # Set the login password sent to the remote host send "okppp1" |
ログイン識別子とログインパスワードは、リモートホストにおけるログインシーケンスで使用されます。このシーケンスとログインダイアログにおける制限は、オペレーティングシステムによって異なります。
リモートホストが Solaris 環境を実装している場合は、ログイン識別子は 1 〜 8 文字の小文字である必要があります。ログインパスワードには、大文字と小文字の両方を使用することができます。パスワードのサイズは 6 文字以上ですが、最初の 6 文字だけが認識されます。
呼を受信するには、ログイン識別子とログインパスワードを持つユーザーアカウントがリモートホスト上に必要です。リモートホストが Solstice PPP を実装している場合は、ファイル ppp.conf に定義されているダイヤルアップパスのいずれかの expect_login_id パラメータの値としてログイン識別子が定義されている必要があります。
デフォルト CHAT スクリプトを編集して、ログイン識別子とログインパスワードをリモートホストが要求する文字列と置き換えます。以下の CHAT スクリプト例では、ログイン識別子 mylogin とログインパスワード mypasswd を使用してリンクを確立します。
# Chat script for ppp login # # Set the line regarding the remote site configuration # Due to UUCP limitations some systems only accept cs7 # setline cs7 parodd # Start dialog with the remote host send RETURN # Set expected response, retry 3 times at 10 second intervals expect "ogin:" 10 onerror send BREAK repeat 3 # Set login id (mylogin) sent to remote host send "mylogin" # Set response expected from remote host, wait up to 40 seconds expect "word: " 40 # # Set the login password (my passwd) of the remote host send "mypasswd" |
ローカルホストが発信を行うと、ログインシーケンスを開始する前にリモートホストの応答が待機されます。ローカルホストの待機時間とローカルホストの発信試行数は、以下のエントリによって定義されます。
expect "ogin:" 10 onerror send BREAK repeat 3 |
最初の数字 10 は待機時間、2 番目の数字 3 は発信試行数を示します。これらのパラメータは、いずれも変更可能です。
たとえば、5 秒ごとに 10 回発信試行するには、以下のようにエントリを変更します。
expect "ogin:" 5 onerror send BREAK repeat 10 |
デフォルトの CHAT スクリプトでは、2 つの Solaris システム間でリンクを確立すると仮定します。Solaris 以外のオペレーティングシステムを使用しているマシンと接続するには、ログインダイアログを変更する必要がある場合があります。
たとえば、PPP を実装している OpenVMS システムと接続するには、以下のように接続スクリプトを変更します。
send RETURN # Change "ogin:" to "name:" for OpenVMS expect "name:" 10 onerror send BREAK repeat 3 send "ppp" expect "word:" 40 # # Set the ppp password of the remote host here # send "xxxxx" |
CHAT テンプレートスクリプトは、単純な方法によってリモートホストにログインします。CHAT スクリプトを変更し拡張して、より複雑なログインダイアログを作成することができます。ただし、Solstice PPP を実装するリモートホストへの接続を開始するには、リモートホストが認識するログイン識別子を定義し、Solstice PPP ログインサービスを起動する手段を用意する必要があります。
次に示す CHAT スクリプト例は、Solaris 環境を実装するリモートホストにログインし、動作が正常終了したことを示す電子メールメッセージを mailx(1) を起動して送信し、Solstice PPP ログインサービスを起動します。この場合は、スクリプトが送信するログイン識別子に該当するリモートホスト上のユーザーアカウントは、デフォルトシェルとして /usr/bin/csh を使用する必要があります。
# Chat script to invoke mailx on remote # # Set the line regarding the remote site configuration # Due to UUCP limitations some systems only accept cs7 # setline cs7 parodd # Start dialog with the remote host send RETURN # Set expected response, retry 3 times at 10 second intervals expect "ogin:" 10 onerror send BREAK repeat 3 # Set login id (mylogin) sent to remote host send "mylogin" # Set response expected from remote host, wait up to 40 seconds expect "word: " 40 # # Set the login password (my passwd) of the remote host send "mypasswd" # Set response expected from remote host (C-shell prompt) expect "%" # Set command sent to invoke mailx send "echo Login to remote successful | /usr/bin/mailx alias" # Set response expected from remote host (C-shell prompt) expect "%" # Start PPP login service (pppls) on remote send "/usr/sbin/pppls" |
以下の CHAT スクリプトは、telnet ターミナルサーバーへのログインを行います。
# Chat script to login to telnet server # # Set the line regarding the remote site configuration # Due to UUCP limitations some systems only accept cs7 # setline cs7 parodd send RETURN expect "sername:" 10 onerror send RETURN repeat 5 send "your_username" expect "assword:" 35 send "your_password" expect "pc>" 10 onerror send RETURN repeat 2 send "terminal flowcontrol hardware" expect "pc>" 10 onerror send RETURN repeat 2 send "terminal databits 8" expect "pc>" 10 onerror send RETURN repeat 2 send "terminal parity none" expect "pc>" 10 onerror send RETURN repeat 2 send "terminal escape-character 0" expect "pc>" 10 onerror send RETURN repeat 2 send "terminal telnet-transparent" expect "pc>" 10 onerror send RETURN repeat 2 send "telnet your_own_machine" expect "ogin:" onerror send RETURN repeat 5 send "your_login_for_PPP" expect "assword:" 35 send "your_password _for_PPP" |
対話型 CHAT スクリプトでは、echo と read のキーワードを使用して、プロンプトの表示とユーザー入力の取得を行います。ユーザー入力は、接頭辞 $ によって識別される変数として格納されます。以下は、前項で紹介したスクリプトの対話型バージョンの例です。
# Interactive Chat Script Example 1 # # Set the line regarding the remote site configuration # Due to UUCP limitations some systems only accept cs7 # setline cs7 parodd send RETURN expect "ogin:" 10 onerror send BREAK repeat 3 # Display prompt for login id echo "Enter your PPP login id: " # Read the login id from standard input and store in $login read $login # Send the login id to the remote host send "$login" # Set expected response, wait up to 40 seconds expect "word: " 40 # Display prompt for password echo "Enter your PPP password: " # Read the password from standard input and store in $password read $password # Send the password to the remote host send "$password" |
次の例は、ユーザーと動的チャレンジ応答認証システムの対話を管理する、より複雑な CHAT スクリプトです。
# Interactive Chat Script Example 2 # # Set the line regarding the remote site configuration # Due to UUCP limitations some systems only accept cs7 # setline cs7 parodd send RETURN expect "ID:" 10 onerror send BREAK repeat 3 # Display prompt for user number id echo "Enter your user ID number: " # Read the user number id from standard input and store in $id read $id # Send the user number id to the remote host send "$id" # Set expected response, wait up to 10 seconds # Receive the 6 character challenge code expect "Challenge: ${challenge,6}" 10 # Display prompt for the challenge response echo "Enter the response for Challenge ${challenge}: " # Read the user number id from standard input # and store in $response read $response # Send the challenge response to the remote host send "$response" # Set expected response, wait up to 20 seconds expect "${host}:" 20 # Display status and name of remote host on successful connection echo "Connected to ${host}¥n" # Start dialog with remote PPP send "ppp" |
この例では、スクリプトはユーザー識別子を読み取ってサーバーに送信します。文字列 Challenge: で始まるサーバーの応答が 10 秒間待機され、チャレンジ値の次の 6 文字を読み取ります。
次に、スクリプトはチャレンジ値を表示し、ユーザーの応答を待機し、この応答をサーバーに送信します。応答が受け付けられると、接続が確立されます。
中括弧 ({}) は、文字列の一部として他の文字とともに示される変数を区切るために使用します。
BNF を使用して記述する CHAT スクリプトの構文は、次のとおりです。
<chat_script> ::= <script_cmd> | <chat_script> <script_cmd> <script_cmd> ::= <send_cmd> | <expect_cmd> | <echo_cmd> | <read_cmd> <send_cmd> ::= "send" <quoted_string> | "send RETURN" | "send BREAK" <expect_cmd> ::= "expect" <quoted_string> <number> <expect_error> <expect_error> ::= "" | "onerror" <send_repeat> <send_repeat> ::= <send_cmd> <repeat> | <send_cmd> | <repeat> <repeat> ::= "repeat" <number> | "repeat" <echo_cmd> ::= "echo" <quoted_string> <read_cmd> ::= "read" <string> <quoted_string> ::= "((<string>|<number>)[ ]*)+" <string> ::= ([a-zA-Z/_-&.%#@‾+*¥(){}$;:?><!]+[0-9"']*)+ <number> ::= ([0-9,@*#$]*.)?[0-9,@*#$]+ |