aboutsummaryrefslogtreecommitdiff
path: root/dialogs.go
blob: 99479936926a3a2d3372326daf64c78a87863658 (plain)
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
package main

import (
	"fmt"
	"html"
	"io/ioutil"
	"os"
	"runtime"

	"github.com/dustin/go-humanize"
)

func (r *wfmRequest) prompt(action string, mul []string) {
	header(r.w, r.uDir, r.eSort, "")

	r.w.Write([]byte(`
    <TABLE WIDTH="100%" HEIGHT="90%" BORDER="0" CELLSPACING="0" CELLPADDING="0"><TR><TD VALIGN="MIDDLE" ALIGN="CENTER">
    <BR>&nbsp;<BR><P>
    <TABLE WIDTH="400" BGCOLOR="#F0F0F0" BORDER="0" CELLSPACING="0" CELLPADDING="1" CLASS="tbr">
      <TR><TD COLSPAN="2" BGCOLOR="#004080"><FONT COLOR="#FFFFFF">&nbsp; ` + action + `</FONT></TD></TR>
      <TR><TD WIDTH="30">&nbsp;</TD><TD>
    `))

	switch action {
	case "mkdir":
		r.w.Write([]byte(`
        &nbsp;<BR>Enter name for the new directory:<P>
        <INPUT TYPE="TEXT" NAME="file" SIZE="40" VALUE="">
        `))
	case "mkfile":
		r.w.Write([]byte(`
        &nbsp;<BR>Enter name for the new file:<P>
        <INPUT TYPE="TEXT" NAME="file" SIZE="40" VALUE="">
        `))
	case "mkurl":
		r.w.Write([]byte(`
        &nbsp;<BR>Enter name for the new url file:<P>
        <INPUT TYPE="TEXT" NAME="file" SIZE="40" VALUE="">
        &nbsp;<BR>Destination URL:<P>
        <INPUT TYPE="TEXT" NAME="url" SIZE="40" VALUE="">
        `))
	case "rename":
		eBn := html.EscapeString(r.uFbn)
		r.w.Write([]byte(`
        &nbsp;<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(`
		&nbsp;<BR>Select destination folder for <B>` + eBn + `</B>:<P>
		<SELECT NAME="dst">
		` + upDnDir(r.uDir, "") + `</SELECT>
		<INPUT TYPE="HIDDEN" NAME="file" VALUE="` + eBn + `">
		`))
	case "delete":
		var a string
		fi, _ := os.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(`
        &nbsp;<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, "&nbsp;<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, "&nbsp;<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),
		)
		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">&nbsp;
    <INPUT TYPE="SUBMIT" VALUE=" Cancel " NAME="cancel">
    <INPUT TYPE="HIDDEN" NAME="fn" VALUE="` + action + `">
    </CENTER>
    </TD></TR><TR><TD COLSPAN="2">&nbsp;</TD></TR>
    </TABLE>
    </TD></TR></TABLE>
    `))

	footer(r.w)
}

func (r *wfmRequest) editText() {
	fi, err := os.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 := ioutil.ReadFile(r.uDir + "/" + r.uFbn)
	if err != nil {
		htErr(r.w, "Unable to read file", err)
		return
	}
	header(r.w, r.uDir, r.eSort, `html, body, table, textarea, form { box-sizing: border-box; height:98%; }`)
	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">&nbsp;</TD>
    </TR>
    <TR STYLE="height:99%;">
    <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>
    <INPUT TYPE="SUBMIT" NAME="save" VALUE="Save" STYLE="float: left;">
	<INPUT TYPE="SUBMIT" NAME="cancel" VALUE="Cancel" STYLE="float: left; margin-left: 10px">
    <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.w.Write([]byte(`
    <TABLE WIDTH="100%" HEIGHT="90%" BORDER="0" CELLSPACING="0" CELLPADDING="0"><TR><TD VALIGN="MIDDLE" ALIGN="CENTER">
    <BR>&nbsp;<BR><P>
    <TABLE WIDTH="400" BGCOLOR="#F0F0F0" BORDER="0" CELLSPACING="0" CELLPADDING="1" CLASS="tbr">
      <TR><TD COLSPAN="2" BGCOLOR="#004080"><FONT COLOR="#FFFFFF">&nbsp; Web File Manager</FONT></TD></TR>
      <TR><TD WIDTH="30">&nbsp;</TD><TD><BR>
	  WFM Version v` + vers + `<BR>
	  Developed by Antoni Sawicki Et Al.<BR>
	  <A HREF="https://github.com/tenox7/wfm/">https://github.com/tenox7/wfm/</A><BR>
	  Copyright &copy; 1994-2018 by Antoni Sawicki<BR>
	  Copyright &copy; 2018-2022 by Google LLC<BR>
	  This is not an official Google product.<P>
	`))

	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">&nbsp;
    </CENTER>
    </TD></TR><TR><TD COLSPAN="2">&nbsp;</TD></TR>
    </TABLE>
    </TD></TR></TABLE>
    `))

	footer(r.w)
}