In [13]:
import os
import getpass
from passlib.hash import pbkdf2_sha256
import crypt, getpass, spwd
from Crypto.PublicKey import RSA

In [14]:
fuliz = os.listdir('/home')

In [15]:
fuliz


Out[15]:
['tnow',
 'sjohns',
 'signinlca.py',
 'charle',
 'wcm',
 'wmck',
 'wmen',
 'webmck',
 'pjohns',
 'red',
 'wez',
 'checkthis',
 'blah',
 'joeman',
 'wkee',
 'jchick',
 'wcmckee',
 'wblack',
 'joemanz',
 'poiu',
 'poi',
 'qwe',
 'point',
 'cvb',
 'pytest',
 'figlet',
 'blag',
 'gerty',
 'jblog',
 'ssung',
 'clittle',
 'joecheck',
 'yellow']

In [16]:
#Chabge password for user
#pasuz = raw_input('User to change password: ')

In [17]:
#logtest = getpass.getpass('new password: ')

#loghash = pbkdf2_sha256.encrypt(logtest, rounds=200000, salt_size=16)
#vercryp = pbkdf2_sha256.verify(logtest, hashez)

In [18]:
#Enter user to delete.
#Even better, user to lock.

#delusa = raw_input('User to delete: ')
#locusa = raw_input('User to lock: ')
#os.system('sudo passwd -l ' + locusa)

In [19]:
#Read hashed passwords from /etc/shadow
#opshad = open('/etc/shadow', 'r')
#opshad.read()
#opshad.close()
#Better to do this with a python module. spwd reads
#shadow files done.
#Need to getpass and ask for password, comparing to 
#the password returned from spwd

In [20]:
pan = raw_input("Enter Username to delete: ")

In [21]:
#enc_pwd = spwd.getspnam(pan)[1]
#if enc_pwd in ["NP", "!", "", None]:
#    print "user '%s' has no password set" % pan
#if enc_pwd in ["LK", "*"]:
#    print "account is locked"
#if enc_pwd == "!!":
#    print "password has expired"

In [22]:
gpas = getpass.getpass('Enter Username Password: ')


Enter Username Password: ········

In [32]:
encpass = spwd.getspnam(pan)[1]


---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-32-9aef7c527eb2> in <module>()
----> 1 encpass = spwd.getspnam(pan)[1]

KeyError: 'getspnam(): name not found'

In [33]:
if crypt.crypt(gpas, encpass) == encpass:
    print ('True')
else:
    print "incorrect password"


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-33-4efe7353fce3> in <module>()
----> 1 if crypt.crypt(gpas, encpass) == encpass:
      2     print ('True')
      3 else:
      4     print "incorrect password"

NameError: name 'encpass' is not defined

In [34]:
#print spwd.getspnam(pan)[1]

In [35]:
#shpa = spwd.getspnam('wcmckee')[1]

In [36]:
#spwd.getspall()

In [37]:
#shpa

rsa key generated for each user and stored in their /home/user/.ssh/ folder. Public key is emailed, added to test servers.


In [38]:
new_key = RSA.generate(2048, e=65537)
public_key = new_key.publickey().exportKey("PEM")
private_key = new_key.exportKey("PEM")
print private_key 
sapriv = open('/home/wcmckee/.ssh/' + pan, 'w')
sapriv.write(private_key)
sapriv.close()

print public_key 
papriv = open('/home/wcmckee/.ssh/' + pan + '.pub', 'w')
papriv.write(public_key)
papriv.close()


-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAvEzwE1+D6TX2wDGUBhSZmwYkVsnVjoYiklhGBBIdg5jMHVkh
93HLlvu04KWAwSQHLIUFy4teTxovw+eo/5+VJAlelJZWcgctMsL+U1uRImD+aieV
uKEN65fCMdRIautEnPDAi9g51XleqpXvK/nGR9BRA5ibR31kcL+OYSqjFY0tlTdV
5JQ0jSZdudjgnNE33lrBwpdCUL112C4dT2r/gDfHM8icsitkhqnGxJ/xsw1sDaW8
ENSg73/lJO9Sc8j8d/mjVVVPHGs0TJneLq6Y/mF7QQq8Os0TAlXG+EnR/bX1saKa
qhxiFmKvF5ww/uSu79xkK2LajPY+DS27kia7yQIDAQABAoIBADl+HEcuAK6yBVcF
TDbXD1df9rRxB71ugxu/zBDuHwjRHHFRh6dvnUPKMp3sqnVONMqJCw3szazFSBQ+
pUD3TqgkHDat+FL0kf5PvytgZ93hU4zB7VrkAcYPHgHs2PecQeTRNVj9ehsN5bOb
99yrdLj0h+fbLn4TcRljw2szg3vOiykVe650zwu0D1J1/JxBq4bG/YndsLCPqdMk
5uZoroKx5myHnCMXRxChJAyHw+H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IBCgKCAQEAvEzwE1+D6TX2wDGUBhSZ
mwYkVsnVjoYiklhGBBIdg5jMHVkh93HLlvu04KWAwSQHLIUFy4teTxovw+eo/5+V
JAlelJZWcgctMsL+U1uRImD+aieVuKEN65fCMdRIautEnPDAi9g51XleqpXvK/nG
R9BRA5ibR31kcL+OYSqjFY0tlTdV5JQ0jSZdudjgnNE33lrBwpdCUL112C4dT2r/
gDfHM8icsitkhqnGxJ/xsw1sDaW8ENSg73/lJO9Sc8j8d/mjVVVPHGs0TJneLq6Y
/mF7QQq8Os0TAlXG+EnR/bX1saKaqhxiFmKvF5ww/uSu79xkK2LajPY+DS27kia7
yQIDAQAB
-----END PUBLIC KEY-----

