Leask's profile#import "Leask.h"BlogListsGuestbook Tools Help

Blog


    天朝春色关我不住,一段代码让我出墙来(Flora_ssh-D 1.73隆重发布!)

    Flora_ssh-D 1.73已经不单单是翻墙脚本了,目前我计划把Flora_ssh-D发展成一个自动化的助理,让你的电脑用得更舒心。

    目前的功能如下:

    1. 自动检查网络状态,根据在线和离线的状态为你开启和关闭软件;
    2. 自动检查ssh -D的连接状态,如果断开了会为你自动连接,连接失败将提示自动重连,使用后墙对你来说基本上是透明的;
    3. VoiceOver语音功能,这个功能和iPod一样,你的iTunes在播放的时候能够语音提示你正在播放的歌名和艺术家名字;
    4. 语音提醒功能的改进,当需要语音提示用户操作的时候,如果你的iTunes正在播放,将自动降低你的iTunes音量,在语音提示结束后还原音量;
    5. 使用API自动将你正在收听的音乐记录到Last.fm,你已经不再需要额外的iTunes插件来记录了;
    6. 使用API自动更新你在DNS-O-MATIC上的动态IP,你不再需要其他额外的软件更新动态IP了;
    7. 新版本使用新的idle时间管理,对比上一个版本有很大的效能提升,后台的常驻几乎不占用任何资源。

    Google Code上下载地址如下:http://code.google.com/p/flora-ssh-d/downloads/list (包含源代码)
    // PS: 使用翻墙功能你需要先有SSH帐号,使用其他功能则不需要。

    源代码如下:

    (* Flora_ssh-D // Version 1.73 // Code by Leask Huang // www.leaskh.com // i@leaskh.com *)

    (* ======= Variable Declaration ======= *)
    global timeTry
    global DNSResponse
    global isOLast
    global iTsCurDBID
    global iTsORSoundVolume
    global strSNGArtist
    global strSNGName
    global strSNGAlbum
    global strSNGTrackNumber
    global strSNGDuration

    (* ======= General Settings ======= *)
    (* Custom these before you run this script *)
    property SSHServerName : "***.*******.com" -- Set ssh -D ServerName (or leave it blank)
    property SSHUserName : "*******" -- Set UserName (or leave it blank)
    property SSHPasswd : "*******" -- Set Password (or leave it blank)
    property TwitterUsername : "*******" -- If you don't want to update Twitter status, leave it blank
    property TwitterPassword : "*******" -- same as above
    property TwitterText : "@" & TwitterUsername & " is online now! // " & (current date) -- same as above
    property DNSUsername : "*******" -- Set DNS UserName (or leave it blank)
    property DNSPassword : "*******" -- Set Password (or leave it blank)
    property LastfmUsername : "*******" -- Set Last.fm UserName (or leave it blank)
    property LastfmPassword : "*******" -- Set Password (or leave it blank)
    property appStList : {"***", "***"} -- these aplications will launch while you are online (or leave it blank)
    property appQuitList : {"***", "***"} -- these aplications will quit while you are offline (or leave it blank)

    (* ======= Main Script ======= *)
    on run
        set isOLast to ""
        set iTsCurDBID to ""
    end run

    on quit
        continue quit
    end quit

    on idle
        if fnCheckNet() is true then
            fnSSHCnt()
            if isOLast is not "online" then
                fnAppStart()
                fnDNSUpdate()
                fnTwitter()
            end if
            fnLastfm()
            set isOLast to "online"
        else
            if isOLast is not "offline" then fnAppQuit()
            set isOLast to "offline"
        end if
        return 180
    end idle

    (* ======= Functions ======= *)
    to fnCheckNet()
        try
            do shell script "curl --connect-timeout 33 \"apple.com/favicon.ico\""
            if isOLast is not "online" then SmartSay("Online")
            return true
        on error
            if isOLast is not "offline" then SmartSay("Offline")
            return false
        end try
    end fnCheckNet

    to fnAppStart()
        if (count appStList) > 0 then
            SmartSay("Start Apps")
            try
                repeat with intSti from 1 to (count appStList)
                    tell application (item intSti of appStList) to activate
                end repeat
                SmartSay("OK")
            on error
                SmartSay("Failed")
            end try
        end if
    end fnAppStart

    to fnAppQuit()
        if (count appQuitList) > 0 then
            SmartSay("Quit Applications")
            try
                repeat with intSti from 1 to count appQuitList
                    tell application (item intSti of appQuitList) to quit
                end repeat
                SmartSay("OK")
            on error
                SmartSay("Failed")
            end try
        end if
    end fnAppQuit

    to fnSSHCnt()
        if (length of SSHServerName) > 0 and (length of SSHUserName) > 0 and (length of SSHPasswd) > 0 then
            set timeTry to 0
            repeat while fnCheckSSHD() is false
                SmartSay("Connect SSH D")
                if timeTry > 0 then if (button returned of (display dialog "ssh -D connection failed." & return & "" buttons {"Retry", "Ignore"})) is "Ignore" then exit repeat
                fnShellSSH()
                set timeTry to timeTry + 1
            end repeat
        end if
    end fnSSHCnt

    to fnCheckSSHD()
        try
            do shell script "curl --socks5 127.0.0.1:7070 --connect-timeout 33 \"apple.com/favicon.ico\""
            if timeTry > 0 then SmartSay("OK")
            return true
        on error
            if timeTry > 0 then SmartSay("Failed")
            return false
        end try
    end fnCheckSSHD

    to fnShellSSH()
        try
            tell application "Terminal"
                quit
                delay 1
                activate
                delay 1
                do script "rm ~/Downloads/.Flora_ssh-D.out" in window 1
                do script "killall ssh" in window 1
                do script "killall ssh-agent" in window 1
                do script "nohup ssh -D 7070 " & SSHUserName & "@" & SSHServerName & " > Downloads/.Flora_ssh-D.out" in window 1
            end tell
            SmartSay("SSH D connection request and log in request have been sent. Waiting for response from remote server.")
            tell application "Terminal"
                do script SSHPasswd in window 1
                delay 1
                quit
            end tell
        end try
    end fnShellSSH

    to fnTwitter()
        if (length of TwitterUsername) > 0 and (length of TwitterPassword) > 0 and (length of TwitterText) > 0 then
            SmartSay("Update Twitter state")
            try
                do shell script "curl --connect-timeout 33  --user " & (quoted form of (TwitterUsername & ":" & TwitterPassword)) & " --data-binary " & (quoted form of ("status=" & TwitterText)) & " \"https://twitter.com/statuses/update.json\""
                SmartSay("OK")
            on error
                SmartSay("Failed")
            end try
        end if
    end fnTwitter

    to fnDNSShell()
        try
            set DNSResponse to (do shell script "curl --connect-timeout 33 \"https://" & DNSUsername & ":" & DNSPassword & "@updates.dnsomatic.com/nic/update?&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG\"")
            if first word of DNSResponse is "good" then -- (second word of DNSResponse) is IP address
                return true
            else
                return false
            end if
        on error
            return false
        end try
    end fnDNSShell

    to fnDNSUpdate()
        if (length of DNSUsername) > 0 and (length of DNSPassword) > 0 then
            SmartSay("Update dynamic IP")
            if fnDNSShell() is true then
                SmartSay("OK")
            else
                SmartSay("Failed")
            end if
        end if
    end fnDNSUpdate

    to fnURLec(strToUEC)
        return do shell script "python -c 'import sys, urllib; print urllib.quote(sys.argv[1])' \"" & strToUEC & "\""
    end fnURLec

    to fniTunesisActive()
        tell application "System Events" to return (name of processes contains "iTunes")
    end fniTunesisActive

    to fuisiTunesNUD()
        if fniTunesisActive() is true then
            tell application "iTunes"
                if player state is playing then
                    set iTsNewDBID to (get database ID of current track)
                    if iTsNewDBID is not iTsCurDBID then
                        set strSNGArtist to (get artist of current track)
                        set strSNGName to (get name of current track)
                        set strSNGAlbum to (get album of current track)
                        set strSNGTrackNumber to (get track number of current track)
                        set strSNGDuration to (get duration of current track as integer)
                        set iTsCurDBID to iTsNewDBID
                        return true
                    else
                        return false
                    end if
                else
                    return false
                end if
            end tell
        else
            return false
        end if
    end fuisiTunesNUD

    to SmartSay(strToSay)
        set isiTPing to false
        if fniTunesisActive() is true then
            tell application "iTunes" to if player state is playing then set isiTPing to true
        end if
        if isiTPing is true then
            tell application "iTunes"
                set iTsORSoundVolume to sound volume
                set sound volume to iTsORSoundVolume * 0.333
            end tell
            say "" & strToSay
            tell application "iTunes" to set sound volume to iTsORSoundVolume
        else
            say "" & strToSay
        end if
    end SmartSay

    to fnLastfm()
        if fuisiTunesNUD() is true then
            if (length of strSNGName) > 0 or (length of strSNGArtist) > 0 then
                tell application "iTunes"
                    set iTsORSoundVolume to sound volume
                    set sound volume to iTsORSoundVolume * 0.333
                end tell
                if (length of strSNGName) > 0 then
                    say strSNGName
                    delay 1
                end if
                if (length of strSNGArtist) > 0 then say strSNGArtist
                tell application "iTunes" to set sound volume to iTsORSoundVolume
            end if
            if (length of LastfmUsername) > 0 and (length of LastfmPassword) > 0 then
                try
                    do shell script "curl --connect-timeout 33 \"http://lastfmstats.livefrombmore.com/universalscrobbler/scrobble.php?submissionType=track" & "&username=" & LastfmUsername & "&password=" & LastfmPassword & "&artist=" & fnURLec(strSNGArtist) & "&track=" & fnURLec(strSNGName) & "&album=" & fnURLec(strSNGAlbum) & "&number=" & strSNGTrackNumber & "&duration=" & strSNGDuration & "\""
                on error
                    SmartSay("Scrobbling Failed")
                end try
            end if
        end if
    end fnLastfm

    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Trackbacks

    The trackback URL for this entry is:
    http://honeonet.spaces.live.com/blog/cns!15BAC1A170471DB!15075.trak
    Weblogs that reference this entry
    • None