Commit 76d57d18 authored by ligaishun's avatar ligaishun

Update node.go

parent 79851a54
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment