@@ -690,6 +690,13 @@ def cmd_lls_help
690
690
# Get list local path information for lls command
691
691
#
692
692
def list_local_path ( path , sort , order )
693
+ if !::File . directory? ( path )
694
+ perms = pretty_perms ( path )
695
+ stat = ::File . stat ( path )
696
+ print_line ( "#{ perms } #{ stat . size } #{ stat . ftype [ 0 , 3 ] } #{ stat . mtime } #{ path } " )
697
+ return
698
+ end
699
+
693
700
columns = [ 'Mode' , 'Size' , 'Type' , 'Last modified' , 'Name' ]
694
701
tbl = Rex ::Text ::Table . new (
695
702
'Header' => "Listing Local: #{ path } " ,
@@ -698,32 +705,19 @@ def list_local_path(path, sort, order)
698
705
'Columns' => columns )
699
706
700
707
items = 0
701
-
702
708
files = ::Dir . entries ( path )
703
709
704
710
files . each do |file |
705
711
file_path = ::File . join ( path , file )
706
- m = ::File . stat ( file_path ) . mode
707
- om = '%04o' % m
708
- perms = ''
709
-
710
- 3 . times {
711
- perms = ( ( m & 01 ) == 01 ? 'x' : '-' ) + perms
712
- perms = ( ( m & 02 ) == 02 ? 'w' : '-' ) + perms
713
- perms = ( ( m & 04 ) == 04 ? 'r' : '-' ) + perms
714
- m >>= 3
715
- }
716
-
717
- perm = "#{ om } /#{ perms } "
718
- size = ::File . stat ( file_path ) . size
719
- ftype = ::File . stat ( file_path ) . ftype [ 0 , 3 ]
720
- mtime = ::File . stat ( file_path ) . mtime
712
+
713
+ perms = pretty_perms ( file_path )
714
+ stat = ::File . stat ( file_path )
721
715
722
716
row = [
723
- perm ? perm : '' ,
724
- size ? size . to_s : '' ,
725
- ftype ? ftype [ 0 , 3 ] : '' ,
726
- mtime ? mtime : '' ,
717
+ perms ? perms : '' ,
718
+ stat . size ? stat . size . to_s : '' ,
719
+ stat . ftype ? stat . ftype [ 0 , 3 ] : '' ,
720
+ stat . mtime ? stat . mtime : '' ,
727
721
file
728
722
]
729
723
if file != '.' && file != '..'
@@ -738,6 +732,23 @@ def list_local_path(path, sort, order)
738
732
end
739
733
end
740
734
735
+ # Code from prettymode in lib/rex/post/file_stat.rb
736
+ # adapted for local file usage
737
+ def pretty_perms ( path )
738
+ m = ::File . stat ( path ) . mode
739
+ om = '%04o' % m
740
+ perms = ''
741
+
742
+ 3 . times {
743
+ perms = ( ( m & 01 ) == 01 ? 'x' : '-' ) + perms
744
+ perms = ( ( m & 02 ) == 02 ? 'w' : '-' ) + perms
745
+ perms = ( ( m & 04 ) == 04 ? 'r' : '-' ) + perms
746
+ m >>= 3
747
+ }
748
+
749
+ return "#{ om } /#{ perms } "
750
+ end
751
+
741
752
#
742
753
# List local files
743
754
#
@@ -774,7 +785,6 @@ def cmd_lls(*args)
774
785
#
775
786
alias cmd_ldir cmd_lls
776
787
777
-
778
788
#
779
789
# Make one or more directory.
780
790
#
0 commit comments