Exemplo n.º 1
0
def addShare(share, group=None, description=None, public=False) :
  debugOutput("Adding Samba share '%s'" % (share))
 
  if not group : group = groupNameFromShare(share)

  sharePath = os.path.join(SAMBA_SHARES_PATH, share)
 
  if share in getShares():
    if not smartbox.options.testRun :
      interface.abort("The share '%s' exists or has been defined already" % sharePath)
 
  if group not in system.readFromFile("/etc/group") :
    system.addGroup(group)
 
  if not os.path.exists(sharePath) :
    system.run("""mkdir -p "%s" """ % sharePath, exitOnFail = False)
  system.run("""chgrp %s "%s" """ % (group, sharePath))
  system.run("""chmod 6770 "%s" """ % sharePath)

  shareConfig = _createShareConfig(share, sharePath, group, description)
  
  sambaConfig = system.readFromFile(SAMBA_CONFIG)
  sambaConfig += "\n\n%s" % shareConfig
  
  sambaConfig = setShareDetails(share, description, public=public, sambaConfig=sambaConfig)
   
  system.writeToConfigFile("/etc/samba/smb.conf",sambaConfig)
 
  restart()
Exemplo n.º 2
0
def addShare(share, group=None, description=None, public=False):
    debugOutput("Adding Samba share '%s'" % (share))

    if not group: group = groupNameFromShare(share)

    sharePath = os.path.join(SAMBA_SHARES_PATH, share)

    if share in getShares():
        if not smartbox.options.testRun:
            interface.abort(
                "The share '%s' exists or has been defined already" %
                sharePath)

    if group not in system.readFromFile("/etc/group"):
        system.addGroup(group)

    if not os.path.exists(sharePath):
        system.run("""mkdir -p "%s" """ % sharePath, exitOnFail=False)
    system.run("""chgrp %s "%s" """ % (group, sharePath))
    system.run("""chmod 6770 "%s" """ % sharePath)

    shareConfig = _createShareConfig(share, sharePath, group, description)

    sambaConfig = system.readFromFile(SAMBA_CONFIG)
    sambaConfig += "\n\n%s" % shareConfig

    sambaConfig = setShareDetails(share,
                                  description,
                                  public=public,
                                  sambaConfig=sambaConfig)

    system.writeToConfigFile("/etc/samba/smb.conf", sambaConfig)

    restart()
Exemplo n.º 3
0
def getSambaRootPass():

    password = interface.prompt("Set a password for the smartbox network Administrator", password=True)
    cPassword = interface.prompt("Retype password for the network Administrator", password=True)
    if password != cPassword:
        interface.abort("The passwords do not match.")
    return password
Exemplo n.º 4
0
def getSambaRootPass():

    password = interface.prompt(
        "Set a password for the smartbox network Administrator", password=True)
    cPassword = interface.prompt(
        "Retype password for the network Administrator", password=True)
    if password != cPassword:
        interface.abort("The passwords do not match.")
    return password
Exemplo n.º 5
0
def generateLogonScript():

    import socket

    try:
        username = smartbox.options.args[-1]
    except:
        interface.abort(
            "You must enter a username to generate a login script.")

    debugOutput("Generating logon.bat for '%s'." % username)

    hostName = socket.gethostname()

    loginScript = "echo off\nnet use /persistent:no\n"

    shareFolder = SAMBA_SHARES_PATH
    for share in os.listdir(shareFolder):
        sharePath = os.path.join(shareFolder, share)
        debugOutput("Checking permissions on '%s' " % sharePath)
        try:
            shareGroup = grp.getgrgid(os.stat(sharePath).st_gid)
            debugOutput("shareGroup: %s members %s" %
                        (shareGroup, shareGroup.gr_mem))
            if username in shareGroup.gr_mem or shareGroup.gr_name == "users":
                loginScript += """net use * "\\\\%s\\%s"\n""" % (hostName,
                                                                 share)
        except:
            pass

    # Add the backup share
    loginScript += """net use * "\\\\%s\\%s"\n""" % (hostName, "backups")

    debugOutput(loginScript)

    # Use DOS file endings.
    loginScript = loginScript.replace("\n", "\r\n")
    scriptFile = os.path.join(SAMBA_HOME, "netlogon", "%s.bat" % username)
    system.writeToFile(scriptFile, loginScript)

    system.run("""chown "%s" "%s" """ % (username, scriptFile))
    system.run("""chgrp "%s" "%s" """ % ("users", scriptFile))
    system.run("""chmod 700 "%s" """ % scriptFile)
Exemplo n.º 6
0
def downloadUncompressInstall(source, installCommand=None) :
  debugOutput("source '%s' installCommand '%s'." % (source, installCommand))
  
  package = os.path.basename(source)
  tempDir = "/tmp"
 
  debugOutput("package '%s'" % package)
  
  if package.endswith("tar.gz") :
    uncompressCommand = "tar -xzf"
  else :
    interface.abort("I don't know how to uncompress '%s'."%package)

  if not os.path.exists(os.path.join(tempDir, package)) :
    run("cd %s && wget %s" % (tempDir, source))
  interface.updateProgress()
  run("cd %s && %s %s" % (tempDir, uncompressCommand, os.path.basename(source)))
  interface.updateProgress()
  if installCommand :
    run("cd %s && %s" % (tempDir, installCommand))
  interface.updateProgress()
Exemplo n.º 7
0
def generateLogonScript() :
 
  import socket

  try :
    username = smartbox.options.args[-1]
  except :
    interface.abort("You must enter a username to generate a login script.")
  
  debugOutput("Generating logon.bat for '%s'." % username)

  hostName = socket.gethostname()

  loginScript = "echo off\nnet use /persistent:no\n"

  shareFolder = SAMBA_SHARES_PATH
  for share in os.listdir(shareFolder) :
    sharePath = os.path.join(shareFolder, share)
    debugOutput("Checking permissions on '%s' " % sharePath)
    try :
      shareGroup = grp.getgrgid(os.stat(sharePath).st_gid)
      debugOutput("shareGroup: %s members %s" % (shareGroup, shareGroup.gr_mem))
      if username in shareGroup.gr_mem or shareGroup.gr_name == "users":
        loginScript += """net use * "\\\\%s\\%s"\n""" % (hostName, share)
    except :
      pass

  # Add the backup share
  loginScript += """net use * "\\\\%s\\%s"\n""" % (hostName, "backups")

  debugOutput(loginScript)
  
  # Use DOS file endings.
  loginScript = loginScript.replace("\n","\r\n")
  scriptFile = os.path.join(SAMBA_HOME, "netlogon", "%s.bat" % username)
  system.writeToFile(scriptFile, loginScript)
  
  system.run("""chown "%s" "%s" """ % (username, scriptFile))
  system.run("""chgrp "%s" "%s" """ % ("users", scriptFile))
  system.run("""chmod 700 "%s" """ % scriptFile)
Exemplo n.º 8
0
def downloadUncompressInstall(source, installCommand=None):
    debugOutput("source '%s' installCommand '%s'." % (source, installCommand))

    package = os.path.basename(source)
    tempDir = "/tmp"

    debugOutput("package '%s'" % package)

    if package.endswith("tar.gz"):
        uncompressCommand = "tar -xzf"
    else:
        interface.abort("I don't know how to uncompress '%s'." % package)

    if not os.path.exists(os.path.join(tempDir, package)):
        run("cd %s && wget %s" % (tempDir, source))
    interface.updateProgress()
    run("cd %s && %s %s" %
        (tempDir, uncompressCommand, os.path.basename(source)))
    interface.updateProgress()
    if installCommand:
        run("cd %s && %s" % (tempDir, installCommand))
    interface.updateProgress()
Exemplo n.º 9
0
def handleCode(code) :
  if code in (dialogInstance.DIALOG_CANCEL, dialogInstance.DIALOG_ESC): interface.abort("")
Exemplo n.º 10
0
def handleCode(code):
    if code in (dialogInstance.DIALOG_CANCEL, dialogInstance.DIALOG_ESC):
        interface.abort("")