Guest User

Untitled

a guest
Feb 21st, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. """
  2. Scripts that imports users from an existing database.
  3.  
  4. Copyright (C) 2006 Filip de Waard, Net Collective.
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License along
  17. with this program; if not, write to the Free Software Foundation, Inc.,
  18. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. """
  20.  
  21. import os
  22. import FTPToolkit
  23. import MySQLdb
  24. import Config
  25.  
  26. toolkit = FTPToolkit.FTPToolkit()
  27.  
  28. con = MySQLdb.connect(host = Config.hostAntiqb, port = Config.portAntiqb,
  29. user = Config.usernameAntiqb, passwd = Config.passwordAntiqb, db = Config.databaseAntiqb)
  30. cursor = con.cursor(MySQLdb.cursors.DictCursor)
  31.  
  32. cursor.execute("SELECT owner_id, passwd FROM klanten")
  33. results = cursor.fetchall()
  34. con.close()
  35.  
  36. print "Adding", len(results), ("users...")
  37. i = 0
  38. j = 0
  39. for row in results:
  40. if row["owner_id"] and row["passwd"]:
  41. i, j = j, j+1
  42. uid = i + Config.minimalUID
  43. homeDir = Config.homeDirBase + row["owner_id"]
  44.  
  45. command = "ftpasswd --passwd --file=" + Config.userConfigFile + " --name=" +
  46. row["owner_id"] + " --uid=" + uid + " --home=" + homeDir + " --shell=" +
  47. Config.shell + " --gid=" + Config.userGID
  48.  
  49. try:
  50. f = os.popen(command)
  51. print >>f, row["passwd"]
  52. f.close()
  53. except OSError:
  54. print
  55.  
  56. #create homeDir if it doesn't exist already
  57. if not os.access(homeDir, os.F_OK):
  58. os.mkdir(homeDir)
  59. try:
  60. os.chown(homeDir, self.ftpUID, self.ftpGID)
  61. except OSError:
  62. if verbose:
  63. print("Directory created, but unable to chown it to the FTP user")
  64. print ("Done.")
Add Comment
Please, Sign In to add comment