Skip to content

Commit

Permalink
Hide password and token
Browse files Browse the repository at this point in the history
Via env variable
  • Loading branch information
TIT8 committed Aug 28, 2023
1 parent f30e909 commit bb681fc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/secrets.txt

/form-api.exe
22 changes: 13 additions & 9 deletions form-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ import (
"log"
"net/http"
"net/url"
"os"
"regexp"
)

const Token string = "6169685035:AAEgNi4pC5gARzCiMlvkDTFIEOOClD6wHB0"
const ChatId string = "-1001888191995"

type Response struct {
Response string `json:"response"`
}
Expand All @@ -31,7 +29,7 @@ type Request struct {

func getUrl() string {

return fmt.Sprintf("https://api.telegram.org/bot%s", Token)
return fmt.Sprintf("https://api.telegram.org/bot%s", os.Getenv("TELEGRAM_TOKEN"))

}

Expand All @@ -42,7 +40,7 @@ func SendMessage(text string) (bool, error) {

url := fmt.Sprintf("%s/sendMessage", getUrl())
body, err := json.Marshal(map[string]string{
"chat_id": ChatId,
"chat_id": os.Getenv("CHAT_ID"),
"text": text,
})
if err != nil {
Expand Down Expand Up @@ -110,8 +108,8 @@ func handler_post(w http.ResponseWriter, r *http.Request) {

data := url.Values{}
data.Add("solution", req.Captcha)
data.Add("secret", "A1UGN12VU21PUJCEUJNDHHTP0CD835IGMDUO3IS0JVBDUBUUVQJ584DPD1")
data.Add("sitekey", "FCMTGCV10AMHV9QE")
data.Add("secret", os.Getenv("CAPTCHA_SECRET"))
data.Add("sitekey", os.Getenv("CAPTCHA_SITEKEY"))

posturl := "https://api.friendlycaptcha.com/api/v1/siteverify"

Expand Down Expand Up @@ -142,15 +140,21 @@ func handler_post(w http.ResponseWriter, r *http.Request) {
text := fmt.Sprintf("New message!\n\nName:\t%s\n\nE-mail:\t%s\n\nMessage:\t%s\n", req.Name, req.Email, req.Message)
result, err := SendMessage(text)
if !result {

log.Printf("Error sending telegram messag, %s\n", err)
w.WriteHeader(http.StatusNotAcceptable)
ok = "Valid CAPTCHA but error on Telegram request"

} else {
ok = "ok"

w.WriteHeader(http.StatusOK)
ok = "Valid CAPTCHA and Telegram sent"

}

} else {

ok = "not ok"
ok = "CAPTCHA validation failed"
w.WriteHeader(http.StatusNotAcceptable)

}
Expand Down

0 comments on commit bb681fc

Please sign in to comment.