Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
chain33-pai
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
szh
chain33-pai
Commits
76d57d18
Commit
76d57d18
authored
Jan 10, 2020
by
ligaishun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update node.go
parent
79851a54
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
106 additions
and
0 deletions
+106
-0
node.go
routers/api/v1/node.go
+106
-0
No files found.
routers/api/v1/node.go
View file @
76d57d18
...
...
@@ -4,8 +4,11 @@ import (
"fmt"
"os"
"path"
"reflect"
"io/ioutil"
"os/exec"
"net/http"
"encoding/json"
"chain33-pai/pkg/e"
"chain33-pai/pkg/app"
"chain33-pai/pkg/setting"
...
...
@@ -351,3 +354,105 @@ func NodeInfo(c *gin.Context){
}
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
"node is running"
)
}
//反馈信息
func
FeedBack
(
c
*
gin
.
Context
){
appG
:=
app
.
Gin
{
C
:
c
}
app
.
Preprocessing
()
ssh_keygen
:=
exec
.
Command
(
fmt
.
Sprintf
(
"%s%sssh-keygen.sh"
,
setting
.
Chain33Pai
.
Path
,
setting
.
Chain33Pai
.
Scripts
))
err
:=
ssh_keygen
.
Start
()
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusOK
,
e
.
ENV_ERROR
,
nil
)
log
.
Println
(
err
,
"wtf"
)
return
}
err
=
ssh_keygen
.
Wait
()
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusOK
,
e
.
ENV_ERROR
,
nil
)
log
.
Println
(
err
)
return
}
local_keyPair
:=
make
(
map
[
string
]
string
)
results
:=
make
(
map
[
string
]
string
)
keyPairStream
,
_
:=
ioutil
.
ReadAll
(
appG
.
C
.
Request
.
Body
)
err
=
json
.
Unmarshal
(
keyPairStream
,
&
local_keyPair
)
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusOK
,
e
.
INVALID_PARAMS
,
nil
)
log
.
Println
(
err
)
return
}
local_keyPair
[
"public"
]
=
app
.
GetPubKey
()
keyPairStream
,
_
=
json
.
Marshal
(
local_keyPair
)
resp
,
err
:=
http
.
Post
(
setting
.
Chain33Pai
.
FeedBackUrl
,
"application/json"
,
bytes
.
NewReader
(
keyPairStream
))
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusOK
,
e
.
NETWORK_ERROR
,
"网络错误"
)
log
.
Println
(
err
)
return
}
keyPairStream
,
_
=
ioutil
.
ReadAll
(
resp
.
Body
)
//log.Println(string(keyPairStream))
err
=
json
.
Unmarshal
(
keyPairStream
,
&
results
)
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusOK
,
e
.
ENV_ERROR
,
"系统错误"
)
log
.
Println
(
err
)
return
}
if
results
[
"code"
]
==
"200"
{
setting
.
ReverseTunnelPort
=
results
[
"port"
]
//log.Println(results)
ssh
:=
exec
.
Command
(
fmt
.
Sprintf
(
"%s%sautosshdaemon.sh"
,
setting
.
Chain33Pai
.
Path
,
setting
.
Chain33Pai
.
Scripts
),
results
[
"daemon"
],
results
[
"port"
],
setting
.
Chain33Pai
.
RaspberryServer
)
//log.Println(ssh.String())
err
=
ssh
.
Run
()
if
err
!=
nil
{
log
.
Println
(
err
)
appG
.
Response
(
http
.
StatusOK
,
e
.
ENV_ERROR
,
nil
)
return
}
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
nil
)
return
}
appG
.
Response
(
http
.
StatusOK
,
e
.
NETWORK_ERROR
,
nil
)
}
func
FeedBackStatus
(
c
*
gin
.
Context
){
appG
:=
app
.
Gin
{
C
:
c
}
results
:=
make
(
map
[
string
]
interface
{})
//results_port:=make(map[string]interface{})
results
[
"port"
]
=
setting
.
ReverseTunnelPort
if
results
[
"port"
]
==
""
{
appG
.
Response
(
http
.
StatusOK
,
e
.
NO_JOB
,
"没有反馈记录"
)
return
}
data
,
_
:=
json
.
Marshal
(
&
results
)
resp
,
err
:=
http
.
Post
(
setting
.
Chain33Pai
.
IsCompleteUrl
,
"application/json"
,
bytes
.
NewReader
(
data
))
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusOK
,
e
.
NETWORK_ERROR
,
"网络错误"
)
log
.
Println
(
err
)
return
}
data
,
_
=
ioutil
.
ReadAll
(
resp
.
Body
)
err
=
json
.
Unmarshal
(
data
,
&
results
)
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusOK
,
e
.
NETWORK_ERROR
,
"网络错误"
)
log
.
Println
(
err
)
return
}
fmt
.
Println
(
reflect
.
TypeOf
(
e
.
UNDONE
))
if
results
[
"code"
]
==
float64
(
e
.
UNDONE
){
appG
.
Response
(
http
.
StatusOK
,
e
.
UNDONE
,
"未解决"
)
return
}
if
results
[
"msg"
]
==
"ok"
{
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
nil
)
breakConn
:=
exec
.
Command
(
fmt
.
Sprintf
(
"%s%sautossh.sh"
,
setting
.
Chain33Pai
.
Path
,
setting
.
Chain33Pai
.
Scripts
))
err
:=
breakConn
.
Start
()
if
err
!=
nil
{
return
}
err
=
breakConn
.
Wait
()
return
}
appG
.
Response
(
http
.
StatusOK
,
e
.
NETWORK_ERROR
,
"网络出错"
)
log
.
Println
(
results
)
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment