[agent] - bastion mode init
This commit is contained in:
@@ -2,75 +2,9 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func BasicDownloadFileHTTP(downloadUrl string, proxyUrl string, proxyUser string, proxyPass string, desFile string) (downloadOk bool, resultLog []string) {
|
||||
// 解析下载URL
|
||||
_, err := url.Parse(downloadUrl)
|
||||
if err != nil {
|
||||
resultLog = append(resultLog, "Error parsing download URL: "+err.Error())
|
||||
return false, resultLog
|
||||
}
|
||||
|
||||
// 创建文件
|
||||
out, err := os.Create(desFile)
|
||||
if err != nil {
|
||||
resultLog = append(resultLog, "Error creating file: "+err.Error())
|
||||
return false, resultLog
|
||||
}
|
||||
defer out.Close()
|
||||
|
||||
// 创建HTTP客户端
|
||||
client := &http.Client{}
|
||||
|
||||
// 如果提供了代理URL
|
||||
if proxyUrl != "" {
|
||||
// 解析代理URL
|
||||
proxyURL, err := url.Parse(proxyUrl)
|
||||
if err != nil {
|
||||
resultLog = append(resultLog, "Error parsing proxy URL: "+err.Error())
|
||||
return false, resultLog
|
||||
}
|
||||
|
||||
// 设置HTTP代理
|
||||
transport := &http.Transport{
|
||||
Proxy: func(req *http.Request) (*url.URL, error) {
|
||||
req.SetBasicAuth(proxyUser, proxyPass)
|
||||
return proxyURL, nil
|
||||
},
|
||||
}
|
||||
client.Transport = transport
|
||||
}
|
||||
|
||||
// 发送HTTP GET请求
|
||||
resp, err := client.Get(downloadUrl)
|
||||
if err != nil {
|
||||
resultLog = append(resultLog, "Error making GET request: "+err.Error())
|
||||
return false, resultLog
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
// 检查HTTP响应状态码
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
resultLog = append(resultLog, "Server returned HTTP status "+resp.Status)
|
||||
return false, resultLog
|
||||
}
|
||||
|
||||
// 将HTTP响应内容写入文件
|
||||
_, err = io.Copy(out, resp.Body)
|
||||
if err != nil {
|
||||
resultLog = append(resultLog, "Error writing to file: "+err.Error())
|
||||
return false, resultLog
|
||||
}
|
||||
|
||||
return true, resultLog
|
||||
}
|
||||
|
||||
func splitTest() {
|
||||
|
||||
bucketName := "123"
|
||||
@@ -93,20 +27,4 @@ func main() {
|
||||
|
||||
splitTest()
|
||||
|
||||
//socksProxyUrl := "socks5://192.168.35.71:22888"
|
||||
//httpProxyUrl := "http://192.168.35.71:22808"
|
||||
//downloadOk, resultLog := BasicDownloadFileHTTP(
|
||||
// "https://happybirthday.107421.xyz/octopus-agent/octopus-agent_linux_amd64_2024-03-29-17-47-14",
|
||||
// httpProxyUrl,
|
||||
// "zeaslity",
|
||||
// "password",
|
||||
// "octopus-agent_linux_1232",
|
||||
//)
|
||||
//if downloadOk {
|
||||
// println("File downloaded successfully")
|
||||
//} else {
|
||||
// for _, log := range resultLog {
|
||||
// println(log)
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user