テキストを直接編集しないログインマクロ
.TTL
;
;2025/07/12 04:31
;
; ファイルを直接編集しないマクロにしたい
; 接続情報の追加
; 接続情報の削除
; メニューリストの自動生成
; history保存->まだ
;
; メニューリスト用接続情報のファイル
; data.datに入る情報
; 接続名の一覧(indexkeyliststr)=indexkey;
; ログイン情報=USER;ADDR;PORT;LOGINPASS;KEYFILE;CHALLENGE;OPTION
; -----------------------------------------------
; indexkey=indexkeyliststr-> _;taro;hana;shiba;
; indexkey=taro-> usr1;1.2.3.4;22;passwd;;;
; indexkey=hana-> usr2;5.6.7.8;22;;C:\Users\hana\document\key;;
; indexkey=shiba-> usr3;5.3.2.8;22;passwd;;1;
; -----------------------------------------------
;
;======================================================================
;=== バージョン5.3以降対応
;======================================================================
getver version '5.3'
if result<0 then
messagebox 'バージョン5.3以降対応' ''
end
endif
;======================================================================
;=== init
;======================================================================
regex='<semicolon>'
indexkeyliststr='_;'
datafile='macrodata.dat'
getdir dir
init=0
passwordbox '起動パスワード' ''
cryptpass=inputstr
indexkey='indexkeylist'
ispassword2 datafile indexkey
if !result then
inputbox 'もう一度パスワードを入力してください' '初期設定'
strcompare cryptpass inputstr
if result!=0 then
messagebox 'パスワードが一致しません' ''
end
endif
setpassword2 datafile indexkey indexkeyliststr cryptpass
endif
getpassword2 datafile indexkey indexkeyliststr cryptpass
if !result then
messagebox 'パスワードが一致しません' ''
end
endif
;======================================================================
;=== メニュー操作
;======================================================================
while 1
call mkmenu
listbox 'comment' 'title' menulistary
if result=0 then
call add
elseif result=1 then
call delete
elseif result=2 then
call portforward
elseif result=-1 then
break
else
indexkey=menulistary[result]
call descrypt
call mkcmd
connect cmd
unlink
endif
endwhile
end
;======================================================================
;=== メニューボックス作成
;======================================================================
:mkmenu
;メニュー項目数のカウント
count=3 ;add,del,pf
tmp=indexkeyliststr
strreplace tmp 1 ';' '' ;indexkeylist初期設定の'_'をパス
while 1
strreplace tmp 1 ';' ''
if result<1 break
count=count+1
endwhile
if init=0 then
;配列menulistary作成
strdim menulistary count
menulistary[0]='<>add'
menulistary[1]='<>del'
menulistary[2]='<>portforward'
;削除,pfリスト用
strdim indexlistary count
indexlistary[0]='---'
indexlistary[1]='---'
indexlistary[2]='---'
init=1
endif
;listboxの作成
if count>3 then ;0add,1del,2pf
i=3 ;menuのadd,del,pf用予約
j=2 ;indexkeylist初期設定の'_'をパス
strsplit indexkeyliststr ';' 9
while 1
sprintf2 ttlcmd 'menulistary[%d]=groupmatchstr%d' i j
execcmnd ttlcmd
sprintf2 ttlcmd 'indexlistary[%d]=groupmatchstr%d' i j
execcmnd ttlcmd
if j=9 then
indexkeyliststr=groupmatchstr9
strsplit indexkeyliststr ';' 9
j=1
else
i=i+1
j=j+1
endif
if i=count then
break
endif
endwhile
endif
return
;======================================================================
;=== mkcmdのサブルーチン
;======================================================================
:mkcmd
strlen KEYFILE
if result>0 then
sprintf2 cmd '%s:%s /ssh /2 /auth=publickey /user=%s /keyfile="%s"' ADDR PORT USER KEYFILE
elseif CHALLENGE then
sprintf2 cmd '%s:%s /ssh /2 /auth=challenge /user=%s /passwd="%s"' ADDR PORT USER LOGINPASS
else
sprintf2 cmd '%s:%s /ssh /2 /auth=password /user=%s /passwd="%s"' ADDR PORT USER LOGINPASS
endif
return
;======================================================================
;=== descryptのサブルーチン
;======================================================================
:descrypt
getpassword2 datafile indexkey decrypt cryptpass
strsplit decrypt ';' 6
USER=groupmatchstr1
ADDR=groupmatchstr2
PORT=groupmatchstr3
LOGINPASS=groupmatchstr4
KEYFILE=groupmatchstr5
str2int CHALLENGE groupmatchstr6
retxt=USER
call alt2semi
USER=retxt
retxt=LOGINPASS
call alt2semi
LOGINPASS=retxt
OPTION=groupmatchstr7
return
;======================================================================
;=== addのサブルーチン
;======================================================================
:add
inputbox '識別名' 'add'
indexkey=inputstr
tmp1=indexkeyliststr
sprintf2 tmp2 ';%s;' indexkey
strreplace tmp1 1 tmp2 ''
if result=1 then
messagebox '既に存在します' 'add'
elseif result=0 then
title='add'
call inputdata
yesnobox inputdatastr 'OK?'
if !result return
sprintf2 indexkeyliststr '%s%s;' indexkeyliststr indexkey
setpassword2 datafile indexkey inputdatastr cryptpass
indexkey='indexkeylist'
setpassword2 datafile indexkey indexkeyliststr cryptpass
messagebox 'マクロを再起動してください' ''
end
else
messagebox tmp1 result
endif
return
;======================================================================
;=== inputdataのサブルーチン
;======================================================================
:inputdata
inputbox 'USER' title
retxt=inputstr
call semi2alt
USER=retxt
inputbox 'ADDR' title
ADDR=inputstr
inputbox 'PORT' title '22'
PORT=inputstr
inputbox 'LOGINPASS' title
retxt=inputstr
call semi2alt
LOGINPASS=retxt
filenamebox 'KEYFILE'
KEYFILE=inputstr
yesnobox 'CHALLENGE' title
CHALLENGE=result
inputbox 'OPTION' title
retxt=inputstr
call semi2alt
OPTION=retxt
sprintf2 inputdatastr '%s;%s;%s;%s;%s;%i;%s' USER ADDR PORT LOGINPASS KEYFILE CHALLENGE OPTION
return
;======================================================================
;=== deleteのサブルーチン
;======================================================================
:delete
title='delete'
comment=''
call selectindex
strlen indexkey
if !result return
sprintf2 delindex '%s;' indexkey
yesnobox delindex 'OK?'
if !result return
delpassword2 datafile indexkey
indexkey='indexkeylist'
strreplace indexkeyliststr 1 delindex ''
setpassword2 datafile indexkey indexkeyliststr cryptpass
messagebox 'マクロを再起動してください' ''
end
;======================================================================
;=== portforwardのサブルーチン
;======================================================================
:portforward
comment=''
title='portforward - fumidai'
call selectindex
strlen indexkey
if !result return
call descrypt
call mkcmd
title='portforward - access'
call inputdata
sprintf2 cmd '%s /ssh-L15000:%s:%s' cmd ADDR PORT
connect cmd
unlink
ADDR='localhost'
PORT='15000'
call mkcmd
connect cmd
unlink
return
;======================================================================
;=== selectindexのサブルーチン
;======================================================================
:selectindex
indexkey=''
while 1
listbox comment title indexlistary
if result<0 break
if result<3 continue
indexkey=indexlistary[result]
break
endwhile
return
;======================================================================
;=== 入力データの';'を置換するサブルーチン
;======================================================================
:alt2semi
while 1
strreplace retxt 1 regex ';'
if result<1 break
endwhile
return
:semi2alt
while 1
strreplace retxt 1 ';' regex
if result<1 break
endwhile
return
;======================================================================
;=== コンソールへコメント表示
;======================================================================
:outputdisp
; 一度画面をクリア。カーソルを左端へ
dispstr #$1B"[2J"
dispstr #$0D
dispstr dispcomment#$0A#$0D
dispstr #$0A
; コンソール改行
sendln
return
テキストを直接編集するほうのログインマクロ
.TTL
;name,user,ip,passwd,key
name=''
user=''
ip=''
passwd=''
key=''
keyfile=''
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
cmd=hostname
strconcat cmd ':22 /ssh /auth=publickey /user='
strconcat cmd username
strconcat cmd ' /keyfile='
strconcat cmd keyfile
connect cmd
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
cmd=hostname
strconcat cmd ':22 /ssh /auth=publickey /user='
strconcat cmd username
strconcat cmd ' /keyfile='
strconcat cmd keyfile
strconcat cmd ' /passwd="'
strconcat cmd pass
strconcat cmd '"'
connect cmd
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
cmd=hostname
strconcat cmd ':22 /ssh /auth=password /user='
strconcat cmd username
strconcat cmd ' /passwd="'
strconcat cmd pass
strconcat cmd '"'
connect cmd