Example #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()
Example #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()
Example #3
0
def installCronScript():
    debugOutput("Debug install cron script.")
    from pkg_resources import resource_filename
    cronConfig = system.readFromFile(
        resource_filename(smartbox.__name__,
                          os.path.join("resources", "smartbox-cron")))
    system.writeToFile(CRON_TARGET, cronConfig)
Example #4
0
def setDomain(domain) :
  if domain == getDomain() :
    return
  sambaConfig = system.readFromFile(SAMBA_CONFIG)
  sambaConfig = surgicalConfigSet(sambaConfig, "global","workgroup",domain)
  debugOutput(sambaConfig)
  system.writeToFile(SAMBA_CONFIG, sambaConfig)
  restart()
Example #5
0
def setDomain(domain):
    if domain == getDomain():
        return
    sambaConfig = system.readFromFile(SAMBA_CONFIG)
    sambaConfig = surgicalConfigSet(sambaConfig, "global", "workgroup", domain)
    debugOutput(sambaConfig)
    system.writeToFile(SAMBA_CONFIG, sambaConfig)
    restart()
Example #6
0
def install(domain):

    if isInstalled():
        return

    debugOutput("Installing samba")

    apt.install("samba samba-common libcupsys2 libkrb53 winbind smbclient")

    interface.updateProgress()

    sambaConfig = _createConfig(domain)
    debugOutput(sambaConfig)
    # XXX: Warning, what if samba file exists.
    system.writeToConfigFile(SAMBA_CONFIG, sambaConfig)

    system.run("""mkdir -p "%s" """ % SAMBA_HOME)
    system.run("""mkdir -p "%s/netlogon" """ % SAMBA_HOME)
    system.run("""mkdir -p "%s/profiles" """ % SAMBA_HOME)
    system.run("""mkdir -p "%s/data" """ % SAMBA_HOME)
    system.run("""mkdir -p "%s" """ % SAMBA_USERS_PATH)
    system.run("""mkdir -p "%s" """ % SAMBA_SHARES_PATH)
    system.run("""mkdir -p /var/spool/samba""", exitOnFail=False)
    system.run("""chmod 777 /var/spool/samba/""")
    system.run("""chmod 770 "%s/profiles" """ % SAMBA_HOME)
    system.run("""chmod 770 "%s/netlogon" """ % SAMBA_HOME)
    system.run("""chmod 775 "%s" """ % SAMBA_USERS_PATH)
    system.run("""chown -R root:users "%s/" || chmod -R 771 "%s/" """ %
               (SAMBA_HOME, SAMBA_HOME))

    interface.updateProgress()

    restart()

    interface.updateProgress()

    nsswitchString = system.readFromFile("/etc/nsswitch.conf")
    onsswitchString = nsswitchString
    nsswitchString = nsswitchString.replace("files dns", "files wins dns")
    if nsswitchString != onsswitchString:
        system.writeToConfigFile("/etc/nsswitch.conf", nsswitchString)

    system.run("net groupmap add ntgroup='Domain Admins' unixgroup=root")
    system.run("net groupmap add ntgroup='Domain Users' unixgroup=users")
    system.run("net groupmap add ntgroup='Domain Guests' unixgroup=nogroup")

    # TODO: Check this has not been done.
    system.run("echo 'root = Administrator' > /etc/samba/smbusers")

    interface.updateProgress()

    # Add a default share that all users can access.
    if not "Files" in getShares():
        addShare("Files")
Example #7
0
def configure():
    # Enable mysql extensions.
    phpConfigFile = "/etc/php4/apache2/php.ini"
    phpConfig = system.readFromFile(phpConfigFile)

    phpConfig = phpConfig.replace(";extension=mysql.so", "extension=mysql.so")

    system.writeToConfigFile(phpConfigFile, phpConfig)

    # TODO: Boost php memory.

    sbapache.restart()
