-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.go
91 lines (79 loc) · 1.89 KB
/
init.go
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
package tunnel
import (
"fmt"
"github.com/onuragtas/tunnel-client/models"
request2 "github.com/onuragtas/tunnel-client/request"
"net/http"
"os"
"os/signal"
"syscall"
"time"
)
var defaultLocalPort = 80
var defaultDestinationIp = "127.0.0.1"
var requestClient = request2.Request{
BaseUrl: "https://tunnel.retp.xyz/api/v1",
}
var domainList = models.Domain{}
type StartedTunnels struct {
Data []Item
}
var startedTunnels StartedTunnels
var process string
var list string
func updateULimit() {
var rLimit syscall.Rlimit
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
if err != nil {
fmt.Println("Error Getting Rlimit ", err)
}
fmt.Println(rLimit)
rLimit.Max = 999999
rLimit.Cur = 999999
err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
if err != nil {
fmt.Println("Error Setting Rlimit ", err)
}
err = syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
if err != nil {
fmt.Println("Error Getting Rlimit ", err)
}
fmt.Println("Rlimit Final", rLimit)
}
func init() {
updateULimit()
//flag.StringVar(&process, "process", "", "")
//flag.StringVar(&list, "list", "", "")
//flag.Parse()
SetupCloseHandler()
go keepAlive()
}
func keepAlive() {
for true {
for key, value := range startedTunnels.Data {
go func(startedTunnels StartedTunnels, item Item, key int) {
if item.Domain.KeepAlive != 0 && time.Now().Sub(item.KeepAliveTime).Seconds() > float64(item.Domain.KeepAlive) {
startedTunnels.Data[key].KeepAliveTime = time.Now()
resp, _ := http.Get("https://" + item.Domain.Domain)
if resp != nil && resp.Body != nil {
resp.Body.Close()
}
}
}(startedTunnels, value, key)
}
time.Sleep(time.Millisecond * 200)
}
}
func SetupCloseHandler() {
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
fmt.Println("Will Closing")
Close()
os.Exit(1)
}()
}
func Close() {
fmt.Println("Closed...")
}