@@ -39,6 +39,7 @@ class Console::CommandDispatcher::Stdapi::Fs
39
39
@@upload_opts = Rex ::Parser ::Arguments . new (
40
40
"-h" => [ false , "Help banner." ] ,
41
41
"-r" => [ false , "Upload recursively." ] )
42
+
42
43
#
43
44
# Options for the ls command
44
45
#
@@ -52,6 +53,12 @@ class Console::CommandDispatcher::Stdapi::Fs
52
53
"-l" => [ false , "List in long format (default)" ] ,
53
54
"-R" => [ false , "Recursively list subdirectories encountered" ] )
54
55
56
+ #
57
+ # Options for the ls command
58
+ #
59
+ @@lls_opts = Rex ::Parser ::Arguments . new (
60
+ "-h" => [ false , "Help banner." ] )
61
+
55
62
#
56
63
# List of supported commands.
57
64
#
@@ -69,6 +76,7 @@ def commands
69
76
'lcd' => 'Change local working directory' ,
70
77
'lpwd' => 'Print local working directory' ,
71
78
'ls' => 'List files' ,
79
+ 'lls' => 'List local files' ,
72
80
'mkdir' => 'Make directory' ,
73
81
'pwd' => 'Print working directory' ,
74
82
'rm' => 'Delete the specified file' ,
@@ -93,6 +101,7 @@ def commands
93
101
'lcd' => [ ] ,
94
102
'lpwd' => [ ] ,
95
103
'ls' => [ 'stdapi_fs_stat' , 'stdapi_fs_ls' ] ,
104
+ 'lls' => [ ] ,
96
105
'mkdir' => [ 'stdapi_fs_mkdir' ] ,
97
106
'pwd' => [ 'stdapi_fs_getwd' ] ,
98
107
'rmdir' => [ 'stdapi_fs_delete_dir' ] ,
@@ -667,6 +676,92 @@ def cmd_ls(*args)
667
676
#
668
677
alias cmd_dir cmd_ls
669
678
679
+ def cmd_lls_help
680
+ print_line "Usage: lls [options]"
681
+ print_line
682
+ print_line "Lists contents of a local directory or file info"
683
+ print_line @@lls_opts . usage
684
+ end
685
+
686
+ #
687
+ # Get list local path information for lls command
688
+ #
689
+ def list_local_path ( path )
690
+ columns = [ 'Mode' , 'Size' , 'Type' , 'Last modified' , 'Name' ]
691
+ tbl = Rex ::Text ::Table . new (
692
+ 'Header' => "Listing Local: #{ path } " ,
693
+ 'SortIndex' => columns . index ( "Name" ) ,
694
+ 'SortOrder' => :forward ,
695
+ 'Columns' => columns )
696
+
697
+ items = 0
698
+
699
+ files = ::Dir . entries ( path )
700
+
701
+ files . each do |file |
702
+ file_path = ::File . join ( path , file )
703
+ m = ::File . stat ( file_path ) . mode
704
+ om = '%04o' % m
705
+ perms = ''
706
+
707
+ 3 . times {
708
+ perms = ( ( m & 01 ) == 01 ? 'x' : '-' ) + perms
709
+ perms = ( ( m & 02 ) == 02 ? 'w' : '-' ) + perms
710
+ perms = ( ( m & 04 ) == 04 ? 'r' : '-' ) + perms
711
+ m >>= 3
712
+ }
713
+
714
+ perm = "#{ om } /#{ perms } "
715
+ size = ::File . stat ( file_path ) . size
716
+ ftype = ::File . stat ( file_path ) . ftype [ 0 , 3 ]
717
+ mtime = ::File . stat ( file_path ) . mtime
718
+
719
+ row = [
720
+ perm ? perm : '' ,
721
+ size ? size . to_s : '' ,
722
+ ftype ? ftype [ 0 , 3 ] : '' ,
723
+ mtime ? mtime : '' ,
724
+ file
725
+ ]
726
+ if file != '.' && file != '..'
727
+ tbl << row
728
+ items += 1
729
+ end
730
+ end
731
+ if items > 0
732
+ print_line ( tbl . to_s )
733
+ else
734
+ print_line ( "No entries exist in #{ path } " )
735
+ end
736
+ end
737
+
738
+ #
739
+ # List local files
740
+ #
741
+ def cmd_lls ( *args )
742
+ path = ::Dir . pwd
743
+
744
+ # Parse the args
745
+ @@lls_opts . parse ( args ) { |opt , idx , val |
746
+ case opt
747
+ # Help and path
748
+ when "-h"
749
+ cmd_lls_help
750
+ return 0
751
+ when nil
752
+ path = val
753
+ end
754
+ }
755
+
756
+ list_local_path ( path )
757
+ end
758
+
759
+ #
760
+ # Alias the lls command to dir, for those of us who have windows muscle-memory
761
+ #
762
+ alias cmd_ldir cmd_lls
763
+
764
+
670
765
#
671
766
# Make one or more directory.
672
767
#
0 commit comments