#!/usr/bin/python

import sys
import dbus, flimflam

if (len(sys.argv) < 2):
    print "Usage: %s <ssid> [passphrase] [security]" % (sys.argv[0])
    sys.exit(1)

print "Attempting to configure hidden service %s" % (sys.argv[1])

flim = flimflam.FlimFlam(dbus.SystemBus())

ssid = sys.argv[1]
if len(sys.argv) > 2:
    if len(sys.argv) > 3:
        security = sys.argv[3]
    else:
        security = "psk"
    passphrase = sys.argv[2]
else:
    security = "none"
    passphrase = ""

flim.manager.ConfigureService(({
      "Type" : "wifi",
      "Mode" : "managed",
      "SSID" : ssid,
      "WiFi.HiddenSSID" : True,
      "Security" : security,
      "Passphrase" : passphrase }))