Skip to content

Instantly share code, notes, and snippets.

@joscha
Created April 24, 2010 23:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joscha/378036 to your computer and use it in GitHub Desktop.
Save joscha/378036 to your computer and use it in GitHub Desktop.
Script for shutting down LaCie d2 Network version 1
#!/usr/bin/env python
''' Script for automatically shutting down LaCie d2 Network version 1
Tested with system version 2.2.5, but might also work on others '''
import crypt, sys, hmac, urllib, urllib2, cookielib
from xml.dom.minidom import parseString
''' Your user name '''
USER = u"admin"
''' Your password '''
PASS = u"password"
''' The IP or hostname of your d2 Network '''
MACHINE = "d2.local"
''' ~~~~~ END OF CONFIGURATION SETTINGS ~~~~~ '''
URL = "http://"+ MACHINE +"/cgi-bin/public/edconfd.cgi?%s"
def getChallenge(opener):
params = urllib.urlencode({'method': 'getChallenge', 'login': USER})
f = opener.open(URL % params)
dom = parseString(f.read())
challenge = dom.getElementsByTagName('challenge')[0].firstChild.data
salt = dom.getElementsByTagName('salt')[0].firstChild.data
'''print "salt", salt
print "challenge", challenge'''
return (challenge, salt)
def getSID(opener, hash,challenge):
params = urllib.urlencode({'method': 'getSID', 'hash': hash, 'challenge': challenge})
f = opener.open(URL % params)
def shutdown(opener):
params = urllib.urlencode({'method': 'shutdown'})
data = '<lacie_conf><machine action="shutdown"/></lacie_conf>'
f = opener.open(URL % params, data)
return parseString(f.read()).getElementsByTagName('returnValue')[0].getAttribute('type')
def calculateRes(salt,challenge):
pw = crypt.crypt(PASS,salt)
'''print "pw", pw'''
res = hmac.new(pw,challenge).hexdigest()
'''print "combined", res'''
return res
def main():
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
(challenge, salt) = getChallenge(opener)
res = calculateRes(salt, challenge)
getSID(opener, res, challenge)
print shutdown(opener)
return sys.stdout
if __name__ == "__main__":
main()
@thobach
Copy link

thobach commented May 12, 2010

Works fine with LaCie d2 Network system version 2.2.2 on Mac
Thanks!

@thobach
Copy link

thobach commented Oct 28, 2010

created a simple dashboard widget (mac osx) that launches the script, if anyone is interested, just ping me...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment