📄 amsn-remote
字号:
#!/usr/bin/wish###### Remote controller program###set initialize_amsn 1proc readsocket { } { global sock if { [gets $sock response] == -1 } { .controler.res.txt insert end "Amsn server closed\n" error .controler.res.txt yview moveto 1.0 destroy .controler connect "Amsn server closed" } elseif { $response != "" } {# puts "$response" set response [string map { \; \\\; \" \\\" \[ \\\[ \] \\\] \: \\\: \\ \\\\ \* \\\* \? \\\?} $response] set colour [lindex "$response" end] set response [string map [list "$colour" ""] $response] set response [string map { \\\\ "^[SLASHCAR]^"} $response] set response [string map { \\ ""} $response] set response [string map { "^[SLASHCAR]^" \\} $response] .controler.res.txt insert end "$response \n" $colour .controler.res.txt yview moveto 1.0 } }proc writesocket { } { global sock set command [.controler.entry get] .controler.entry delete 0 end .controler.res.txt insert end "\n$command\n" command .controler.res.txt yview moveto 1.0 set command [string map { \; \\\; \" \\\" \[ \\\[ \] \\\] \: \\\: \\ \\\\ \* \\\* \? \\\?} $command] # set command [join $command] if { "$command" != "quit" } { puts ${sock} "$command" flush $sock } else { destroy .controler }}proc authenticate { password } { global sock puts ${sock} "auth" flush $sock gets $sock response if { "[lindex $response 0]" != "auth" } { return "fail" } else { set hash [::md5::hmac "[lindex $response 1]" "$password"] puts $sock "auth2 $hash" flush $sock gets $sock response if { "$response" == "Authentication successfull normal" } { return "OK" } elseif { "$response" == "Authentication failed normal" } { return "fail" } else { return "disabled" } }}proc connect { status } { global sockDS stat set ip [.ip get] if { [catch {toplevel .connect}] } { destroy .connect toplevel .connect } wm group .connect . if { $sockDS == 0 } { set stat [catch {socket $ip 63251} sockDS] set status "Connected to the server" } if { $stat != 0 } { label .connect.status -text "Error connecting to server\n$sockDS" button .connect.ok -text "OK" -command "destroy .connect" set sockDS 0 grid .connect.status -row 0 -column 0 grid .connect.ok -row 2 -column 1 bind .connect <Destroy> "grab release .connect" grab set .connect } else { label .connect.status -text "$status" button .connect.ok -text "Connect to account" -command "retreive_port $ip" label .connect.acc_l -text "Account :" entry .connect.acc label .connect.pass_l -text "Password for remote access :" entry .connect.pass -show "*" button .connect.cancel -text "Cancel" -command "close $sockDS;set sockDS 0; destroy .connect" grid .connect.status -row 0 -column 2 grid .connect.ok -row 2 -column 3 grid .connect.cancel -row 3 -column 3 grid .connect.acc_l -row 2 -column 0 grid .connect.acc -row 2 -column 2 grid .connect.pass_l -row 3 -column 0 grid .connect.pass -row 3 -column 2 bind .connect <Destroy> { if {"%W" == ".connect"} { grab release .connect } } bind .connect.acc <Return> "retreive_port $ip" bind .connect.pass <Return> "retreive_port $ip" grab set .connect focus -force .connect.acc }}proc retreive_port { ip } { global sockDS sock set account [.connect.acc get] set password [.connect.pass get] puts $sockDS "$account" if { [catch { flush $sockDS}] } { set sockDS 0 connect "Disconnected from the DS server" return 0 } set port [gets $sockDS] if { "$port" == "invalid" } { connect "This Amsn Account is invalid" return 0 } if { "$port" == "noexist" } { connect "The Amsn profile file doesn't exist or you don't have permissions to read from it" return 0 } if { "$port" == "versionerror" } { connect "The Amsn profile file has an invalid version" return 0 } if { [catch {socket $ip $port} sock] != 0 } { connect "This Amsn Account isn't connected" return 0 } else { fconfigure $sock -buffering line if { [set auth_response [authenticate "$password"]] == "fail" } { connect "Password incorrect or not set" return 0 } elseif { $auth_response == "disabled" } { connect "This account doesn't have remote controlling enabled" return 0 } else { fileevent $sock readable "readsocket" connect "Connected to Account on port : $port" after 500 control return 1 } }}proc control { } { global sock toplevel .controler wm group .controler . wm title .controler "Remote Controler Shell" frame .controler.res -class Degt text .controler.res.txt -height 40 -width 120 \ -wrap none -background white -foreground black \ -yscrollcommand ".controler.res.sy set" \ -xscrollcommand ".controler.res.sx set" scrollbar .controler.res.sy -command ".controler.res.txt yview" scrollbar .controler.res.sx -orient horizontal -command ".controler.res.txt xview" .controler.res.txt tag configure error -foreground #ff0000 -background white .controler.res.txt tag configure command -foreground #888888 -background white .controler.res.txt tag configure normal -foreground #000000 -background white .controler.res.txt tag configure msgsent -foreground #ff8800 -background white .controler.res.txt tag configure msgrcv -foreground blue -background white pack .controler.res.sy -side right -fill y pack .controler.res.sx -side bottom -fill x pack .controler.res.txt -anchor nw -expand true -fill both entry .controler.entry -width 50 button .controler.close -text "Close" -command "destroy .controler" pack .controler.res -expand true -fill both pack .controler.entry -fill x pack .controler.res .controler.entry -side top bind .controler.entry <Return> "writesocket" grab set .controler bind .controler <Destroy> { if { "%W" == ".controler" } { close $sock grab release .controler } } focus -force .controler.entry}proc main { } { global sockDS wm group . . wm geometry . wm title . "Amsn Remote Controller" button .con -text "Connect" -command "connect \"Connected to the server\"" label .lab -text "Enter the IP address of the host : " entry .ip grid .lab -row 0 -column 0 grid .ip -row 0 -column 2 grid .con -row 0 -column 10 -sticky w bind .ip <Return> "connect \"Connected to the server\"" focus -force .ip}############################################################### Look if we are launched from a link### and set the correct working directory#############################################################Fixed by Tomasz Nguyenset program_dir [file dirname [info script]]set program [file tail [info script]]while {[catch {file readlink [file join $program_dir $program]} program]== 0} { if {[file pathtype $program] == "absolute"} { set program_dir [file dirname $program] } else { set program_dir [file join $program_dir [file dirname $program]] } set program [file tail $program]}set starting_dir [pwd]cd $program_dirset program_dir [pwd]unset program#unset program_dirsource [file join $program_dir migmd5.tcl]set sockDS 0main
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -