Changeset 680 for trunk/mwsubmitter

Show
Ignore:
Timestamp:
10/27/06 05:41:44 (2 years ago)
Author:
chengyu
Message:

Add multiple files submission for convenient.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/mwsubmitter/CHANGELOG

    r671 r680  
     12006-10-27 
     2v0.1.1 
     31. Added support for multiple files submission. 
     42. Removed -d option and now the sample directory is given as a arguement. 
     5 
    162006-10-18 
    27v0.1.0 
     
    611v0.0.9b 
    7121. Added -D option for future HoneyBow shell-script. 
    8 2. Fixed a 'bug' caused by GOTEK client while submitting empty file. 
    9 3. Fixed a submitting display bug. 
     132. Fixed a 'bug' caused by GOTEK client while submits empty file. 
     143. Fixed a submission display bug. 
    10154. Added GOTEK client recompilation in install script. 
  • trunk/mwsubmitter/src/mwsubmitter

    r671 r680  
    66# Copyright (C) 2006 Artmeis: Chinese Honeynet Project 
    77# 
    8 # Version 0.1.0 
     8# Version 0.1.1 
    99 
    1010# This program is free software; you can redistribute it and/or modify 
     
    2626# Usage: mwsubmitter [-c config-file] [-D] -b 
    2727#                mwsubmitter [-c config-file] [-t cycle] -m 
    28 #        mwsubmitter -s server-address [-p port] [-D] -d scan-dir -u user-name -k key-file 
     28#        mwsubmitter -s server-address [-p port] [-D] -u user-name -k key-file {sample-dir|sample-file[s]} 
    2929#        mwsubmitter -v 
    3030#        mwsubmitter -h 
    3131# 
    32 #        -s MwCollector (or any other G.O.T.E.K. campatible server) address. 
    33 #                -p MwCollector's port. 
     32#        -s G.O.T.E.K. server address. 
     33#                -p G.O.T.E.K. server port. 
    3434#        -c Use <config-file> as monitor directory set, use $HOME/.mwsubmitter/config 
    3535#                       as default. Read MwSubmitter Manual for more information about MwSubmitter's  
     
    3939#                -t Scan cycle in monitor mode. 
    4040#                -m Use monitor mode, implicitly contain -D option. 
    41 #        -d Scan directory, scan only once. 
    4241#        -u User name for submit authentication. 
    4342#        -k Correspond key file for submit authentication. 
     
    4847# 
    4948#   Please write to songchengyu@icst.pku.edu.cn 
     49#                       or cs@mwcollect.org 
    5050# 
    5151########################################################################### 
     
    5353#! /bin/bash 
    5454 
    55 version="0.1.0
     55version="0.1.1
    5656 
    5757submit_sample() { 
    58         local user="$1" 
    59         local keyfile="$2" 
    60         local sample_dir="$3" 
    61          
     58        local sample_dir="$1" 
     59        local file 
     60        local line 
     61        local new_name 
     62 
    6263        #if there are samples 
    6364        if [ -n "$(ls -1 "$sample_dir")" ]; then 
     
    7677                 
    7778                echo "Submitting..." 
    78                 for file in "$sample_dir"/* 
    79                 do 
     79                for file in "$sample_dir"/*; do 
    8080                        if [ ! -s "$file" ]; then 
     81                        echo "Clean empty file $file" 
    8182                                rm -f "$file" 
    82                                 continue 
    83                         fi 
    84                          
    85                         echo -n "Submitting $file ... " 
    86                         if [ -z $port ]; then 
    87                                 "$gotekc_path" -k "$keyfile" -u "$user" -s "$server" -f "$file" 2>&1 > /dev/null 
    88                         else 
    89                                 "$gotekc_path" -k "$keyfile" -u "$user" -s "$server" -p "$port" -f "$file" 2>&1 > /dev/null 
    90                         fi 
    91                         result=$? 
    92                          
    93                         if (($result == 0 || $result == 2)); then 
    94                                 echo "Succeed" 
    95                                  
    96                                 if (($doDelete == 1)); then 
    97                                         rm -f "$file" 
    98                                 fi 
    99                         else 
    100                                 echo "Failed" 
    101  
    102                                 if ((monitor == 1)); then 
    103                                         if [ -z "$(echo "$file" | grep '#_#')" ]; then 
    104                                                 new_file="$file""#_#"`date +%G%m%d%H%M` 
    105                                                 mv "$file" "$new_file" 
    106                                         fi 
    107                                 fi 
    108                         fi 
    109  
     83                        continue 
     84                fi 
     85 
     86                        submit_file "$file" 
    11087                done 
    11188        fi 
     
    11390} 
    11491 
     92submit_file (){ 
     93        local file="$1" 
     94        local new_file 
     95 
     96        echo -n "Submitting $file ... " 
     97         
     98        if [ -z $port ]; then 
     99                "$gotekc_path" --key "$key" --user "$name" --server "$server" --file "$file" 2>&1 > /dev/null 
     100        else 
     101                "$gotekc_path" --key "$key" --user "$name" --server "$server" --port "$port" --file "$file" 2>&1 > /dev/null 
     102        fi 
     103        result=$? 
     104 
     105    if (($result == 0 || $result == 2)); then 
     106        echo "Succeed" 
     107 
     108        if (($doDelete == 1)); then 
     109                rm -f "$1" 
     110                fi 
     111    else 
     112        echo "Failed" 
     113 
     114        if ((monitor == 1)); then 
     115            if [ -z "$(echo "$file" | grep '#_#')" ]; then 
     116                new_file="$file""#_#"`date +%G%m%d%H%M` 
     117                mv "$file" "$new_file" 
     118            fi 
     119        fi 
     120    fi 
     121} 
     122 
    115123process (){ 
     124        local dir 
     125         
    116126        while read server port; do 
    117127                if [ -z "$(echo $server | grep ^#)" ]; then 
     
    135145                fi 
    136146                 
    137                 submit_sample "$name" "$key" "$dir" 
     147                submit_sample "$dir" 
    138148        done 
    139149} 
     
    142152        echo "Usage: $PROGRAM [-c config-file] [-D] -b" 
    143153        echo "       $PROGRAM [-c config-file] [-t cycle] -m" 
    144         echo "       $PROGRAM -s server-address [-p port] [-D] -d scan-dir -u user-name -k key-file
     154        echo "       $PROGRAM -s server-address [-p port] [-D] -u user-name -k key-file {dir|file[s]}
    145155        echo "       $PROGRAM -v" 
    146156        echo "       $PROGRAM -h" 
    147         echo -e "\n\t-s MwCollector (or any other G.O.T.E.K. campatible server) address." 
    148         echo -e "\t-p MwCollector port." 
     157        echo -e "\n\t-s G.O.T.E.K. server address." 
     158        echo -e "\t-p G.O.T.E.K. server port." 
    149159        echo -e "\t-c Use <config-file> as monitor directory set, use $HOME/.mwsubmitter/config. \n\t   as default. Read MwSubmitter Manual for more information about MwSubmitter's \n\t   config-file." 
    150160        echo -e "\t-D Delete samples after successful submit." 
     
    152162        echo -e "\t-t Scan cycle in monitor mode." 
    153163        echo -e "\t-m Use monitor mode, implicitly contain -D option." 
    154         echo -e "\t-d Scan directory, scan only once." 
    155164        echo -e "\t-u User name for submit authentication." 
    156165        echo -e "\t-k Correspond key file for submit authentication." 
     
    186195fi 
    187196 
    188 while getopts ":s:p:c:bt:md:u:k:Dvh" opt; do 
     197while getopts ":s:p:c:bt:mu:k:Dvh" opt; do 
    189198        case $opt in 
    190199                s  )    server="$OPTARG" ;; 
     
    201210 
    202211                m  )    monitor=1 ;; 
    203  
    204                 d  )    dir="$OPTARG" ;; 
    205212                 
    206213                u  )    name="$OPTARG" ;; 
     
    225232cycle=${cycle:-1200} 
    226233cfg_file=${cfg_file:-"$HOME/.mwsubmitter/config"} 
    227 gotekc_path=/usr/bin/gotekc 
     234gotekc_path="/usr/local/bin/gotekc" 
    228235doDelete=${doDelete:-0} 
    229236 
     
    233240 
    234241if [ ! -x $gotekc_path ]; then 
    235         echo "$PROGRAM: G.O.T.E.K. client not found, please reinstall MwSubmitter." 
     242        echo "$PROGRAM: G.O.T.E.K. client not found, please reinstall gotekc." 
    236243        exit 1 
    237244fi 
     
    266273fi 
    267274 
    268 if [ -z $dir ]; then 
    269         echo "$PROGRAM: scan directory not specified." 
    270         exit 1 
    271 fi 
    272275if [ -z $name ]; then 
    273276        echo "$PROGRAM: user name not specified." 
    274277        exit 1 
    275278fi 
    276 if [ -z $key ]; then 
     279if [ -z "$key" ]; then 
    277280        echo "$PROGRAM: key file not specified" 
    278         exit 1 
    279 fi 
    280  
    281 if [ ! -d "$dir" ]; then 
    282         echo "$PROGRAM: scan directory does not exist" 
    283281        exit 1 
    284282fi 
     
    289287fi 
    290288 
    291 submit_sample "$name" "$key" "$dir" 
    292 date 
     289if [ -z "$*" ]; then 
     290        echo "$PROGRAM: no submitter dir or file specified" 
     291        exit 1 
     292fi 
     293 
     294if [ -d "$1" ]; then 
     295        submit_sample "$1" 
     296        exit 0 
     297fi 
     298 
     299for file in "$@"; do 
     300        if [ ! -e "$file" ]; then 
     301                echo "$PROGRAM: $file does not exist" 
     302                continue 
     303        fi 
     304        if [ ! -s "$file" ]; then 
     305                echo "Ignore empty file $file" 
     306                continue 
     307        fi 
     308        submit_file "$file" 
     309done