Check-in [17d801292a]
Overview
SHA1:17d801292a250da6a8b48dbd6b29ef8a2c3a94b2
Date: 2017-03-22 21:11:22
User: rkeene
Comment:Support wrapping for long lines
Timelines: family | ancestors | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | folders | manifest
Tags And Properties
Context
2017-03-22
21:11
[17d801292a] Leaf: Support wrapping for long lines (user: rkeene, tags: trunk)
2016-03-15
19:53
[fb8686074b] Better error handling without a PKCS#11 module (user: rkeene, tags: trunk)
Changes

Modified hunter2 from [6da8c360ca] to [7d93abb92c].

    21     21   # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
    22     22   # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 
    23     23   # TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
    24     24   # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
    25     25   # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
    26     26   # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
    27     27   # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
           28  +
           29  +set ::defaultWrapLength 60
    28     30   
    29     31   set passwordFile [lindex $argv 0]
    30     32   set action [lindex $argv 1]
    31     33   
    32     34   set validCommands [list "listLocalKeys" "listPasswords" "listAvailablePasswords" "listUsers" "addUser" "addPassword" "authorizeUser" "authorizeUsers" "deauthorizeUser" "deauthorizeUsers" "getPassword" "updatePassword" "deletePassword" "help" "whoami"]
    33     35   
    34     36   proc _argDescription {command argName} {
................................................................................
    51     53   		"args" {
    52     54   			return "userList - A list of usernames"
    53     55   		}
    54     56   	}
    55     57   
    56     58   	return "<UNKNOWN>"
    57     59   }
           60  +
           61  +proc _wrapString {string width {prefix ""}} {
           62  +	set newString ""
           63  +
           64  +	set prefixWidth [string length $prefix]
           65  +	set width [expr {$width - $prefixWidth}]
           66  +	while {[string length $string] > 0} {
           67  +		if {[string length $string] > $width} {
           68  +			set subStringIndex [string last " " $string $width]
           69  +
           70  +			if {$subStringIndex == -1} {
           71  +				set subStringIndex [string first " " $string]
           72  +			}
           73  +		} else {
           74  +			set subStringIndex -1
           75  +		}
           76  +
           77  +		if {$subStringIndex == -1} {
           78  +			set subStringIndex end
           79  +		}
           80  +		set subString [string trim [string range $string 0 $subStringIndex]]
           81  +		set string [string trim [string range $string $subStringIndex+1 end]]
           82  +
           83  +		append newString $prefix
           84  +		append newString $subString
           85  +		if {$string ne ""} {
           86  +			append newString "\n"
           87  +		}
           88  +	}
           89  +
           90  +	return $newString
           91  +}
    58     92   
    59     93   proc _printHelp {channel command} {
    60     94   	if {$command == ""} {
    61     95   		puts $channel "Usage: hunter2 <passwordFile> <action> \[<actionArgs...>\]"
    62     96   		puts $channel ""
    63     97   		puts $channel "Actions:"
    64         -		puts $channel "    [join $::validCommands {, }]"
           98  +		puts $channel "[_wrapString [join $::validCommands {, }] $::defaultWrapLength {    }]"
    65     99   		puts $channel ""
    66    100   		puts $channel "    hunter2 <file> help <action>    for help with an action"
    67    101   	} else {
    68    102   		set args [info args $command]
    69    103   		set printArgs [list]
    70    104   		foreach arg $args {
    71    105   			if {$arg == "args"} {
................................................................................
   574    608   
   575    609   			lappend passwordNames $row(name)
   576    610   		}
   577    611   	}
   578    612   
   579    613   
   580    614   	foreach passwordName $passwordNames {
   581         -		puts "$passwordName - [join [_getUsersForPassword [list $passwordName]] {, }]"
          615  +		puts "[_wrapString [join [_getUsersForPassword [list $passwordName]] {, }] $::defaultWrapLength "$passwordName - "]"
   582    616   	}
   583    617   
   584    618   	set ::saveRequired 0
   585    619   }
   586    620   
   587    621   proc listPasswords {} {
   588    622   	db eval {SELECT DISTINCT name FROM passwords;} row {
   589         -		puts "$row(name) - [join [_getUsersForPassword [list $row(name)]] {, }]"
          623  +		puts "[_wrapString [join [_getUsersForPassword [list $row(name)]] {, }] $::defaultWrapLength "$row(name) - "]"
   590    624   	}
   591    625   
   592    626   	set ::saveRequired 0
   593    627   }
   594    628   
   595    629   proc listUsers {} {
   596    630   	db eval {SELECT DISTINCT name FROM users;} row {
   597         -		puts "$row(name) - [join [_getPasswordsForUser [list $row(name)]] {, }]"
          631  +		puts "[_wrapString [join [_getPasswordsForUser [list $row(name)]] {, }] $::defaultWrapLength "$row(name) - "]"
   598    632   	}
   599    633   
   600    634   	set ::saveRequired 0
   601    635   }
   602    636   
   603    637   proc addUser {userName key} {
   604    638   	set keyRaw [binary decode base64 $key]