Usage:
The code is as follows: |
Copy code |
[Root @ itchenyi-1 ~] #./Vsftpd_auto_user.py create chenyi # create a user Please input your ftpuser's password >>: Password [Root @ itchenyi-1 ~] #./Vsftpd_auto_user.py delete chenyi # delete a user [Root @ itchenyi-1 ~] #./Vsftpd_auto_user.py # Usage Warning:> syntax error Example:./vsftpd. py {create | disable | enable | passwd | delete} {username} Example:./vsftpd. py create username |
Demonstrate some python code. If you need to download it, please download it at the end of this article ,:
The code is as follows: |
Copy code |
#! /Usr/bin/env python # Blog: www.111cn.net # Des: auto add, delete, enable, disable user and change user's password Import sys, OS, commands USERFILE = "/etc/vsftpd/passwd. file" USERFILEDB = "/etc/vsftpd/ftpuser_passwd.db" VIRTUALFILE = "/etc/vsftpd/user_config" TEMPLATEFILE = "/etc/vsftpd/template_file" FTPROOT = "/vsftptest" FTPENTITYUSER = "chenyi" SYNTAXERROR = "warning:> syntax error Example:./vsftpd. py {create | disable | enable | passwd | delete} {username} Example:./vsftpd. py create usernamen """ Try: PARAM = sys. argv [1] USERNAME = sys. argv [2] Except t: Print SYNTAXERROR Exit () Def check_username_exist (): DESTPATH = OS. path. exists (r '% s' % USERFILE) If DESTPATH = False: Print "% s not exitstnnP. S: nYou can create this file to solve the problem" % USERFILE Exit () Else: EN, SN = commands. getstatusoutput ("sed-n 'p; n' % s | grep-w % s | wc-l" % (USERFILE, USERNAME )) If not (SN) = '0 ': Print "User % s ALREADY exist! "% USERNAME Exit () |
You may think the function meets your requirements. You need to use it by yourself. You need to modify the following:
Note:
USERFILE = the file where your virtual user stores the account password
USERFILEDB = database file generated by your db_load
VIRTUALFILE = path for storing configuration files by your virtual user
TEMPLATEFILE = the default template configuration file used by your virtual user. The user directory must be changed to chenyi. You can also modify the code yourself.
FTPROOT = your FTP root directory
FTPENTITYUSER = Your Virtual User maps to the local real user