Example #8
0
def install(domain) :
  
  if isInstalled() :
    return
  
  debugOutput("Installing samba")
  
  apt.install("samba samba-common libcupsys2 libkrb53 winbind smbclient")
 
  interface.updateProgress();
 
  sambaConfig = _createConfig(domain)
  debugOutput(sambaConfig)
  # XXX: Warning, what if samba file exists.
  system.writeToConfigFile(SAMBA_CONFIG, sambaConfig)
  
  system.run("""mkdir -p "%s" """ % SAMBA_HOME)
  system.run("""mkdir -p "%s/netlogon" """ % SAMBA_HOME)
  system.run("""mkdir -p "%s/profiles" """ % SAMBA_HOME)
  system.run("""mkdir -p "%s/data" """ % SAMBA_HOME)
  system.run("""mkdir -p "%s" """ % SAMBA_USERS_PATH)
  system.run("""mkdir -p "%s" """ % SAMBA_SHARES_PATH)
  system.run("""mkdir -p /var/spool/samba""", exitOnFail=False)
  system.run("""chmod 777 /var/spool/samba/""")
  system.run("""chmod 770 "%s/profiles" """ % SAMBA_HOME)
  system.run("""chmod 770 "%s/netlogon" """ % SAMBA_HOME)
  system.run("""chmod 775 "%s" """ % SAMBA_USERS_PATH)
  system.run("""chown -R root:users "%s/" || chmod -R 771 "%s/" """ % (SAMBA_HOME, SAMBA_HOME))

  interface.updateProgress();
  
  restart()

  interface.updateProgress();
  
  nsswitchString = system.readFromFile("/etc/nsswitch.conf")
  onsswitchString = nsswitchString
  nsswitchString = nsswitchString.replace("files dns","files wins dns")
  if nsswitchString != onsswitchString :
    system.writeToConfigFile("/etc/nsswitch.conf", nsswitchString)

  system.run("net groupmap add ntgroup='Domain Admins' unixgroup=root")
  system.run("net groupmap add ntgroup='Domain Users' unixgroup=users")
  system.run("net groupmap add ntgroup='Domain Guests' unixgroup=nogroup")

  # TODO: Check this has not been done.
  system.run("echo 'root = Administrator' > /etc/samba/smbusers")
  
  interface.updateProgress();
  
  # Add a default share that all users can access.
  if not "Files" in getShares() :
    addShare("Files")
Example #9
0
def configure() :
  # Enable mysql extensions.
  phpConfigFile = "/etc/php4/apache2/php.ini"
  phpConfig = system.readFromFile(phpConfigFile)

  phpConfig = phpConfig.replace(";extension=mysql.so","extension=mysql.so")

  system.writeToConfigFile(phpConfigFile, phpConfig)

  # TODO: Boost php memory.

  sbapache.restart()
Example #10
0
def install(backupSources=None):
    debugOutput("Installing rsnapshot")
    apt.install("rsnapshot")

    # TODO: Sort out config file handling.
    system.run("mkdir /.rsnapshot", exitOnFail=False)
    system.run("chmod +rx /.rsnapshot")

    rsnapshotConf = system.readFromFile("/etc/rsnapshot.conf")
    rsnapshotConf = rsnapshotConf.replace(
        "snapshot_root\t/var/cache/rsnapshot/", "snapshot_root\t/.rsnapshot/")
    #rsnapshotConf = rsnapshotConf.replace("#no_create_root\t1","no_create_root\t0")
    rsnapshotConf = rsnapshotConf.replace("#interval", "interval")
    rsnapshotConf = rsnapshotConf.replace("\nbackup", "\n#backup")

    rsnapshotConf += "\n\n"

    for backupSource in backupSources:
        rsnapshotConf += "backup\t%s/\tbackups/\n" % backupSource.rstrip("/")
    rsnapshotConf += "backup\t/home/\t.system/\n"
    rsnapshotConf += "backup\t/etc/\t.system/\n"

    debugOutput(rsnapshotConf)

    system.writeToConfigFile("/etc/rsnapshot.conf", rsnapshotConf)

    cronConf = system.readFromFile("/etc/cron.d/rsnapshot")
    cronConf = cronConf.replace("# 0", "0")
    cronConf = cronConf.replace("# 30", "30")
    cronConf = cronConf.replace("*/4", "*")

    debugOutput(cronConf)

    system.writeToConfigFile("/etc/cron.d/rsnapshot", cronConf)

    interface.updateProgress()

    system.run("rsnapshot hourly")

    interface.updateProgress()
