Guest User

Untitled

a guest
Feb 21st, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 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 popen2
  23. import FTPToolkit
  24. import MySQLdb
  25. import Config
  26.  
  27. toolkit = FTPToolkit.FTPToolkit()
  28.  
  29. con = MySQLdb.connect(host = Config.hostAntiqb, port = Config.portAntiqb,
  30. user = Config.usernameAntiqb, passwd = Config.passwordAntiqb, db = Config.databaseAntiqb)
  31. cursor = con.cursor(MySQLdb.cursors.DictCursor)
  32.  
  33. cursor.execute("SELECT owner_id, passwd FROM klanten")
  34. results = cursor.fetchall()
  35. con.close()
  36.  
  37. print "Adding", len(results), ("users...")
  38. i = 0
  39. j = 0
  40. for row in results:
  41. if row["owner_id"] and row["passwd"]:
  42. i, j = j, j+1
  43. uid = i + Config.minimalUID
  44. homeDir = Config.homeDirBase + row["owner_id"]
  45.  
  46. command = ("ftpasswd --passwd --file=%s --name=%s --uid=%d --home=%s --shell=%s --gid=%d --stdin" %
  47. (Config.userConfigFile, row["owner_id"], uid, homeDir, Config.shell, Config.userGID))
  48.  
  49. try:
  50. stdout, stdin = popen2.popen2(command, 8192, "w")
  51. stdin.write(row["passwd"])
  52. stdout.close()
  53. stdin.close()
  54. except OSError:
  55. print "Oops, something went wrong! (OSError)"
  56. except IOError:
  57. print "Oops, there was an IOError"
  58.  
  59. #create homeDir if it doesn't exist already
  60. if not os.access(homeDir, os.F_OK):
  61. os.mkdir(homeDir)
  62. print ("Done.")
Add Comment
Please, Sign In to add comment