Skip to content

Commit

Permalink
ftp/sftp switch at add cloud dialog.
Browse files Browse the repository at this point in the history
  • Loading branch information
schwarzlichtbezirk committed Apr 22, 2023
1 parent def674d commit 0d97554
Show file tree
Hide file tree
Showing 16 changed files with 150 additions and 38 deletions.
10 changes: 7 additions & 3 deletions aec.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,13 @@ const (

AECcldaddnoacc
AECcldaddnodata
AECcldaddnodial
AECcldaddnocred
AECcldaddroot
AECcldaddftpdial
AECcldaddftpcred
AECcldaddftproot
AECcldaddsftpdial
AECcldaddsftpcli
AECcldaddsftppwd
AECcldaddsftproot

// cloud/del

Expand Down
81 changes: 64 additions & 17 deletions api-profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import (
"path"
"strconv"
"strings"
"time"

"github.com/jlaffaye/ftp"
"github.com/pkg/sftp"
"golang.org/x/crypto/ssh"
)

// APIHANDLER
Expand Down Expand Up @@ -159,6 +162,7 @@ func cldaddAPI(w http.ResponseWriter, r *http.Request, aid, uid ID_t) {
var arg struct {
XMLName xml.Name `json:"-" yaml:"-" xml:"arg"`

Scheme string `json:"scheme" yaml:"scheme" xml:"scheme"`
Host string `json:"host" yaml:"host" xml:"host"`
Port int `json:"port" yaml:"port" xml:"port"`
Login string `json:"login,omitempty" yaml:"login,omitempty" xml:"login,omitempty"`
Expand Down Expand Up @@ -203,29 +207,72 @@ func cldaddAPI(w http.ResponseWriter, r *http.Request, aid, uid ID_t) {
host += ":" + strconv.Itoa(arg.Port)
}
var ftpaddr = (&url.URL{
Scheme: "ftp",
Scheme: arg.Scheme,
User: url.UserPassword(arg.Login, arg.Password),
Host: host,
}).String()

var session = xormStorage.NewSession()
defer session.Close()

var conn *ftp.ServerConn
if conn, err = ftp.Dial(host, ftp.DialWithTimeout(cfg.DialTimeout)); err != nil {
WriteError(w, r, http.StatusNotFound, err, AECcldaddnodial)
return
}
defer conn.Quit()
if err = conn.Login(arg.Login, arg.Password); err != nil {
WriteError(w, r, http.StatusNotFound, err, AECcldaddnocred)
return
}
var (
size int64
mtime time.Time
)
switch arg.Scheme {
case "ftp":
var conn *ftp.ServerConn
if conn, err = ftp.Dial(host, ftp.DialWithTimeout(cfg.DialTimeout)); err != nil {
WriteError(w, r, http.StatusNotFound, err, AECcldaddftpdial)
return
}
defer conn.Quit()
if err = conn.Login(arg.Login, arg.Password); err != nil {
WriteError(w, r, http.StatusNotFound, err, AECcldaddftpcred)
return
}

var root *ftp.Entry
if root, err = conn.GetEntry(""); err != nil {
WriteError(w, r, http.StatusNotFound, err, AECcldaddroot)
return
var root *ftp.Entry
if root, err = conn.GetEntry(""); err != nil {
WriteError(w, r, http.StatusNotFound, err, AECcldaddftproot)
return
}
size, mtime = int64(root.Size), root.Time

case "sftp":
var conn *ssh.Client
var config = &ssh.ClientConfig{
User: arg.Login,
Auth: []ssh.AuthMethod{
ssh.Password(arg.Password),
},
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
}
if conn, err = ssh.Dial("tcp", host, config); err != nil {
WriteError(w, r, http.StatusNotFound, err, AECcldaddsftpdial)
return
}
defer conn.Close()

var client *sftp.Client
if client, err = sftp.NewClient(conn); err != nil {
WriteError(w, r, http.StatusNotFound, err, AECcldaddsftpcli)
return
}
defer client.Close()

var pwd string
if pwd, err = client.Getwd(); err != nil {
WriteError(w, r, http.StatusNotFound, err, AECcldaddsftppwd)
return
}

var root fs.FileInfo
if root, err = client.Lstat(path.Join(pwd, "/")); err != nil {
WriteError(w, r, http.StatusNotFound, err, AECcldaddsftproot)
return
}
size, mtime = int64(root.Size()), root.ModTime()
}

var fk FileKit
Expand All @@ -235,8 +282,8 @@ func cldaddAPI(w http.ResponseWriter, r *http.Request, aid, uid ID_t) {
fk.Static = false
fk.Name = name
fk.Type = FTcld
fk.Size = int64(root.Size)
fk.Time = root.Time
fk.Size = size
fk.Time = mtime

ret.FP = fk
ret.Added = acc.AddCloud(ftpaddr, name)
Expand Down
2 changes: 1 addition & 1 deletion frontend/build/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,6 @@
<!-- application bundle: leaflet, sha256 -->
<script src="/relm/app.bundle.js?0.10.0"></script>
<!-- page bundle -->
<script src="/relm/main.bundle.js?0.10.0"></script>
<script src="/relm/main.bundle.js?0.10.1"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion frontend/build/stat.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@
<!-- Vue.js release version -->
<script src="/plug/vue.global.prod.js?3.2.47"></script>
<!-- page bundle -->
<script src="/relm/stat.bundle.js?0.10.0"></script>
<script src="/relm/stat.bundle.js?0.10.1"></script>
</body>
</html>
22 changes: 21 additions & 1 deletion frontend/devmode/cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,12 @@ const VueCloudCard = {
data() {
return {
selfile: null, // current selected cloud
scheme: "ftp",
host: "", // path to disk to add
port: 21,
login: "",
password: "",
showpswd: false,
name: "",
hoststate: 0,
portstate: 0,
Expand All @@ -316,6 +318,14 @@ const VueCloudCard = {
this.pinned = this.$root.curpuid === CNID.remote;
}
},
scheme: {
handler(newval, oldval) {
switch (newval) {
case 'ftp': this.port = 21; break;
case 'sftp': this.port = 22; break;
}
}
}
},
computed: {
drvlist() {
Expand All @@ -336,10 +346,16 @@ const VueCloudCard = {
});
},

pswdstate() {
return this.showpswd ? 'visibility' : 'visibility_off';
},
clspswdstate() {
return this.showpswd ? 'text' : 'password';
},

clsfilelist() {
return listmoderow[this.listmode];
},

clsorder() {
return this.sortorder > 0
? 'arrow_downward'
Expand Down Expand Up @@ -426,6 +442,7 @@ const VueCloudCard = {
eventHub.emit('ajax', +1);
try {
const response = await fetchjsonauth("POST", `/id${this.$root.aid}/api/cloud/add`, {
scheme: this.scheme,
host: this.host,
port: this.port,
login: this.login,
Expand Down Expand Up @@ -476,6 +493,9 @@ const VueCloudCard = {
}
})();
},
onshowpswd() {
this.showpswd = !this.showpswd;
},
onchange(e) {
this.hoststate = 0;
this.portstate = 0;
Expand Down
2 changes: 1 addition & 1 deletion frontend/devmode/devmode.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This file is included only for developer mode linkage

const buildvers = "0.10.1";
const builddate = "2023.04.20";
const builddate = "2023.04.22";
console.info("version: %s, builton: %s", buildvers, builddate);
console.info("starts in developer mode");

Expand Down
6 changes: 3 additions & 3 deletions frontend/devmode/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@
<script src="/plug/sha256.min.js?0.9.0"></script>

<!-- common functionality used in all components -->
<script src="/devm/devmode.js?0.10.0"></script>
<script src="/devm/devmode.js?0.10.1"></script>
<script src="/devm/common.js?0.8.4"></script>
<script src="/devm/request.js?0.9.2"></script>
<!-- register Vue.js components -->
<script src="/devm/fileitem.js?0.10.0"></script>
<script src="/devm/cards.js?0.10.0"></script>
<script src="/devm/cards.js?0.10.1"></script>
<script src="/devm/mp3player.js?0.9.2"></script>
<script src="/devm/slider.js?0.10.0"></script>
<!-- load application script -->
<script src="/devm/mainpage.js?0.10.0"></script>
<script src="/devm/mainpage.js?0.10.1"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion frontend/devmode/relmode.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This file is included for release mode linkage

const buildvers = "0.10.1";
const builddate = "2023.04.19";
const builddate = "2023.04.22";
const devmode = false;

const traceajax = () => undefined;
Expand Down
4 changes: 4 additions & 0 deletions frontend/skin/blue/page.css
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ body {
background-color: rgba(232, 17, 35, 0.5);
}

select.bg-tool {
color: AliceBlue;
}

.bg-high {
background-color: rgba(255, 255, 255, 0.25);
}
Expand Down
4 changes: 4 additions & 0 deletions frontend/skin/coffee-beans/page.css
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ a, .btn-link {
background-color: rgba(232, 17, 35, 0.5);
}

select.bg-tool {
color: #e0a854;
}

.bg-high {
background-color: rgba(255, 255, 255, 0.25);
}
Expand Down
4 changes: 4 additions & 0 deletions frontend/skin/dark/page.css
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ body {
background-color: rgba(232, 17, 35, 0.5);
}

select.bg-tool {
color: White;
}

.bg-high {
background-color: rgba(255, 255, 255, 0.25);
}
Expand Down
4 changes: 4 additions & 0 deletions frontend/skin/light/page.css
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ body {
background-color: rgba(232, 17, 35, 0.5);
}

select.bg-tool {
color: #222;
}

.bg-high {
background-color: rgba(0, 0, 0, 0.25);
}
Expand Down
4 changes: 4 additions & 0 deletions frontend/skin/matrix/page.css
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ a, .btn-link {
background-color: rgba(24, 232, 24, 0.5);
}

select.bg-tool {
color: #00a000;
}

.bg-high {
background-color: rgba(255, 255, 255, 0.25);
}
Expand Down
4 changes: 4 additions & 0 deletions frontend/skin/neon/page.css
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ a, .btn-link {
background-color: rgba(232, 17, 35, 0.5);
}

select.bg-tool {
color: #00cc66;
}

.bg-high {
background-color: rgba(255, 255, 255, 0.25);
}
Expand Down
17 changes: 12 additions & 5 deletions frontend/tmpl/card-ft/cloud.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,22 @@
<form class="modal-content rounded p-2 bg-tool">
<div class="modal-header">
<div class="modal-title">Network disk connecting</div>
<select v-model="scheme" class="form-select bg-tool w-auto mx-2">
<option value="ftp">FTP</option>
<option value="sftp">SFTP</option>
</select>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<fieldset>
<label v-bind:for="'host'+iid" class="small navbar-text">Type here host where placed FTP server to connect and it's port. It can be DNS-name or IP-address. For example, host can be <span class="bg-stat">192.168.1.3</span> and port <span class="bg-stat">21</span></label>
<div class="row g-2">
<div class="form-floating col-md-8">
<input v-model.trim="host" v-bind:class="clshostedt" v-bind:id="'host'+iid" v-on:keyup.enter.prevent="onadd" v-on:keyup="onchange" class="form-control toolinp bg-tool" type="text" maxlength="256" placeholder="127.0.0.1" required>
<input v-model.trim="host" v-bind:class="clshostedt" v-bind:id="'host'+iid" v-on:keyup.enter.prevent="onadd" v-on:keyup="onchange" class="form-control toolinp bg-tool" type="text" maxlength="256" required>
<label v-bind:for="'host'+iid">connection host</label>
</div>
<div class="form-floating col-md-4">
<input v-model.trim="port" v-bind:class="clsportedt" v-bind:id="'port'+iid" v-on:keyup.enter.prevent="onadd" v-on:keyup="onchange" class="form-control toolinp bg-tool" type="number" min="1" max="65535" placeholder="21" required>
<input v-model.trim="port" v-bind:class="clsportedt" v-bind:id="'port'+iid" v-on:keyup.enter.prevent="onadd" v-on:keyup="onchange" class="form-control toolinp bg-tool" type="number" min="1" max="65535" required>
<label v-bind:for="'port'+iid">connection port</label>
</div>
</div>
Expand All @@ -62,9 +66,12 @@
<input v-model.trim="login" v-bind:class="clsloginedt" v-bind:id="'login'+iid" v-on:keyup.enter.prevent="onadd" v-on:keyup="onchange" class="form-control toolinp bg-tool" type="text" maxlength="256">
<label v-bind:for="'login'+iid">login</label>
</div>
<div class="form-floating col-md">
<input v-model.trim="password" v-bind:class="clspassedt" v-bind:id="'pass'+iid" v-on:keyup.enter.prevent="onadd" v-on:keyup="onchange" class="form-control toolinp bg-tool" type="password" maxlength="256">
<label v-bind:for="'pass'+iid">password</label>
<div class="input-group col-md">
<div class="form-floating">
<input v-model.trim="password" v-bind:class="clspassedt" v-bind:id="'pass'+iid" v-on:keyup.enter.prevent="onadd" v-on:keyup="onchange" class="form-control toolinp bg-tool" v-bind:type="clspswdstate" maxlength="256">
<label v-bind:for="'pass'+iid">password</label>
</div>
<button v-on:click="onshowpswd" class="btn toolbtn" type="button"><i class="material-icons">{{pswdstate}}</i></button>
</div>
</div>
</fieldset>
Expand Down
Loading

0 comments on commit 0d97554

Please sign in to comment.