Example #11
0
def install(backupSources=None) :
  debugOutput("Installing rsnapshot")
  apt.install("rsnapshot")


  # TODO: Sort out config file handling.
  system.run("mkdir /.rsnapshot", exitOnFail=False)
  system.run("chmod +rx /.rsnapshot")

  rsnapshotConf = system.readFromFile("/etc/rsnapshot.conf")
  rsnapshotConf = rsnapshotConf.replace("snapshot_root\t/var/cache/rsnapshot/","snapshot_root\t/.rsnapshot/")
  #rsnapshotConf = rsnapshotConf.replace("#no_create_root\t1","no_create_root\t0")
  rsnapshotConf = rsnapshotConf.replace("#interval","interval")
  rsnapshotConf = rsnapshotConf.replace("\nbackup","\n#backup")

  rsnapshotConf += "\n\n"

  for backupSource in backupSources :
    rsnapshotConf += "backup\t%s/\tbackups/\n" % backupSource.rstrip("/")
  rsnapshotConf += "backup\t/home/\t.system/\n"
  rsnapshotConf += "backup\t/etc/\t.system/\n"

  debugOutput(rsnapshotConf)

  system.writeToConfigFile("/etc/rsnapshot.conf",rsnapshotConf)
  
  cronConf = system.readFromFile("/etc/cron.d/rsnapshot")
  cronConf = cronConf.replace("# 0","0")
  cronConf = cronConf.replace("# 30","30")
  cronConf = cronConf.replace("*/4","*")
  
  debugOutput(cronConf)
  
  system.writeToConfigFile("/etc/cron.d/rsnapshot", cronConf)
  
  interface.updateProgress()

  system.run("rsnapshot hourly")

  interface.updateProgress()
Example #12
0
def setShareDetails(shareName, description, public=False, sambaConfig=None):
    debugOutput("Setting share details for %s" % shareName)

    if not sambaConfig and shareName not in getShares():
        return

    # Get the group name of this share.
    shareGroup = groupNameFromShare(shareName)

    if not sambaConfig:
        sambaConfig = system.readFromFile(SAMBA_CONFIG)
        saveConfig = True
    else:
        saveConfig = False

    # Update the comment field
    newSambaConfig = surgicalConfigSet(sambaConfig, shareName, "comment",
                                       description)

    # Update guest access to the share
    # TODO: guest only, valid users
    if public:
        newSambaConfig = surgicalConfigSet(newSambaConfig, shareName,
                                           "valid users", "")
        newSambaConfig = surgicalConfigSet(newSambaConfig, shareName,
                                           "guest ok", "yes")
        newSambaConfig = surgicalConfigSet(newSambaConfig, shareName,
                                           "guest only", "yes")
        if not system.isUserInGroup("nobody", shareGroup):
            system.addUserToGroup("nobody", shareGroup)
    else:
        newSambaConfig = surgicalConfigSet(newSambaConfig, shareName,
                                           "valid users",
                                           "@%s root" % shareGroup)
        newSambaConfig = surgicalConfigSet(newSambaConfig, shareName,
                                           "guest ok", "no")
        newSambaConfig = surgicalConfigSet(newSambaConfig, shareName,
                                           "guest only", "no")
        if system.isUserInGroup("nobody", shareGroup):
            system.removeUserFromGroup("nobody", shareGroup)

    if saveConfig:
        if newSambaConfig != sambaConfig:
            system.writeToFile(SAMBA_CONFIG, newSambaConfig)
            restart()
    else:
        return newSambaConfig
Example #13
0
def prepareSystem():
  
  debugOutput("Configuring the Apt package manager")
  aptSources = system.readFromFile(APT_SOURCES).lower()
  originalSources = aptSources

  aptSources = re.compile("^\s*deb cdrom", re.MULTILINE).sub("#deb cdrom", aptSources)
  aptSources = re.compile("^#\s*deb http", re.MULTILINE).sub("deb http", aptSources)
  aptSources = re.compile("^#\s*deb-src http", re.MULTILINE).sub("deb-src http", aptSources)
  
  if aptSources != originalSources :
    debugOutput("Updating sources.")
    print "Preparing the system"
    system.writeToConfigFile(APT_SOURCES, aptSources)
    update()
  else :
    debugOutput("Package sources do not need updating.")
