Enables Uberspace users to administrate some functions via a very simple web panel
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

changepw.py 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/env python
  2. ########################################################################
  3. # Copyright (C) 2016 Max Mehl <mail [at] mehl [dot] mx>
  4. ########################################################################
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Affero General Public License as
  8. # published by the Free Software Foundation, either version 3 of the
  9. # License, or (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 Affero General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Affero General Public
  17. # License along with this program. If not, see
  18. # <http://www.gnu.org/licenses/>.
  19. #
  20. ########################################################################
  21. #
  22. # This script is responsible to change a password using vpasswd. It is
  23. # needed because we need the expect function and using python we can
  24. # avoid potential password leaks when other users see the output of ps.
  25. #
  26. ########################################################################
  27. import sys
  28. import pexpect
  29. # Read variables of first and second given argument
  30. user = str(sys.argv[1])
  31. passwordfile = str(sys.argv[2])
  32. # Read content of passwordfile and put as variable "password"
  33. with open (passwordfile, "r") as myfile:
  34. password=myfile.read().replace('\n', '')
  35. # Define function
  36. def _vchangepw(user, password):
  37. changepw = pexpect.spawn(
  38. command='vpasswd', # actual shell command which should be started
  39. args=[user] # necessary argument
  40. )
  41. changepw.expect('password:')
  42. changepw.sendline(password)
  43. changepw.expect('verification:')
  44. changepw.sendline(password)
  45. changepw.expect(pexpect.EOF)
  46. changepw.close()
  47. # Error handling
  48. if changepw.exitstatus != 0:
  49. last_line = filter(None, changepw.before.split('\r\n'))[-1]
  50. problem = last_line.split(':')[-1]
  51. print "ERROR! Code: " + str(changepw.exitstatus)
  52. print "Last error: " + str(problem)
  53. else:
  54. print "SUCCESS!"
  55. print "The password of user " + str(user) + " has been changed to: " + str(password)
  56. # Start function
  57. _vchangepw(user, password)