-
Notifications
You must be signed in to change notification settings - Fork 0
/
stat.src
144 lines (117 loc) · 3.02 KB
/
stat.src
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
if params.len == 0 then exit("No target.")
HumanOn = 0
DebugOn = 0
filepaths = []
tocolor = function(color)
return "<color="+color+">"+self.str+"</color>"
end function
convert = function(text)
obj = {}
obj.str = str(text)
obj.tocolor = @tocolor
return obj
end function
debug = function(msg)
if DebugOn == 1 then
print( convert("[DEBUG] "+msg).tocolor("purple") )
end if
end function
for parm in params
if parm == "-h" then
HumanOn = 1
continue
end if
if parm == "-d" then
DebugOn = 1
continue
end if
if parm.indexOf("/") == 0 then
if typeof(get_shell.host_computer.File(parm)) != "file" then
debug(parm+" is invalid")
continue
else if typeof(get_shell.host_computer.File(parm)) == "file" then
filepaths.push(parm)
end if
end if
if parm.indexOf("/") != 0 then
p = parent_path(launch_path)+"/"+parm
if typeof(get_shell.host_computer.File(p)) != "file" then
debug(p+" is invalid")
continue
else if typeof(get_shell.host_computer.File(p)) == "file" then
filepaths.push(p)
end if
end if
end for
debug("Paths: "+filepaths)
if filepaths.len == 0 then
debug("No valid paths")
exit()
end if
print(char(32))
for filepath in filepaths
map = {}
map["file"] = get_shell.host_computer.File(filepath).path
map["acc"] = get_shell.host_computer.File(filepath).permissions
map["own"] = get_shell.host_computer.File(filepath).owner
map["grp"] = get_shell.host_computer.File(filepath).group
HumanSize = function()
s = get_shell.host_computer.File(filepath).size.to_int
h = round(s / 1000000,2)
o = str(h)+"MB"
return o
end function
if HumanOn == 1 then
map["size"] = HumanSize
else if HumanOn == 0 then
map["size"] = get_shell.host_computer.File(filepath).size
end if
octal = function()
acc = get_shell.host_computer.File(filepath).permissions.values
perm = {}
perm["typ"] = acc.pull
perm["own"] = acc.pull+acc.pull+acc.pull
perm["grp"] = acc.pull+acc.pull+acc.pull
perm["oth"] = acc.pull+acc.pull+acc.pull
r = 4
w = 2
x = 1
octa = {}
for p in perm.indexes
if perm[p] == "rwx" then
octa[p] = r+w+x
else if perm[p] == "rw-" then
octa[p] = r+w
else if perm[p] == "r-x" then
octa[p] = r+x
else if perm[p] == "r--" then
octa[p] = r
else if perm[p] == "-wx" then
octa[p] = w+x
else if perm[p] == "-w-" then
octa[p] = w
else if perm[p] == "--x" then
octa[p] = x
else if perm[p] == "---" then
octa[p] = 0
end if
end for
if perm["typ"] == "d" then octa["typ"] = 1
if perm["typ"] == "-" then octa["typ"] = 0
obj = str(octa["typ"]) + str(octa["own"]) + str(octa["grp"]) + str(octa["oth"])
return obj
end function
type = octal.values[0].to_int
if type == 1 then
map["type"] = "Folder"
else if get_shell.host_computer.File(filepath).is_binary then
map["type"] = "Binary"
else
map["type"] = "Text"
end if
print("File: "+map["file"])
print("Size: "+map["size"]+char(32)*3+"Type: "+map["type"])
print("Owner: "+map["own"]+char(32)*3+"Group: "+map["grp"])
print("Access: ("+map["acc"]+"/"+octal+")")
print()
end for