テキストを直接編集しないログインマクロ
;
; ファイルを直接編集しないマクロにしたい
; 接続情報の追加
; 接続情報の削除
; メニューリストの自動生成
; add,del後のメニューリストの再生成->まだ
;
; メニューリスト用接続情報のファイル
; data.datに入る情報
; 接続名の一覧(userliststr)=indexkey;
; ログイン情報=USER;ADDR;LOGINPASS;KEYFILE;CHALLENGE
; -----------------------------------------------
; indexkey=userliststr-> _;taro;hana;shiba;
; indexkey=taro-> usr1;1.2.3.4;passwd;;
; indexkey=hana-> usr2;5.6.7.8;;C:\Users\hana\document\key;
; indexkey=shiba-> usr3;5.3.2.8;passwd;;1
; -----------------------------------------------
;
;======================================================================
;=== バージョン5.3以降対応
;======================================================================
getver version '5.3'
if result<0 then
messagebox 'バージョン5.3以降対応' ''
end
endif
;======================================================================
;=== init
;======================================================================
regex='<semicolon>'
userliststr='_;'
datafile='data.dat'
inputbox '起動パスワード' ''
cryptpass=inputstr
indexkey='userlist'
ispassword2 datafile indexkey
if !result then
inputbox 'もう一度パスワードを入力してください' '初期設定'
strcompare cryptpass inputstr
if result!=0 then
messagebox 'パスワードが一致しません' ''
end
endif
indexkey='userlist'
setpassword2 datafile indexkey userliststr cryptpass
endif
getpassword2 datafile indexkey userliststr cryptpass
if !result then
messagebox 'パスワードが一致しません' ''
end
endif
;======================================================================
;=== メニュー表示
;======================================================================
call mkmenu
while 1
listbox 'txt' 'title' menulistary
if result=0 then
call add
elseif result=1 then
call delete
elseif result<2 then
break
else
indexkey=menulistary[result]
getpassword2 datafile indexkey decrypt cryptpass
strsplit decrypt ';'
USER=groupmatchstr1
ADDR=groupmatchstr2
LOGINPASS=groupmatchstr3
KEYFILE=groupmatchstr4
str2int CHALLENGE groupmatchstr5
retxt=USER
call alt2semi
USER=retxt
retxt=LOGINPASS
call alt2semi
LOGINPASS=retxt
strlen KEYFILE
if result>0 then
sprintf2 cmd '%s:22 /ssh /2 /auth=publickey /user=%s /keyfile=%s' ADDR USER KEYFILE
elseif CHALLENGE then
sprintf2 cmd '%s:22 /ssh /2 /auth=challenge /user=%s /passwd="%s"' ADDR USER LOGINPASS
else
sprintf2 cmd '%s:22 /ssh /2 /auth=password /user=%s /passwd="%s"' ADDR USER LOGINPASS
endif
connect cmd
endif
endwhile
end
;======================================================================
;=== メニューボックス作成
;======================================================================
:mkmenu
;メニュー項目数のカウント
count=1
tmp=userliststr
while 1
strreplace tmp 1 ';' ''
if result<1 break
count=count+1
endwhile
;配列menulistary作成
strdim menulistary count
menulistary[0]='追加'
menulistary[1]='削除'
;削除リスト用
strdim dellistary count
dellistary[0]='---'
dellistary[1]='---'
;listboxの作成
if count>2 then
i=2
j=2
strsplit userliststr ';' 9
while 1
sprintf2 ttlcmd 'menulistary[%d]=groupmatchstr%d' i j
execcmnd ttlcmd
sprintf2 ttlcmd 'dellistary[%d]=groupmatchstr%d' i j
execcmnd ttlcmd
if j=9 then
userliststr=groupmatchstr9
strsplit userliststr ';' 9
j=1
else
i=i+1
j=j+1
endif
if i=count then
break
endif
endwhile
endif
return
;======================================================================
;=== addのサブルーチン
;======================================================================
:add
inputbox '識別名' 'add'
indexkey=inputstr
strscan userliststr indexkey
if result!=0 then
messagebox '既に存在します' 'add'
else
inputbox 'USER' 'add'
retxt=inputstr
call semi2alt
USER=retxt
inputbox 'ADDR' 'add'
ADDR=inputstr
inputbox 'LOGINPASS' 'add'
retxt=inputstr
call semi2alt
LOGINPASS=retxt
filenamebox 'KEYFILE'
KEYFILE=inputstr
yesnobox 'CHALLENGE' 'add'
CHALLENGE=result
sprintf2 userliststr '%s%s;' userliststr indexkey
sprintf2 cryptstr '%s;%s;%s;%s;%i' USER ADDR LOGINPASS KEYFILE CHALLENGE
;リトライ
yesnobox cryptstr 'OK?'
if !result call add
setpassword2 datafile indexkey cryptstr cryptpass
indexkey='userlist'
setpassword2 datafile indexkey userliststr cryptpass
endif
return
;======================================================================
;=== deleteのサブルーチン
;======================================================================
:delete
while 1
listbox 'txt' 'delete' dellistary
if result<0 break
if result<2 continue
indexkey=dellistary[result]
sprintf2 delindex '%s;' indexkey
delpassword2 datafile indexkey
indexkey='userlist'
strreplace userliststr 1 delindex ''
setpassword2 datafile indexkey userliststr cryptpass
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
テキストを直接編集するほうのログインマクロ
;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