In [39]:
#Spin up digital ocean server, with public key and 
#user created.

In [1]:
#import digitalocean

In [2]:
#tok  = ('c54ea484dcf55053743215cdb37309cb77a153e9810f35851b4701d4c8bf2881')

In [3]:
#digid = digitalocean.Manager(token='c54ea484dcf55053743215cdb37309cb77a153e9810f35851b4701d4c8bf2881')

In [4]:
#digid.get_account


Out[4]:
<bound method Manager.get_account of <digitalocean.Manager.Manager object at 0xb1a49390>>

In [15]:
#my_droplets = digid.get_all_droplets()

In [16]:
#lisdrop = []

In [17]:
#for myd in my_droplets:
#    print myd
    #lisdrop.append(myd.image)
    #
#    lisdrop.append(myd.ip_address)


1331748 brobeur.com
2109421 brobeurkids
2531143 wcmckee-notebook
3353353 getsdrawn

In [18]:
#lisdrop


Out[18]:
[u'128.199.199.74', u'178.62.53.181', u'104.131.11.174', u'128.199.60.12']

In [ ]:


In [7]:
#droplet = digitalocean.Droplet(token=tok,
#                               name='Example',
#                               region='nyc2', # New York 2
##                               image= , # Ubuntu 14.04 x64
 #                              size_slug='512mb',  # 512MB
#                              backups=True)


  File "<ipython-input-7-cdb0ee9afb58>", line 4
    image= , # Ubuntu 14.04 x64
           ^
SyntaxError: invalid syntax

In [8]:
#droplet.create()


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-8-e40debe66120> in <module>()
----> 1 droplet.create()

NameError: name 'droplet' is not defined

In [9]:
#dimg = digid.get_all_images()

In [10]:
#for di in dimg:
##    print di


4985495 wcmckee Debian
6126511 wcmckee Ubuntu
10690295 artcontrol final Debian
10564942 557.2.0 (beta) CoreOS
10679356 557.2.0 (stable) CoreOS
10679369 593.0.0 (alpha) CoreOS
6370882 20 x64 Fedora
6370885 20 x32 Fedora
6370968 19 x64 Fedora
6370969 19 x32 Fedora
6372321 5.10 x64 CentOS
6372425 5.10 x32 CentOS
6372581 6.0 x64 Debian
6372662 6.0 x32 Debian
9640922 21 x64 Fedora
9801948 14.04 x32 Ubuntu
9801950 14.04 x64 Ubuntu
9801951 14.10 x32 Ubuntu
9801954 14.10 x64 Ubuntu
10144573 10.1 FreeBSD
10321756 12.04.5 x64 Ubuntu
10321777 12.04.5 x32 Ubuntu
10321819 10.04 x64 Ubuntu
10321870 10.04 x32 Ubuntu
10322059 7.0 x64 Debian
10322378 7.0 x32 Debian
10322623 7 x64 CentOS
10325922 6.5 x64 CentOS
10325992 6.5 x32 CentOS
6376601 Ruby on Rails on 14.04 (Nginx + Unicorn) Ubuntu
6423475 WordPress on 14.04 Ubuntu
6732690 LEMP on 14.04 Ubuntu
6732691 LAMP on 14.04 Ubuntu
6798184 MEAN on 14.04 Ubuntu
8375425 Drupal 7.34 on 14.04 Ubuntu
8412876 Magento 1.9.1.0 on 14.04 Ubuntu
8953301 ELK Logging Stack on 14.04 Ubuntu
9918633 Ghost 0.5.8 on 14.04 Ubuntu
9967718 Django on 14.04 Ubuntu
10163059 FreeBSD AMP on 10.1 FreeBSD
10274087 GitLab 7.7.1 CE on 14.04 Ubuntu
10321359 MediaWiki 1.24.0 on 14.04 Ubuntu
10462503 Drone on 14.04 Ubuntu
10507592 node-v0.12.0 on 14.04 Ubuntu
10563620 Dokku v0.3.14 on 14.04 Ubuntu
10565666 ownCloud 8.0 on 14.04 Ubuntu
10581649 Docker 1.5.0 on 14.04 Ubuntu
7572830 Redmine on 14.04 Ubuntu

In [23]:
#opdel = os.listdir('/home/wcmckee/signinlca/deleteusers')

In [24]:
#opdel


Out[24]:
[]

In [ ]:
usrtodel = raw_input('Account to delete: ')

In [ ]:
locacc = os.system('sudo passwd -l ' + usrtodel)

In [ ]:
locacc

In [ ]:
os.system('mv ' + '  ' + '/home/wcmckee/signinlca/usernames/' + usrtodel + ' /home/wcmckee/signinlca/username/deleteusers/')