Automatic decompression of vsftpd uploaded files

Source: Internet
Author: User

rsyslog.conf Configuring custom templates

$template Ssolog, "%msg%\n"
if $programname = = ' vsftpd ' then ^/bin/auto_unzip.py;ssolog
# $ModLoad Omprog
# $ActionOMProgBinary/etc/auto_unzip.py
#if $programname = = ' VSFTPD ' then:omprog:;ssolog * */var/log/mvsftpd.log;ssolog

Writing scripts

vim/bin/auto_unzip.py

#!/usr/bin/python

Import Sys
Import OS


Base_dir = '/home/wwwroot/default/client/'

def extract_zip (Ftp_user, File_path):
Abs_file_path = Os.path.join (Base_dir, file_path[1:])
If Ftp_user! = ":
Os.system (' sudo unzip%s-d%s '% (Abs_file_path, Os.path.dirname (Abs_file_path)))
Os.system (' sudo chown%s.%s-r%s '% (Ftp_user, Ftp_user, Os.path.dirname (Abs_file_path)))
Os.system (' sudo rm-f%s '% Abs_file_path)
Else
Return

def extract_targz (Ftp_user, File_path):
Abs_file_path = Os.path.join (Base_dir, file_path[1:])
If Ftp_user! = ":
Os.system (' sudo tar zxf%s-c%s '% (Abs_file_path, Os.path.dirname (Abs_file_path)))
Os.system (' sudo chown%s.%s-r%s '% (Ftp_user, Ftp_user, Os.path.dirname (Abs_file_path)))
Os.system (' sudo rm-f%s '% Abs_file_path)
Else
Return

def extract_tgz (Ftp_user, File_path):
Abs_file_path = Os.path.join (Base_dir, file_path[1:])
If Ftp_user! = ":
Os.system (' sudo tar xf%s-c%s '% (Abs_file_path, Os.path.dirname (Abs_file_path)))
Os.system (' sudo chown%s.%s-r%s '% (Ftp_user, Ftp_user, Os.path.dirname (Abs_file_path)))
Os.system (' sudo rm-f%s '% Abs_file_path)
Else
Return

FH = open ('/tmp/auto_unzip.log ', ' A + ')

Log = sys.argv[1]
Log_arr = Log.split (', ')
If Len (Log_arr) > 2:
Ftp_user = ' '
Ftp_user_arr = Log_arr[0].split (")
If Len (Ftp_user_arr) > 1:
Ftp_user = Ftp_user_arr[1].strip (' [] ')
File_path = Log_arr[1].strip (' "')
#fh. Write (File_path + ' \ n ')
If File_path.endswith ('. zip '):
Extract_zip (Ftp_user, File_path)
Fh.write ('%s extract ok.\n '% file_path)
Elif file_path.endswith (' tar.gz '):
Extract_targz (Ftp_user, File_path)
Fh.write ('%s extract ok.\n '% file_path)
Elif File_path.endswith ('. tgz '):
Extract_tgz (Ftp_user, File_path)
Fh.write ('%s extract ok.\n '% file_path)
Else
Pass
Fh.close ()

Automatic decompression of vsftpd uploaded files

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.