Example #14
0
def deleteShare(shareName) :
  debugOutput("Deleting share %s" % shareName)

  if shareName not in getShares() :
    return

  group = groupNameFromShare(shareName)
  sharePath = os.path.join(SAMBA_SHARES_PATH, shareName)
  system.run("""rm -rf "%s" """ % sharePath, exitOnFail=False)
  system.run("""delgroup "%s" """ % group, exitOnFail=False)
  
  # Remove smb.conf entry
  sambaConfig = system.readFromFile(SAMBA_CONFIG)
  match = re.search(r"\[%s\][^[]+" % shareName, sambaConfig, re.DOTALL)
  if match :
    sambaConfig = sambaConfig.replace(match.group(0),"").strip()
    system.writeToFile(SAMBA_CONFIG, sambaConfig)
    restart()
Example #15
0
def deleteShare(shareName):
    debugOutput("Deleting share %s" % shareName)

    if shareName not in getShares():
        return

    group = groupNameFromShare(shareName)
    sharePath = os.path.join(SAMBA_SHARES_PATH, shareName)
    system.run("""rm -rf "%s" """ % sharePath, exitOnFail=False)
    system.run("""delgroup "%s" """ % group, exitOnFail=False)

    # Remove smb.conf entry
    sambaConfig = system.readFromFile(SAMBA_CONFIG)
    match = re.search(r"\[%s\][^[]+" % shareName, sambaConfig, re.DOTALL)
    if match:
        sambaConfig = sambaConfig.replace(match.group(0), "").strip()
        system.writeToFile(SAMBA_CONFIG, sambaConfig)
        restart()
Example #16
0
def prepareSystem():

    debugOutput("Configuring the Apt package manager")
    aptSources = system.readFromFile(APT_SOURCES).lower()
    originalSources = aptSources

    aptSources = re.compile("^\s*deb cdrom",
                            re.MULTILINE).sub("#deb cdrom", aptSources)
    aptSources = re.compile("^#\s*deb http",
                            re.MULTILINE).sub("deb http", aptSources)
    aptSources = re.compile("^#\s*deb-src http",
                            re.MULTILINE).sub("deb-src http", aptSources)

    if aptSources != originalSources:
        debugOutput("Updating sources.")
        print "Preparing the system"
        system.writeToConfigFile(APT_SOURCES, aptSources)
        update()
    else:
        debugOutput("Package sources do not need updating.")
Example #17
0
def setShareDetails(shareName, description, public=False, sambaConfig=None) :
  debugOutput("Setting share details for %s" % shareName)

  if not sambaConfig and shareName not in getShares() :
    return
 
  # Get the group name of this share.
  shareGroup = groupNameFromShare(shareName)
  
  if not sambaConfig :
    sambaConfig = system.readFromFile(SAMBA_CONFIG)
    saveConfig = True
  else :
    saveConfig = False

  # Update the comment field
  newSambaConfig = surgicalConfigSet(sambaConfig, shareName, "comment", description)
  
  # Update guest access to the share
  # TODO: guest only, valid users
  if public :
    newSambaConfig = surgicalConfigSet(newSambaConfig, shareName, "valid users", "")
    newSambaConfig = surgicalConfigSet(newSambaConfig, shareName, "guest ok", "yes")
    newSambaConfig = surgicalConfigSet(newSambaConfig, shareName, "guest only", "yes")
    if not system.isUserInGroup("nobody", shareGroup) :
      system.addUserToGroup("nobody", shareGroup)
  else :
    newSambaConfig = surgicalConfigSet(newSambaConfig, shareName, "valid users", "@%s root" % shareGroup)
    newSambaConfig = surgicalConfigSet(newSambaConfig, shareName, "guest ok", "no")
    newSambaConfig = surgicalConfigSet(newSambaConfig, shareName, "guest only", "no")
    if system.isUserInGroup("nobody", shareGroup) :
      system.removeUserFromGroup("nobody", shareGroup)
  
  if saveConfig :
    if newSambaConfig != sambaConfig :
      system.writeToFile(SAMBA_CONFIG, newSambaConfig)
      restart()
  else :
    return newSambaConfig
Example #18
0
def installCronScript():
    debugOutput("Debug install cron script.")
    from pkg_resources import resource_filename

    cronConfig = system.readFromFile(resource_filename(smartbox.__name__, os.path.join("resources", "smartbox-cron")))
    system.writeToFile(CRON_TARGET, cronConfig)