-
Notifications
You must be signed in to change notification settings - Fork 10
/
dialogs.go
203 lines (189 loc) · 6.36 KB
/
dialogs.go
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
package main
import (
"bytes"
"fmt"
"html"
"runtime"
"strings"
"github.com/dustin/go-humanize"
"github.com/spf13/afero"
)
func selOpt(s string, f ...struct{ v, n string }) string {
var o []string
var m = make(map[string]string)
m[s] = "SELECTED"
m[""] = "DISABLED"
for _, i := range f {
o = append(o, fmt.Sprintf("<OPTION VALUE=\"%v\" %v>%v</OPTION>", i.v, m[i.v], i.n))
}
return strings.Join(o, "\n")
}
func (r *wfmRequest) prompt(action string, mul []string) {
header(r.w, r.uDir, r.eSort, "", r.modern)
r.w.Write([]byte(`
<TABLE WIDTH="100%" HEIGHT="90%" BORDER="0" CELLSPACING="0" CELLPADDING="0"><TR><TD VALIGN="MIDDLE" ALIGN="CENTER">
<BR> <BR><P>
<TABLE WIDTH="400" BGCOLOR="#F0F0F0" BORDER="0" CELLSPACING="0" CELLPADDING="1" CLASS="tbr">
<TR><TD COLSPAN="2" BGCOLOR="#004080"><FONT COLOR="#FFFFFF"> ` + action + `</FONT></TD></TR>
<TR><TD WIDTH="30"> </TD><TD>
`))
switch action {
case "mkdir":
r.w.Write([]byte(`
<BR>Enter name for the new directory:<P>
<INPUT TYPE="TEXT" NAME="file" SIZE="40" VALUE="">
`))
case "mkfile":
r.w.Write([]byte(`
<BR>Enter name for the new file:<P>
<INPUT TYPE="TEXT" NAME="file" SIZE="40" VALUE="">
`))
case "mkurl":
r.w.Write([]byte(`
<BR>Enter name for the new url file:<P>
<INPUT TYPE="TEXT" NAME="file" SIZE="40" VALUE="">
<BR>Destination URL:<P>
<INPUT TYPE="TEXT" NAME="url" SIZE="40" VALUE="">
`))
case "rename":
eBn := html.EscapeString(r.uFbn)
r.w.Write([]byte(`
<BR>Enter new name for the file <B>` + eBn + `</B>:<P>
<INPUT TYPE="TEXT" NAME="dst" SIZE="40" VALUE="` + eBn + `">
<INPUT TYPE="HIDDEN" NAME="file" VALUE="` + eBn + `">
`))
case "move":
eBn := html.EscapeString(r.uFbn)
r.w.Write([]byte(`
<BR>Select destination folder for <B>` + eBn + `</B>:<P>
<SELECT NAME="dst">
` + upDnDir(r.uDir, "", r.fs) + `</SELECT>
<INPUT TYPE="HIDDEN" NAME="file" VALUE="` + eBn + `">
`))
case "delete":
var a string
fi, _ := r.fs.Stat(r.uDir + "/" + r.uFbn)
if fi.IsDir() {
a = "directory - recursively"
} else {
a = "file, size " + humanize.Bytes(uint64(fi.Size()))
}
eBn := html.EscapeString(r.uFbn)
r.w.Write([]byte(`
<BR>Are you sure you want to delete:<BR><B>` + eBn + `</B>
(` + a + `)<P>
<INPUT TYPE="HIDDEN" NAME="file" VALUE="` + eBn + `">
`))
case "multi_delete":
fmt.Fprintf(r.w, " <BR>Are you sure you want to delete from <B>%v</B>:<P><UL>\n", html.EscapeString(r.uDir))
for _, f := range mul {
fE := html.EscapeString(f)
fmt.Fprintf(r.w, "<INPUT TYPE=\"HIDDEN\" NAME=\"mulf\" VALUE=\"%s\">\n"+
"<LI TYPE=\"square\">%v</LI>\n", fE, fE)
}
fmt.Fprintln(r.w, "</UL><P>")
case "multi_move":
fmt.Fprintf(r.w, " <BR>Move from: <B>%v</B><P>\n"+
"To: <SELECT NAME=\"dst\">%v</SELECT><P>\n<UL>Items:<P>\n",
html.EscapeString(r.uDir),
upDnDir(r.uDir, r.uFbn, r.fs),
)
for _, f := range mul {
fE := html.EscapeString(f)
fmt.Fprintf(r.w, "<INPUT TYPE=\"HIDDEN\" NAME=\"mulf\" VALUE=\"%s\">\n"+
"<LI TYPE=\"square\">%v</LI>\n", fE, fE)
}
fmt.Fprintln(r.w, "</UL><P>")
}
r.w.Write([]byte(`
</TD></TR>
<TR><TD COLSPAN="2">
<P><CENTER>
<INPUT TYPE="SUBMIT" VALUE=" OK " NAME="OK" ` + disTag[r.rwAccess] + `>
<INPUT TYPE="SUBMIT" VALUE=" Cancel " NAME="cancel">
<INPUT TYPE="HIDDEN" NAME="fn" VALUE="` + action + `">
</CENTER>
</TD></TR><TR><TD COLSPAN="2"> </TD></TR>
</TABLE>
</TD></TR></TABLE>
`))
footer(r.w)
}
func (r *wfmRequest) editText() {
fi, err := r.fs.Stat(r.uDir + "/" + r.uFbn)
if err != nil {
htErr(r.w, "Unable to get file attributes", err)
return
}
if fi.Size() > 1<<20 {
htErr(r.w, "edit", fmt.Errorf("the file is too large for editing"))
return
}
f, err := afero.ReadFile(r.fs, r.uDir+"/"+r.uFbn)
if err != nil {
htErr(r.w, "Unable to read file", err)
return
}
le := *defLe
if bytes.IndexByte(f, '\r') != -1 {
le = "CRLF"
}
header(r.w, r.uDir, r.eSort, `html, body, table, textarea, form { box-sizing: border-box; height:98%; }`, r.modern)
r.w.Write([]byte(`
<TABLE BGCOLOR="#EEEEEE" BORDER="0" CELLSPACING="0" CELLPADDING="5" STYLE="width: 100%; height: 100%;">
<TR STYLE="height:1%;">
<TD ALIGN="LEFT" VALIGN="MIDDLE" BGCOLOR="#CCCCCC">File Editor: ` + html.EscapeString(r.uFbn) + `</TD>
<TD BGCOLOR="#CCCCCC" ALIGN="RIGHT">
Line Endings:
<SELECT NAME="crlf">
` + selOpt(le, []struct{ v, n string }{
{"LF", "LF (Unix)"},
{"CRLF", "CRLF (Windows)"},
}...) + `
</SELECT>
</TD>
</TR>
<TR STYLE="height:98%;">
<TD COLSPAN="2" ALIGN="CENTER" VALIGN="MIDDLE" STYLE="height:100%;">
<TEXTAREA NAME="text" SPELLCHECK="false" COLS="80" ROWS="24" STYLE="width: 99%; height: 99%;">` + html.EscapeString(string(f)) + `</TEXTAREA><P>
</TD></TR><TR STYLE="height:1%;"><TD> </TD><TD ALIGN="RIGHT">
<INPUT TYPE="SUBMIT" NAME="save" VALUE="Save" ` + disTag[r.rwAccess] + `>
<INPUT TYPE="SUBMIT" NAME="cancel" VALUE="Cancel">
<INPUT TYPE="HIDDEN" NAME="dir" VALUE="` + html.EscapeString(r.uDir) + `">
<INPUT TYPE="HIDDEN" NAME="file" VALUE="` + html.EscapeString(r.uFbn) + `">
</TD></TR></TABLE>
`))
footer(r.w)
}
func (r *wfmRequest) about(ua string) {
header(r.w, r.uDir, r.eSort, "", r.modern)
r.w.Write([]byte(`
<TABLE WIDTH="100%" HEIGHT="90%" BORDER="0" CELLSPACING="0" CELLPADDING="0"><TR><TD VALIGN="MIDDLE" ALIGN="CENTER">
<BR> <BR><P>
<TABLE WIDTH="400" BGCOLOR="#F0F0F0" BORDER="0" CELLSPACING="0" CELLPADDING="1" CLASS="tbr">
<TR><TD COLSPAN="2" BGCOLOR="#004080"><FONT COLOR="#FFFFFF"> Web File Manager</FONT></TD></TR>
<TR><TD WIDTH="30"> </TD><TD ALIGN="LEFT"><BR>
WFM Version v` + vers + `<BR>
<A HREF="https://github.com/tenox7/wfm/">https://github.com/tenox7/wfm/</A><BR>
Written by Antoni Sawicki Et Al.<BR>
Copyright © 1994-2024 by Antoni Sawicki<BR>
`))
if *aboutRnt {
fmt.Fprintf(r.w, "Build: %v %v-%v<BR>Agent: %v<P>",
runtime.Version(),
runtime.GOARCH,
runtime.GOOS,
ua)
}
r.w.Write([]byte(`
</TD></TR>
<TR><TD COLSPAN="2">
<P><CENTER>
<INPUT TYPE="SUBMIT" VALUE=" OK " NAME="OK">
</CENTER>
</TD></TR><TR><TD COLSPAN="2"> </TD></TR>
</TABLE>
</TD></TR></TABLE>
`))
footer(r.w)
}