def install() : debugOutput("Installing") system.run("sudo easy_install -f http://www.nickblundell.org.uk/packages --upgrade wikidbase") # Create a suitable settings file and a place for the db with www-data access uploadsPath = os.path.join(WB_PATH, "files") # XXX: pops up no module named wikidbase wbSettings = getSettingsData() settingsFile = os.path.join(WB_PATH, "settings.py") databasePath = os.path.join(WB_PATH, "wbdata.db") cacheTable = "wbcache" # XXX: Adding these to end will cause settings.py logic to fail. # Set settings. wbSettings += """ DATABASE_ENGINE = "sqlite3" DATABASE_NAME="%s" CACHE_BACKEND="db://%s" UPLOAD_FOLDER="%s" """ % (databasePath, cacheTable, uploadsPath) # Create folders and set permissions. system.run("mkdir -p '%s'" % uploadsPath) system.writeToFile(settingsFile, wbSettings) system.run("chgrp -R www-data '%s'" % WB_PATH) system.run("chmod -R g+rwx '%s'" % WB_PATH) # Initialise app sbdjango.initialiseApp("settings",DEFAULT_ADMIN_CREDENTIALS[0], DEFAULT_ADMIN_CREDENTIALS[1], DEFAULT_ADMIN_CREDENTIALS[2], pythonPath=WB_PATH, cacheTable=cacheTable) # Do mod_python setup apt.install("libapache2-mod-python")
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)
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()
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()
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
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()
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()
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)
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)
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
def install(): debugOutput("Installing") system.run( "sudo easy_install -f http://www.nickblundell.org.uk/packages --upgrade wikidbase" ) # Create a suitable settings file and a place for the db with www-data access uploadsPath = os.path.join(WB_PATH, "files") # XXX: pops up no module named wikidbase wbSettings = getSettingsData() settingsFile = os.path.join(WB_PATH, "settings.py") databasePath = os.path.join(WB_PATH, "wbdata.db") cacheTable = "wbcache" # XXX: Adding these to end will cause settings.py logic to fail. # Set settings. wbSettings += """ DATABASE_ENGINE = "sqlite3" DATABASE_NAME="%s" CACHE_BACKEND="db://%s" UPLOAD_FOLDER="%s" """ % (databasePath, cacheTable, uploadsPath) # Create folders and set permissions. system.run("mkdir -p '%s'" % uploadsPath) system.writeToFile(settingsFile, wbSettings) system.run("chgrp -R www-data '%s'" % WB_PATH) system.run("chmod -R g+rwx '%s'" % WB_PATH) # Initialise app sbdjango.initialiseApp("settings", DEFAULT_ADMIN_CREDENTIALS[0], DEFAULT_ADMIN_CREDENTIALS[1], DEFAULT_ADMIN_CREDENTIALS[2], pythonPath=WB_PATH, cacheTable=cacheTable) # Do mod_python setup apt.install("libapache2-mod-python")
def setVHost(vHostName, vHostData): debugOutput("Setting vhost '%s': '%s'" % (vHostName, vHostData)) system.writeToFile( os.path.join("/etc", "apache2", "sites-available", vHostName), vHostData) setSiteEnabled(vHostName, True)
def setVHost(vHostName, vHostData) : debugOutput("Setting vhost '%s': '%s'" % (vHostName, vHostData)) system.writeToFile(os.path.join("/etc","apache2","sites-available",vHostName), vHostData) setSiteEnabled(vHostName, True)
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)