-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdssh_etc.go
More file actions
129 lines (112 loc) · 2.67 KB
/
Copy pathdssh_etc.go
File metadata and controls
129 lines (112 loc) · 2.67 KB
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
//go:build !windows
// +build !windows
package main
import (
"bufio"
"context"
"fmt"
"os"
"os/exec"
"path"
"path/filepath"
"strings"
"github.com/abakum/winssh"
)
const win = false
var (
PuTTY = winssh.UserHomeDirs(".putty")
Sessions = path.Join(PuTTY, "sessions")
SshHostCAs = path.Join(PuTTY, "sshhostcas")
SshHostKeys = path.Join(PuTTY, "sshhostkeys")
)
func confToMap(name, separator string) (kv map[string]string) {
kv = make(map[string]string)
file, err := os.Open(name)
if err != nil {
Println(err)
return
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
s := scanner.Text()
if s == "" {
continue
}
ss := strings.Split(s, separator)
v := ""
if len(ss) > 1 {
v = ss[1]
}
kv[ss[0]] = v
}
return
}
func mapToConf(name, separator string, p map[string]string) (err error) {
os.MkdirAll(path.Dir(name), 0700)
f, err := os.Create(name)
if err != nil {
return
}
defer f.Close()
defer f.Chmod(FILEMODE)
for k, v := range p {
_, err = f.WriteString(k + separator + v + "\n")
if err != nil {
return
}
}
return
}
// Конфиг для putty на linux и на MacOS
func Conf(name, separator string, kv map[string]string) {
p := confToMap(name, separator)
for k, v := range kv {
if k == "" {
continue
}
p[k] = v
}
mapToConf(name, separator, p)
}
func GlobalSshPath() string {
return path.Join("/etc", SSH)
}
func createNewConsole(*exec.Cmd) {
}
func isWin7() bool { return false }
func ConsoleCP() {
setRaw(&once)
}
func sx(ctx context.Context, u, hp string) {
x := "sftp"
if args.Scp {
x = "scp"
}
bin, err := exec.LookPath(fileZillaBin)
if err == nil && args.Sftp {
uhd, err := os.UserHomeDir()
if err == nil {
u, err := uhp2u(u, filepath.Join(uhd, ".config", fileZillaBin, fileZillaXml))
if err == nil {
cmdStart(exec.CommandContext(ctx, bin, "-l", "interactive", fmt.Sprintf("%s://%s@%s/", x, u, hp)))
return
}
}
}
u, _ = uhp2u(u, "")
// XDG_UTILS_DEBUG_LEVEL=999 xdg-mime query default x-scheme-handler/sftp
// gio mime x-scheme-handler/sftp
// gio mime x-scheme-handler/sftp filezilla.desktop
// /usr/share/applications/filezilla.desktop
// Exec=filezilla -l interactive %U
// MimeType=x-scheme-handler/sftp;
// gio mime x-scheme-handler/ssh
// gio mime x-scheme-handler/ssh putty.desktop
// Exec=bash -c 'putty -load ${0//ssh:\/\//}' %u
// MimeType=x-scheme-handler/ssh;
// echo a://b|awk '{split($0,a,"://"); print a[2]}'
// если не в /usr/share/applications/ а в ~/.local/share/applications
// update-desktop-database ~/.local/share/applications
cmdStart(exec.CommandContext(ctx, "xdg-open", fmt.Sprintf("%s://%s@%s/", x, u, hp)))
}