Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- property vers : "SABchill 1.6"
- property setuprun : false
- property sabnzbd_ip : "127.0.0.1"
- property sabnzbd_port : "8080"
- property sabnzbd_api : "00000000000000000000"
- property sabnzbd_user : ""
- property sabnzbd_pass : ""
- property time_in_minutes : "30" -- minutes
- property always_ask_time : "true"
- (*
- 0.8
- First release, small distribution.
- 1.0
- Fixed issues where setup loops, or asks for delay numerous times.
- 1.1
- If sabnzbd_ip remains "12.0.0.1" then script will run setup.
- 1.2
- If provided with the correct hostname and port, SABchill will open a web broser to make it easier to grab your API KEY. Please note if you have web authentication turned on, you will need to sign in prior to seeing the API Key
- 1.5
- Added support to automatically pull the user api key, but I stick it in the existing interface, still gives the option to open the webpage at the correct location.
- 1.6
- Fixed error handling of new routine. Now if the username/pass or ip/port is wrong, we will reset those variables, and the script will ask until it is right
- *)
- on run {}
- tell me to activate
- if setuprun is false then
- my runsetup()
- end if
- if always_ask_time = "true" then
- set time_in_minutes to text returned of (display dialog "How long would you like to pause SABnzbd for?" default answer time_in_minutes with title vers)
- end if
- ignoring application responses
- set sabnzbd_respose to (do shell script "curl \"http://" & sabnzbd_ip & ":" & sabnzbd_port & "/sabnzbd/api?mode=config&name=set_pause&value=" & time_in_minutes & "&apikey=" & sabnzbd_api & "\";true")
- if sabnzbd_respose does not contain "ok" then
- if sabnzbd_respose contains "connect() timed out" or sabnzbd_respose contains "resolve host" then
- set setuprun to false
- display dialog "Connection Timed out. Please verify IP and Port
- IP: " & sabnzbd_ip & "
- Port: " & sabnzbd_port with title vers
- set sabnzbd_ip to "127.0.0.1"
- set sabnzbd_port to "8080"
- end if
- if sabnzbd_respose contains "API Key Incorrect" then
- set setuprun to false
- display dialog "API Key is wrong, please verify in SABnzbd-> Config -> General -> API Key
- Current Value: " & sabnzbd_api with title vers
- set sabnzbd_api to "00000000000000000000"
- end if
- end if
- end ignoring
- end run
- on runsetup()
- --if sabnzbd_api = "00000000000000000000" and sabnzbd_ip = "127.0.0.1" then
- if sabnzbd_ip = "127.0.0.1" or sabnzbd_port = "8080" then
- set sabnzbd_ip to text returned of (display dialog "What is the IP address or domain of your SABnzbd installation?" default answer sabnzbd_ip with title vers)
- set sabnzbd_port to text returned of (display dialog "What is the port of your SABnzbd installation?" default answer sabnzbd_port with title vers)
- end if
- if sabnzbd_user = "" or sabnzbd_pass = "" then
- set sabnzbd_user to text returned of (display dialog "What is the USERNAME used to access?" default answer sabnzbd_user with title vers)
- set sabnzbd_pass to text returned of (display dialog "What is the PASSWORD used to access?" default answer sabnzbd_pass with title vers)
- end if
- try
- set sabnzbd_api to item 1 of stringtolist(item 2 of my stringtolist(do shell script "curl -u " & sabnzbd_user & ":" & sabnzbd_pass & " http://" & sabnzbd_ip & ":" & sabnzbd_port & "/config/general/", "var apikey = \""), "\";")
- on error errmsg
- if errmsg contains "Connection refused" then
- try
- display dialog "The IP address \"" & sabnzbd_ip & "\" or port \"" & sabnzbd_port & "\" is incorrect." buttons "Cancel" default button 1
- on error
- set sabnzbd_ip to "127.0.0.1"
- set sabnzbd_port to "8080"
- end try
- else if errmsg contains "Error 401 Unauthorized" then
- try
- display dialog "The username \"" & sabnzbd_user & "\" or password \"" & sabnzbd_pass & "\" is incorrect." buttons "Cancel" default button 1
- on error
- set sabnzbd_user to ""
- set sabnzbd_pass to ""
- end try
- else
- display dialog errmsg
- end if
- set setuprun to false
- my runsetup()
- end try
- set sabtempanswer to (display dialog "What is SABnzbd API key?
- SABnzbd-> Config -> General -> API Key
- If this field is something besides 0's then the key shown was pulled from your installation." default answer sabnzbd_api buttons {"See my API key", "Cancel", "OK"} with title vers)
- set sabnzbd_api to text returned of sabtempanswer
- if button returned of sabtempanswer = "See my API key" then
- do shell script "open http://" & sabnzbd_ip & ":" & sabnzbd_port & "/config/general/"
- delay 3
- tell me to activate
- my runsetup()
- end if
- set always_ask_time to button returned of (display dialog "Prompt for pause length?
- Current value is " & time_in_minutes & " minutes." buttons {"False", "True"} default button "True" with title vers)
- set setuprun to true
- end runsetup
- --takes a string of data like "hello, my name is Mike" and converts it into {"hello,","my","name","is","Mike"} so that you can specify first item, second item or walk down a list searching, listtostring() does the opposite. listtostring is not used in this script, but I have included that code below, as these 2 should always be with each other.
- on stringtolist(theString, delim)
- set oldelim to AppleScript's text item delimiters
- set AppleScript's text item delimiters to delim
- set dlist to (every text item of theString)
- set AppleScript's text item delimiters to oldelim
- return dlist
- end stringtolist
- on ListToString(theList, delim)
- set oldelim to AppleScript's text item delimiters
- set AppleScript's text item delimiters to delim
- set alist to theList as string
- set AppleScript's text item delimiters to oldelim
- return alist
- end ListToString
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement