2009年10月26日星期一

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

非常感谢热心网友赐稿!热烈欢迎大家向我们投稿投稿信箱地址:chinagfwblog(at)gmail.com

来源:http://honeonet.spaces.live.com/Blog/cns!15BAC1A170471DB!15075.entry

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




--
Posted By GFW Blog to GFW BLOG at 10/26/2009 04:30:00 A
--~--~---------~--~----~------------~-------~--~----~
1、请点击www.chinagfw.org访问我们,订阅地址:http://feeds2.feedburner.com/chinagfwblog。2、需要Psiphon2注册邀请的朋友,请向english@sesawe.net发送电子邮件请求,说明 "can I have psiphon2 access" 并告诉您所在的国家。也可以使用Twitter Direct Messages或登陆Psiphon网站直接向Psiphon索取使用邀请。3、GFW Blog现提供最新翻墙工具下载(地址一、二、三),翻墙(突破网络封锁)方法介绍请见本站anti-censorship部分。4、本站热烈欢迎各位朋友投稿或推荐文章,请发邮件至chinagfwblog[at]gmail.com。5、敬请关注、支持、参与Sesawe和黑箱监管集体诉讼。
To unsubscribe from this group, send email to
gfw-blog+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/gfw-blog?hl=zh-CN
-~----------~----~----~----~------~----~------~--~---

没有评论:

发表评论