Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Scripts that imports users from an existing database.
- Copyright (C) 2006 Filip de Waard, Net Collective.
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- """
- import os
- import FTPToolkit
- import MySQLdb
- import Config
- toolkit = FTPToolkit.FTPToolkit()
- con = MySQLdb.connect(host = Config.hostAntiqb, port = Config.portAntiqb,
- user = Config.usernameAntiqb, passwd = Config.passwordAntiqb, db = Config.databaseAntiqb)
- cursor = con.cursor(MySQLdb.cursors.DictCursor)
- cursor.execute("SELECT owner_id, passwd FROM klanten")
- results = cursor.fetchall()
- con.close()
- print "Adding", len(results), ("users...")
- i = 0
- j = 0
- for row in results:
- if row["owner_id"] and row["passwd"]:
- i, j = j, j+1
- uid = i + Config.minimalUID
- homeDir = Config.homeDirBase + row["owner_id"]
- command = "ftpasswd --passwd --file=" + Config.userConfigFile + " --name=" +
- row["owner_id"] + " --uid=" + uid + " --home=" + homeDir + " --shell=" +
- Config.shell + " --gid=" + Config.userGID
- try:
- f = os.popen(command)
- print >>f, row["passwd"]
- f.close()
- except OSError:
- print
- #create homeDir if it doesn't exist already
- if not os.access(homeDir, os.F_OK):
- os.mkdir(homeDir)
- try:
- os.chown(homeDir, self.ftpUID, self.ftpGID)
- except OSError:
- if verbose:
- print("Directory created, but unable to chown it to the FTP user")
- print ("Done.")
Add Comment
Please, Sign In to add comment