From 49f0c86eb68dd878d0be133b7708b54756117f92 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Tue, 1 Oct 2024 22:01:10 +0530 Subject: [PATCH 01/72] feat: project init --- .gitignore | 1 + go.mod | 5 +++++ go.sum | 2 ++ main.go | 5 +++++ 4 files changed, 13 insertions(+) create mode 100644 .gitignore create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..7a78258 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/bikram-ghuku/finb + +go 1.23.1 + +require github.com/joho/godotenv v1.5.1 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..d61b19e --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= diff --git a/main.go b/main.go new file mode 100644 index 0000000..7905807 --- /dev/null +++ b/main.go @@ -0,0 +1,5 @@ +package main + +func main() { + +} From c282eee476091be02621a5b69530dea95d42566d Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Tue, 1 Oct 2024 22:25:06 +0530 Subject: [PATCH 02/72] feat: added basic endpoints --- go.mod | 2 +- main.go | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 7a78258..7b75a8b 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,4 @@ module github.com/bikram-ghuku/finb go 1.23.1 -require github.com/joho/godotenv v1.5.1 // indirect +require github.com/joho/godotenv v1.5.1 diff --git a/main.go b/main.go index 7905807..e6c578a 100644 --- a/main.go +++ b/main.go @@ -1,5 +1,32 @@ package main +import ( + "fmt" + "log" + "net/http" + + "github.com/joho/godotenv" +) + func main() { + godotenv.Load() + + erpCatCodeTopicMap := map[int]string{ + 11: "Academic", + 12: "Administrative", + 13: "Miscellaneous", + 1001: "Academic (UG) section notices", + 1002: "Academic (PG) section notices", + } + + endpoint := "https://erp.iitkgp.ac.in/InfoCellDetails/internal_noticeboard/get_notice_list.htm?cat_code=%d" + + resp, err := http.Get(fmt.Sprintf(endpoint, "")) + + if err != nil { + log.Printf(err.Error()) + } + + fmt.Println(resp.StatusCode) } From 185c2a9abfeecb175987de2c59b690d6bdcb6e50 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Wed, 2 Oct 2024 08:03:55 +0530 Subject: [PATCH 03/72] feat: added request maker --- main.go | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index e6c578a..ab073c6 100644 --- a/main.go +++ b/main.go @@ -1,17 +1,57 @@ package main import ( + "encoding/json" "fmt" "log" "net/http" + "os" "github.com/joho/godotenv" ) +type NoticeElement struct { + SlNo string `json:"slno"` + EventType string `json:"event_type"` + MessageSubject string `json:"message_subject"` + MessageBody string `json:"message_body"` + ApprovedOn string `json:"approved_on"` + Attachment int64 `json:"primary_attachemnt_id"` +} + +var ( + ERPJSession string + ERPSSOToken string + NoticeEndpoint string + FileEndpoint string + erpCatCodeTopicMap map[int]string +) + +func MakeRequest(channel int) *http.Request { + client, err := http.NewRequest("GET", fmt.Sprintf(NoticeEndpoint, channel), nil) + if err != nil { + log.Println(err.Error()) + return nil + } + + client.AddCookie(&http.Cookie{ + Name: "JSESSION", + Value: ERPJSession, + }) + + client.AddCookie(&http.Cookie{ + Name: "ssoToken", + Value: ERPSSOToken, + }) + return client +} + func main() { godotenv.Load() + ERPJSession = os.Getenv("JSESSIONID") + ERPSSOToken = os.Getenv("ssoToken") - erpCatCodeTopicMap := map[int]string{ + erpCatCodeTopicMap = map[int]string{ 11: "Academic", 12: "Administrative", 13: "Miscellaneous", @@ -19,14 +59,21 @@ func main() { 1002: "Academic (PG) section notices", } - endpoint := "https://erp.iitkgp.ac.in/InfoCellDetails/internal_noticeboard/get_notice_list.htm?cat_code=%d" - - resp, err := http.Get(fmt.Sprintf(endpoint, "")) + NoticeEndpoint = "https://erp.iitkgp.ac.in/InfoCellDetails/internal_noticeboard/get_notice_list.htm?cat_code=%d" + FileEndpoint = "https://erp.iitkgp.ac.in/InfoCellDetails/resources/external/groupemailfile?file_id=%s" + client := &http.Client{} + req := MakeRequest(12) + resp, err := client.Do(req) if err != nil { - log.Printf(err.Error()) + log.Println(err.Error()) } - fmt.Println(resp.StatusCode) + var resBody []NoticeElement + + if err := json.NewDecoder(resp.Body).Decode(&resBody); err != nil { + log.Println(err.Error()) + } + fmt.Printf("%v", resBody[0]) } From 7c827c88eebd595c1199cbbade6016dcfa8049b5 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Wed, 2 Oct 2024 08:26:23 +0530 Subject: [PATCH 04/72] feat: added more parameters to decode --- main.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/main.go b/main.go index ab073c6..72c8d9f 100644 --- a/main.go +++ b/main.go @@ -17,6 +17,9 @@ type NoticeElement struct { MessageBody string `json:"message_body"` ApprovedOn string `json:"approved_on"` Attachment int64 `json:"primary_attachemnt_id"` + EventDate string `json:"event_date"` + EventTime string `json:"time_desc"` + EventVenue string `json:"event_venue"` } var ( From 933c83b2a2bf5f2d9b23a9c2051d331e8e89a8ff Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Wed, 2 Oct 2024 08:29:49 +0530 Subject: [PATCH 05/72] fix: response parameters to decode --- main.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/main.go b/main.go index 72c8d9f..81f0338 100644 --- a/main.go +++ b/main.go @@ -11,8 +11,7 @@ import ( ) type NoticeElement struct { - SlNo string `json:"slno"` - EventType string `json:"event_type"` + MessageId int `json:"message_id"` MessageSubject string `json:"message_subject"` MessageBody string `json:"message_body"` ApprovedOn string `json:"approved_on"` From cb5403feea518ffbb847fb06e050cd180ac30ef9 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Wed, 2 Oct 2024 09:09:07 +0530 Subject: [PATCH 06/72] feat: made client reuseable --- main.go | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/main.go b/main.go index 81f0338..e9a6629 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,8 @@ import ( "fmt" "log" "net/http" + "net/http/cookiejar" + "net/url" "os" "github.com/joho/godotenv" @@ -27,25 +29,22 @@ var ( NoticeEndpoint string FileEndpoint string erpCatCodeTopicMap map[int]string + Client http.Client ) -func MakeRequest(channel int) *http.Request { - client, err := http.NewRequest("GET", fmt.Sprintf(NoticeEndpoint, channel), nil) - if err != nil { - log.Println(err.Error()) - return nil - } +func MakeCookies() []*http.Cookie { - client.AddCookie(&http.Cookie{ + var Cookies []*http.Cookie + Cookies = append(Cookies, &http.Cookie{ Name: "JSESSION", Value: ERPJSession, }) - client.AddCookie(&http.Cookie{ + Cookies = append(Cookies, &http.Cookie{ Name: "ssoToken", Value: ERPSSOToken, }) - return client + return Cookies } func main() { @@ -64,17 +63,33 @@ func main() { NoticeEndpoint = "https://erp.iitkgp.ac.in/InfoCellDetails/internal_noticeboard/get_notice_list.htm?cat_code=%d" FileEndpoint = "https://erp.iitkgp.ac.in/InfoCellDetails/resources/external/groupemailfile?file_id=%s" - client := &http.Client{} - req := MakeRequest(12) - resp, err := client.Do(req) + req, err := http.NewRequest("GET", fmt.Sprintf(NoticeEndpoint, 11), nil) + if err != nil { + log.Fatalf("Error %s", err.Error()) + } + + jar, err := cookiejar.New(nil) + if err != nil { + log.Fatalf("Error %s", err.Error()) + } + + parseURL, _ := url.Parse(NoticeEndpoint) + + jar.SetCookies(parseURL, MakeCookies()) + + Client = http.Client{ + Jar: jar, + } + + resp, err := Client.Do(req) if err != nil { - log.Println(err.Error()) + log.Fatalf("Error %s", err.Error()) } var resBody []NoticeElement if err := json.NewDecoder(resp.Body).Decode(&resBody); err != nil { - log.Println(err.Error()) + log.Fatalf("Error %s", err.Error()) } fmt.Printf("%v", resBody[0]) From 9708e6efc24b67820b2bd445d837a32872c25234 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Wed, 2 Oct 2024 09:26:44 +0530 Subject: [PATCH 07/72] feat: added cron, get notices, initialse client functions --- main.go | 83 +++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 54 insertions(+), 29 deletions(-) diff --git a/main.go b/main.go index e9a6629..54b570c 100644 --- a/main.go +++ b/main.go @@ -8,11 +8,13 @@ import ( "net/http/cookiejar" "net/url" "os" + "time" "github.com/joho/godotenv" ) type NoticeElement struct { + SerialNo int `json:"slno"` MessageId int `json:"message_id"` MessageSubject string `json:"message_subject"` MessageBody string `json:"message_body"` @@ -32,6 +34,56 @@ var ( Client http.Client ) +func RunCron() { + for true { + log.Println("Getting messages....") + for key, value := range erpCatCodeTopicMap { + log.Printf("Getting notices for %s", value) + getNotices(key) + } + time.Sleep(5 * time.Second) + } +} + +func getNotices(channel int) { + req, err := http.NewRequest("GET", fmt.Sprintf(NoticeEndpoint, channel), nil) + if err != nil { + log.Fatalf("Error %s", err.Error()) + } + + resp, err := Client.Do(req) + if err != nil { + log.Fatalf("Error %s", err.Error()) + } + + var resBody []NoticeElement + + if err := json.NewDecoder(resp.Body).Decode(&resBody); err != nil { + log.Fatalf("Error %s", err.Error()) + } + + if channel < 1000 { + log.Printf("Last message id: %d", resBody[0].MessageId) + } else { + log.Printf("Last message id: %d", resBody[0].SerialNo) + } +} + +func initClient() { + jar, err := cookiejar.New(nil) + if err != nil { + log.Fatalf("Error %s", err.Error()) + } + + parseURL, _ := url.Parse(NoticeEndpoint) + + jar.SetCookies(parseURL, MakeCookies()) + + Client = http.Client{ + Jar: jar, + } +} + func MakeCookies() []*http.Cookie { var Cookies []*http.Cookie @@ -63,34 +115,7 @@ func main() { NoticeEndpoint = "https://erp.iitkgp.ac.in/InfoCellDetails/internal_noticeboard/get_notice_list.htm?cat_code=%d" FileEndpoint = "https://erp.iitkgp.ac.in/InfoCellDetails/resources/external/groupemailfile?file_id=%s" - req, err := http.NewRequest("GET", fmt.Sprintf(NoticeEndpoint, 11), nil) - if err != nil { - log.Fatalf("Error %s", err.Error()) - } - - jar, err := cookiejar.New(nil) - if err != nil { - log.Fatalf("Error %s", err.Error()) - } - - parseURL, _ := url.Parse(NoticeEndpoint) - - jar.SetCookies(parseURL, MakeCookies()) - - Client = http.Client{ - Jar: jar, - } - - resp, err := Client.Do(req) - if err != nil { - log.Fatalf("Error %s", err.Error()) - } - - var resBody []NoticeElement - - if err := json.NewDecoder(resp.Body).Decode(&resBody); err != nil { - log.Fatalf("Error %s", err.Error()) - } + initClient() - fmt.Printf("%v", resBody[0]) + RunCron() } From 60f762a0ac9705c365ff8ddf7b48215aff28a5fb Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Wed, 2 Oct 2024 10:02:51 +0530 Subject: [PATCH 08/72] feat: added last message checker --- main.go | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 54b570c..99854a4 100644 --- a/main.go +++ b/main.go @@ -30,14 +30,14 @@ var ( ERPSSOToken string NoticeEndpoint string FileEndpoint string - erpCatCodeTopicMap map[int]string + ERPCatCodeTopicMap map[int]string Client http.Client ) func RunCron() { for true { log.Println("Getting messages....") - for key, value := range erpCatCodeTopicMap { + for key, value := range ERPCatCodeTopicMap { log.Printf("Getting notices for %s", value) getNotices(key) } @@ -69,6 +69,39 @@ func getNotices(channel int) { } } +func ChkUpdtLastNotice(channel int, lastElement NoticeElement) { + file, err := os.Open("lastmsg.json") + defer file.Close() + if err != nil { + log.Panicf("Error opening file: %s", err.Error()) + } + + var fileContent map[int]int + if err = json.NewDecoder(file).Decode(&fileContent); err != nil { + log.Panicf("Error decoding file: %s", err.Error()) + } + + if channel < 1000 { + if fileContent[channel] != lastElement.MessageId { + log.Printf("New message on channel %s: \n %v", ERPCatCodeTopicMap[channel], lastElement) + fileContent[channel] = lastElement.MessageId + } else { + log.Printf("Last message id: %d", lastElement.MessageId) + } + } else { + if fileContent[channel] != lastElement.SerialNo { + log.Printf("New message on channel %s: \n %v", ERPCatCodeTopicMap[channel], lastElement) + fileContent[channel] = lastElement.SerialNo + } else { + log.Printf("Last message id: %d", lastElement.SerialNo) + } + } + + if err = json.NewEncoder(file).Encode(fileContent); err != nil { + log.Panicf("Error writing file: %s", err.Error()) + } +} + func initClient() { jar, err := cookiejar.New(nil) if err != nil { @@ -104,7 +137,7 @@ func main() { ERPJSession = os.Getenv("JSESSIONID") ERPSSOToken = os.Getenv("ssoToken") - erpCatCodeTopicMap = map[int]string{ + ERPCatCodeTopicMap = map[int]string{ 11: "Academic", 12: "Administrative", 13: "Miscellaneous", From f90d84984f9d3b6957168e97a0743dee84aa1704 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Wed, 2 Oct 2024 10:21:52 +0530 Subject: [PATCH 09/72] fix: writing file error --- main.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index 99854a4..94d2cc4 100644 --- a/main.go +++ b/main.go @@ -61,16 +61,11 @@ func getNotices(channel int) { if err := json.NewDecoder(resp.Body).Decode(&resBody); err != nil { log.Fatalf("Error %s", err.Error()) } - - if channel < 1000 { - log.Printf("Last message id: %d", resBody[0].MessageId) - } else { - log.Printf("Last message id: %d", resBody[0].SerialNo) - } + ChkUpdtLastNotice(channel, resBody[0]) } func ChkUpdtLastNotice(channel int, lastElement NoticeElement) { - file, err := os.Open("lastmsg.json") + file, err := os.OpenFile("lastmsg.json", os.O_RDWR|os.O_CREATE, os.ModePerm) defer file.Close() if err != nil { log.Panicf("Error opening file: %s", err.Error()) @@ -97,9 +92,16 @@ func ChkUpdtLastNotice(channel int, lastElement NoticeElement) { } } - if err = json.NewEncoder(file).Encode(fileContent); err != nil { + txt, err := json.Marshal(fileContent) + if err != nil { log.Panicf("Error writing file: %s", err.Error()) } + + file.Seek(0, 0) + if _, err = file.Write(txt); err != nil { + log.Panicf("Error writing file: %s", err.Error()) + } + } func initClient() { From 2cd14983467711824cde32874e4a15e704641dc9 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Wed, 2 Oct 2024 10:22:36 +0530 Subject: [PATCH 10/72] feat: updated gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 4c49bd7..baa77c6 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .env +lastmsg.json From bf1e4cc1e681073753a88334e4823d6ac227f379 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Wed, 2 Oct 2024 10:29:58 +0530 Subject: [PATCH 11/72] feat: added field correction and printer message --- main.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 94d2cc4..b4fdfd3 100644 --- a/main.go +++ b/main.go @@ -19,7 +19,8 @@ type NoticeElement struct { MessageSubject string `json:"message_subject"` MessageBody string `json:"message_body"` ApprovedOn string `json:"approved_on"` - Attachment int64 `json:"primary_attachemnt_id"` + Attachment int64 `json:"primary_attachemnt_id"` // This is not a spelling mistake by me + AttachmentURL string `json:"attachment_url"` EventDate string `json:"event_date"` EventTime string `json:"time_desc"` EventVenue string `json:"event_venue"` @@ -77,15 +78,19 @@ func ChkUpdtLastNotice(channel int, lastElement NoticeElement) { } if channel < 1000 { + // For channels with id 1001 & 1002 the serial number is the message id and message id is empty if fileContent[channel] != lastElement.MessageId { - log.Printf("New message on channel %s: \n %v", ERPCatCodeTopicMap[channel], lastElement) + lastElement.AttachmentURL = fmt.Sprintf(FileEndpoint, lastElement.Attachment) + PrintNewMsg(ERPCatCodeTopicMap[channel], lastElement) fileContent[channel] = lastElement.MessageId } else { log.Printf("Last message id: %d", lastElement.MessageId) } } else { if fileContent[channel] != lastElement.SerialNo { - log.Printf("New message on channel %s: \n %v", ERPCatCodeTopicMap[channel], lastElement) + lastElement.MessageId = lastElement.SerialNo + lastElement.AttachmentURL = fmt.Sprintf(FileEndpoint, lastElement.Attachment) + PrintNewMsg(ERPCatCodeTopicMap[channel], lastElement) fileContent[channel] = lastElement.SerialNo } else { log.Printf("Last message id: %d", lastElement.SerialNo) @@ -104,6 +109,11 @@ func ChkUpdtLastNotice(channel int, lastElement NoticeElement) { } +func PrintNewMsg(channel string, content NoticeElement) { + // this function is called upon receving a new message + log.Printf("New message on channel %s: \n %v", channel, content) +} + func initClient() { jar, err := cookiejar.New(nil) if err != nil { @@ -148,7 +158,7 @@ func main() { } NoticeEndpoint = "https://erp.iitkgp.ac.in/InfoCellDetails/internal_noticeboard/get_notice_list.htm?cat_code=%d" - FileEndpoint = "https://erp.iitkgp.ac.in/InfoCellDetails/resources/external/groupemailfile?file_id=%s" + FileEndpoint = "https://erp.iitkgp.ac.in/InfoCellDetails/resources/external/groupemailfile?file_id=%d" initClient() From 40f76d6172e8d17753e2f65517a9194fd16fb28c Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Wed, 2 Oct 2024 10:30:36 +0530 Subject: [PATCH 12/72] feat: increment refresh timer --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index b4fdfd3..775a456 100644 --- a/main.go +++ b/main.go @@ -42,7 +42,7 @@ func RunCron() { log.Printf("Getting notices for %s", value) getNotices(key) } - time.Sleep(5 * time.Second) + time.Sleep(2 * time.Minute) } } From 4889afb654589e41bbe6bdbef629706059bbeb34 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Wed, 2 Oct 2024 10:31:09 +0530 Subject: [PATCH 13/72] feat: update logger message --- main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 775a456..4a29631 100644 --- a/main.go +++ b/main.go @@ -84,7 +84,7 @@ func ChkUpdtLastNotice(channel int, lastElement NoticeElement) { PrintNewMsg(ERPCatCodeTopicMap[channel], lastElement) fileContent[channel] = lastElement.MessageId } else { - log.Printf("Last message id: %d", lastElement.MessageId) + log.Printf("No new messages!! Last message id: %d", lastElement.MessageId) } } else { if fileContent[channel] != lastElement.SerialNo { @@ -93,7 +93,7 @@ func ChkUpdtLastNotice(channel int, lastElement NoticeElement) { PrintNewMsg(ERPCatCodeTopicMap[channel], lastElement) fileContent[channel] = lastElement.SerialNo } else { - log.Printf("Last message id: %d", lastElement.SerialNo) + log.Printf("No new messages!! Last message id: %d", lastElement.SerialNo) } } From 43e55b4f5f4a55a614b24bd162c7449b947f2a1d Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Wed, 2 Oct 2024 11:12:47 +0530 Subject: [PATCH 14/72] fix: latest single msg -> latest all message --- main.go | 58 ++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 23 deletions(-) diff --git a/main.go b/main.go index 4a29631..7f1685f 100644 --- a/main.go +++ b/main.go @@ -42,7 +42,7 @@ func RunCron() { log.Printf("Getting notices for %s", value) getNotices(key) } - time.Sleep(2 * time.Minute) + time.Sleep(30 * time.Second) } } @@ -62,10 +62,26 @@ func getNotices(channel int) { if err := json.NewDecoder(resp.Body).Decode(&resBody); err != nil { log.Fatalf("Error %s", err.Error()) } - ChkUpdtLastNotice(channel, resBody[0]) + lastNoticeId := getLastNotice(channel) + + i := 0 + for i < len(resBody) && resBody[i].MessageId != lastNoticeId && resBody[i].SerialNo != lastNoticeId { + PrintNewMsg(ERPCatCodeTopicMap[channel], resBody[i]) + i++ + } + + if channel > 1000 { + setLastNotice(channel, resBody[0].SerialNo) + } else { + setLastNotice(channel, resBody[0].MessageId) + } + + if i == 0 { + log.Printf("No new message on \"%s\"", ERPCatCodeTopicMap[channel]) + } } -func ChkUpdtLastNotice(channel int, lastElement NoticeElement) { +func getLastNotice(channel int) int { file, err := os.OpenFile("lastmsg.json", os.O_RDWR|os.O_CREATE, os.ModePerm) defer file.Close() if err != nil { @@ -77,26 +93,23 @@ func ChkUpdtLastNotice(channel int, lastElement NoticeElement) { log.Panicf("Error decoding file: %s", err.Error()) } - if channel < 1000 { - // For channels with id 1001 & 1002 the serial number is the message id and message id is empty - if fileContent[channel] != lastElement.MessageId { - lastElement.AttachmentURL = fmt.Sprintf(FileEndpoint, lastElement.Attachment) - PrintNewMsg(ERPCatCodeTopicMap[channel], lastElement) - fileContent[channel] = lastElement.MessageId - } else { - log.Printf("No new messages!! Last message id: %d", lastElement.MessageId) - } - } else { - if fileContent[channel] != lastElement.SerialNo { - lastElement.MessageId = lastElement.SerialNo - lastElement.AttachmentURL = fmt.Sprintf(FileEndpoint, lastElement.Attachment) - PrintNewMsg(ERPCatCodeTopicMap[channel], lastElement) - fileContent[channel] = lastElement.SerialNo - } else { - log.Printf("No new messages!! Last message id: %d", lastElement.SerialNo) - } + return fileContent[channel] +} + +func setLastNotice(channel int, lastMsgId int) { + file, err := os.OpenFile("lastmsg.json", os.O_RDWR|os.O_CREATE, os.ModePerm) + defer file.Close() + if err != nil { + log.Panicf("Error opening file: %s", err.Error()) } + var fileContent map[int]int + if err = json.NewDecoder(file).Decode(&fileContent); err != nil { + log.Panicf("Error decoding file: %s", err.Error()) + } + + fileContent[channel] = lastMsgId + txt, err := json.Marshal(fileContent) if err != nil { log.Panicf("Error writing file: %s", err.Error()) @@ -106,12 +119,11 @@ func ChkUpdtLastNotice(channel int, lastElement NoticeElement) { if _, err = file.Write(txt); err != nil { log.Panicf("Error writing file: %s", err.Error()) } - } func PrintNewMsg(channel string, content NoticeElement) { // this function is called upon receving a new message - log.Printf("New message on channel %s: \n %v", channel, content) + log.Printf("New message on channel %s: \n %v", channel, content.MessageSubject) } func initClient() { From f62faeb1109a99af5bdee72f9f5536b01b7070f9 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Wed, 2 Oct 2024 11:13:34 +0530 Subject: [PATCH 15/72] refactor: naming --- main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 7f1685f..c4c1a7a 100644 --- a/main.go +++ b/main.go @@ -40,13 +40,13 @@ func RunCron() { log.Println("Getting messages....") for key, value := range ERPCatCodeTopicMap { log.Printf("Getting notices for %s", value) - getNotices(key) + getNewNotices(key) } time.Sleep(30 * time.Second) } } -func getNotices(channel int) { +func getNewNotices(channel int) { req, err := http.NewRequest("GET", fmt.Sprintf(NoticeEndpoint, channel), nil) if err != nil { log.Fatalf("Error %s", err.Error()) From 13df9c346f63a33b48844248db2d3449cf044462 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Wed, 2 Oct 2024 11:15:21 +0530 Subject: [PATCH 16/72] Initial commit --- .github/CODE_OF_CONDUCT.md | 128 +++++ .github/CONTRIBUTING.md | 13 + .github/ISSUE_TEMPLATE/bug_report.md | 38 ++ .github/ISSUE_TEMPLATE/custom.md | 10 + .github/ISSUE_TEMPLATE/feature_request.md | 20 + .github/SECURITY.md | 39 ++ .github/pull_request_template.md | 38 ++ .github/workflows/deploy.yaml | 119 ++++ .gitignore | 4 + LICENSE | 661 ++++++++++++++++++++++ README.md | 191 +++++++ metaploy/PROJECT_NAME.metaploy.conf | 16 + metaploy/postinstall.sh | 14 + 13 files changed, 1291 insertions(+) create mode 100644 .github/CODE_OF_CONDUCT.md create mode 100644 .github/CONTRIBUTING.md create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/custom.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/SECURITY.md create mode 100644 .github/pull_request_template.md create mode 100644 .github/workflows/deploy.yaml create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 metaploy/PROJECT_NAME.metaploy.conf create mode 100755 metaploy/postinstall.sh diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..aa76813 --- /dev/null +++ b/.github/CODE_OF_CONDUCT.md @@ -0,0 +1,128 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, religion, or sexual identity +and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the + overall community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +https://bit.ly/metakgp-slack. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series +of actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or +permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within +the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.0, available at +https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. + +Community Impact Guidelines were inspired by [Mozilla's code of conduct +enforcement ladder](https://github.com/mozilla/diversity). + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see the FAQ at +https://www.contributor-covenant.org/faq. Translations are available at +https://www.contributor-covenant.org/translations. diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 0000000..67d9212 --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,13 @@ + +## Contributing + +Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**. + +If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". +Don't forget to give the project a star! Thanks again! + +1. Fork the Project +2. Create your Feature Branch (`git checkout -b feature`) +3. Commit your Changes (`git commit -m 'Add some newFeature'`) +4. Push to the Branch (`git push origin feature`) +5. Open a Pull Request diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..dd84ea7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,38 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS] + - Browser [e.g. chrome, safari] + - Version [e.g. 22] + +**Smartphone (please complete the following information):** + - Device: [e.g. iPhone6] + - OS: [e.g. iOS8.1] + - Browser [e.g. stock browser, safari] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/custom.md b/.github/ISSUE_TEMPLATE/custom.md new file mode 100644 index 0000000..48d5f81 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/custom.md @@ -0,0 +1,10 @@ +--- +name: Custom issue template +about: Describe this issue template's purpose here. +title: '' +labels: '' +assignees: '' + +--- + + diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..bbcbbe7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/SECURITY.md b/.github/SECURITY.md new file mode 100644 index 0000000..92e3337 --- /dev/null +++ b/.github/SECURITY.md @@ -0,0 +1,39 @@ +# Security Policy + +## Reporting a Vulnerability + +If you have discovered a vulnerability within the project, we sincerely appreciate your efforts in helping us maintain a secure system. We take security concerns seriously and encourage you to report any potential vulnerabilities promptly. This section will guide you on how to report a vulnerability and what you can expect during the process. + +### Reporting Process + +To report a vulnerability, please follow these steps: + +1. **Create an Issue**: Go to the project's GitHub repository and create a new issue. Please provide a clear and concise title that reflects the nature of the vulnerability. + +2. **Include Details**: In the issue description, please provide us with a detailed explanation of the vulnerability. It would be immensely helpful if you could include steps to reproduce the issue, relevant code snippets, and any additional information that can assist us in understanding and addressing the problem effectively. + +3. **Contact Information**: Don't forget to include your contact information (preferably an email address) so that we can reach out to you for further clarification or updates regarding the reported vulnerability. + +### Response and Update + +Once you have reported a vulnerability, we will promptly review the issue and respond to you within a reasonable timeframe. We aim to acknowledge the report within **4 business days** and provide an initial assessment of the vulnerability's severity. + +### Vulnerability Assessment + +After receiving your vulnerability report, we will conduct a thorough assessment to determine its validity and severity. We may request additional information or clarifications from you during this process to ensure a comprehensive evaluation. + +### Acceptance or Decline + +If the vulnerability is accepted, we will take appropriate measures to address and fix the issue. We will provide you with expected timelines for resolving the vulnerability. + +In case the vulnerability is deemed outside the scope of the project or does not pose a significant risk, it may be declined. We will provide a clear explanation for our decision and any recommended actions, if applicable. + +### Public Disclosure + +To ensure the safety and security of our users, we kindly request that you refrain from publicly disclosing the vulnerability until we have had sufficient time to address it. We strive to resolve vulnerabilities in a timely manner and appreciate your cooperation in maintaining responsible security practices. + +### Recognition + +We deeply value the contributions of the security community, and we are open to recognizing individuals who responsibly report vulnerabilities. If you would like to be credited for your discovery, please let us know when submitting the report. + +Thank you for helping us improve the security of the project. We genuinely appreciate your support in making our software safer for everyone. diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..d884663 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,38 @@ +# Description + +Please include a summary of the changes and the related issue. Please also include relevant motivation and context. List any dependencies that are required for this change. + +Fixes # (issue) + +## Type of change + +Please delete options that are not relevant. + +- [ ] Bug fix (non-breaking change which fixes an issue) +- [ ] New feature (non-breaking change which adds functionality) +- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) +- [ ] This change requires a documentation update + +# How Has This Been Tested? + +Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration + +- [ ] Test A +- [ ] Test B + +**Test Configuration**: +* Firmware version: +* Hardware: +* Toolchain: +* SDK: + +# Checklist: + +- [ ] My code follows the style guidelines of this project +- [ ] I have performed a self-review of my code +- [ ] I have commented my code, particularly in hard-to-understand areas +- [ ] I have made corresponding changes to the documentation +- [ ] My changes generate no new warnings +- [ ] I have added tests that prove my fix is effective or that my feature works +- [ ] New and existing unit tests pass locally with my changes +- [ ] Any dependent changes have been merged and published in downstream modules diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml new file mode 100644 index 0000000..97cbca0 --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -0,0 +1,119 @@ +name: Continuous Deployment Pipeline + +on: + push: + branches: + - "main" + paths-ignore: + - "**.md" + - "LICENSE" + - "LICENSE.txt" + - "frontend/**" + +jobs: + dockerhub: + name: Publish Docker Image(s) to Dockerhub + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + - name: Cache Docker layers SERVICE_NAME + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache-SERVICE_NAME + key: ${{ runner.os }}-buildx-SERVICE_NAME-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx-SERVICE_NAME- + + - name: Build & Push SERVICE_NAME + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ secrets.DOCKERHUB_USERNAME }}/SERVICE_NAME:latest + cache-from: type=local,src=/tmp/.buildx-cache-SERVICE_NAME + cache-to: type=local,dest=/tmp/.buildx-cache-SERVICE_NAME-new,mode=max + + - name: Move SERVICE_NAME cache + run: | + rm -rf /tmp/.buildx-cache-SERVICE_NAME + mv /tmp/.buildx-cache-SERVICE_NAME-new /tmp/.buildx-cache-SERVICE_NAME + + push: + name: Push Code Stage + needs: dockerhub + runs-on: ubuntu-latest + + steps: + - name: Sync local repo with remote repo + uses: appleboy/ssh-action@master + env: + PROJECT_DIR: ${{ secrets.PROJECT_DIR }} + with: + host: ${{ secrets.SSH_HOSTNAME }} + username: ${{ secrets.SSH_USERNAME }} + key: ${{ secrets.SSH_PRIVATE_KEY }} + passphrase: ${{ secrets.SSH_PRIVATE_KEY_PASSPHRASE }} + envs: PROJECT_DIR + script_stop: true + script: | + cd "${PROJECT_DIR}/" + sudo git fetch origin + sudo git reset --hard origin/main + + pull: + name: Pull Image Stage + needs: push + runs-on: ubuntu-latest + + steps: + - name: Pull the latest images(s) + uses: appleboy/ssh-action@master + env: + PROJECT_DIR: ${{ secrets.PROJECT_DIR }} + with: + host: ${{ secrets.SSH_HOSTNAME }} + username: ${{ secrets.SSH_USERNAME }} + key: ${{ secrets.SSH_PRIVATE_KEY }} + passphrase: ${{ secrets.SSH_PRIVATE_KEY_PASSPHRASE }} + envs: PROJECT_DIR + script_stop: true + script: | + cd "${PROJECT_DIR}/" + sudo docker compose pull + + deploy: + name: Deploy Stage + needs: pull + runs-on: ubuntu-latest + + steps: + - name: Deploy the latest build(s) + uses: appleboy/ssh-action@master + env: + PROJECT_DIR: ${{ secrets.PROJECT_DIR }} + with: + host: ${{ secrets.SSH_HOSTNAME }} + username: ${{ secrets.SSH_USERNAME }} + key: ${{ secrets.SSH_PRIVATE_KEY }} + passphrase: ${{ secrets.SSH_PRIVATE_KEY_PASSPHRASE }} + envs: PROJECT_DIR + script_stop: true + script: | + cd "${PROJECT_DIR}/" + sudo docker compose down + sudo docker compose up -d diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..967d1c4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +# Garbage & not required config files +.DS_Store +.vscode +node-modules/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0ad25db --- /dev/null +++ b/LICENSE @@ -0,0 +1,661 @@ + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU Affero General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Remote Network Interaction; Use with the GNU General Public License. + + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU Affero General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for the +specific requirements. + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU AGPL, see +. diff --git a/README.md b/README.md new file mode 100644 index 0000000..339cf3d --- /dev/null +++ b/README.md @@ -0,0 +1,191 @@ +
+ + + +
+ +[![Contributors][contributors-shield]][contributors-url] +[![Forks][forks-shield]][forks-url] +[![Stargazers][stars-shield]][stars-url] +[![Issues][issues-shield]][issues-url] +[![MIT License][license-shield]][license-url] +[![Wiki][wiki-shield]][wiki-url] + +
+ + +
+ +
+ + image + + +

PROJECT_NAME

+ +

+ + Project one liner slogan goes here +
+ Website + · + Request Feature / Report Bug +

+
+ + + +
+Table of Contents + +- [About The Project](#about-the-project) + - [Supports](#supports) +- [Getting Started](#getting-started) + - [Prerequisites](#prerequisites) + - [Installation](#installation) +- [Usage](#usage) +- [Contact](#contact) + - [Maintainer(s)](#maintainers) + - [creators(s)](#creators) +- [Additional documentation](#additional-documentation) + +
+ + + +## About The Project + + + +_Detailed explaination of the project goes here_ + +

(back to top)

+ +
+ +### Supports: + +1. Shells + * `bash` + * `zsh` +2. OS(s) + * any `*nix`[`GNU+Linux` and `Unix`] + +

(back to top)

+ +## Getting Started + +To set up a local instance of the application, follow the steps below. + +### Prerequisites +The following dependencies are required to be installed for the project to function properly: + +* npm + ```sh + npm install npm@latest -g + ``` + +

(back to top)

+ +### Installation + +_Now that the environment has been set up and configured to properly compile and run the project, the next step is to install and configure the project locally on your system._ + +1. Clone the repository + ```sh + git clone https://github.com/metakgp/PROJECT_NAME.git + ``` +2. Make the script executable + ```sh + cd ./PROJECT_NAME + chmod +x ./PROJECT_NAME + ``` +3. Execute the script + ```sh + ./PROJECT_NAME + ``` + +

(back to top)

+ + + +## Usage + +Use this space to show useful examples of how this project can be used. Additional screenshots, code examples and demos work well in this space. + + + +

(back to top)

+ +## Contact + +

+📫 Metakgp - + + Metakgp's slack invite + + + Metakgp's email + + + metakgp's Facebook + + + metakgp's LinkedIn + + + metakgp's Twitter + + + metakgp's Instagram + +

+ +### Maintainer(s) + +The currently active maintainer(s) of this project. + + +- [NAME](https://github.com/GITHUB_USERNAME) + +### Creator(s) + +Honoring the original creator(s) and ideator(s) of this project. + + +- [NAME](https://github.com/GITHUB_USERNAME) + +

(back to top)

+ +## Additional documentation + + - [License](/LICENSE) + - [Code of Conduct](/.github/CODE_OF_CONDUCT.md) + - [Security Policy](/.github/SECURITY.md) + - [Contribution Guidelines](/.github/CONTRIBUTING.md) + +

(back to top)

+ + + +[contributors-shield]: https://img.shields.io/github/contributors/metakgp/PROJECT_NAME.svg?style=for-the-badge +[contributors-url]: https://github.com/metakgp/PROJECT_NAME/graphs/contributors +[forks-shield]: https://img.shields.io/github/forks/metakgp/PROJECT_NAME.svg?style=for-the-badge +[forks-url]: https://github.com/metakgp/PROJECT_NAME/network/members +[stars-shield]: https://img.shields.io/github/stars/metakgp/PROJECT_NAME.svg?style=for-the-badge +[stars-url]: https://github.com/metakgp/PROJECT_NAME/stargazers +[issues-shield]: https://img.shields.io/github/issues/metakgp/PROJECT_NAME.svg?style=for-the-badge +[issues-url]: https://github.com/metakgp/PROJECT_NAME/issues +[license-shield]: https://img.shields.io/github/license/metakgp/PROJECT_NAME.svg?style=for-the-badge +[license-url]: https://github.com/metakgp/PROJECT_NAME/blob/master/LICENSE +[wiki-shield]: https://custom-icon-badges.demolab.com/badge/metakgp_wiki-grey?logo=metakgp_logo&style=for-the-badge +[wiki-url]: https://wiki.metakgp.org +[slack-url]: https://slack.metakgp.org diff --git a/metaploy/PROJECT_NAME.metaploy.conf b/metaploy/PROJECT_NAME.metaploy.conf new file mode 100644 index 0000000..3f25c81 --- /dev/null +++ b/metaploy/PROJECT_NAME.metaploy.conf @@ -0,0 +1,16 @@ +upstream PROJECT_NAME { + server PROJECT-NAME:5173; +} + +server { + server_name PROJECT-NAME.metakgp.org; + + location / { + proxy_pass http://PROJECT_NAME; + + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Original-URI $request_uri; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } +} \ No newline at end of file diff --git a/metaploy/postinstall.sh b/metaploy/postinstall.sh new file mode 100755 index 0000000..a5468f0 --- /dev/null +++ b/metaploy/postinstall.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +cleanup() { + echo "Container stopped. Removing nginx configuration." + rm /etc/nginx/sites-enabled/PROJECT_NAME.metaploy.conf +} + +trap 'cleanup' SIGQUIT SIGTERM SIGHUP + +"${@}" & + +cp ./PROJECT_NAME.metaploy.conf /etc/nginx/sites-enabled + +wait $! From da36e8f1348d8be8a55e147be488aeae6e838760 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Wed, 2 Oct 2024 11:23:13 +0530 Subject: [PATCH 17/72] feat: remove workflow --- .github/workflows/deploy.yaml | 119 ---------------------------------- 1 file changed, 119 deletions(-) delete mode 100644 .github/workflows/deploy.yaml diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml deleted file mode 100644 index 97cbca0..0000000 --- a/.github/workflows/deploy.yaml +++ /dev/null @@ -1,119 +0,0 @@ -name: Continuous Deployment Pipeline - -on: - push: - branches: - - "main" - paths-ignore: - - "**.md" - - "LICENSE" - - "LICENSE.txt" - - "frontend/**" - -jobs: - dockerhub: - name: Publish Docker Image(s) to Dockerhub - runs-on: ubuntu-latest - - steps: - - name: Checkout Repository - uses: actions/checkout@v4 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_PASSWORD }} - - - name: Cache Docker layers SERVICE_NAME - uses: actions/cache@v3 - with: - path: /tmp/.buildx-cache-SERVICE_NAME - key: ${{ runner.os }}-buildx-SERVICE_NAME-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-buildx-SERVICE_NAME- - - - name: Build & Push SERVICE_NAME - uses: docker/build-push-action@v5 - with: - context: . - push: true - tags: ${{ secrets.DOCKERHUB_USERNAME }}/SERVICE_NAME:latest - cache-from: type=local,src=/tmp/.buildx-cache-SERVICE_NAME - cache-to: type=local,dest=/tmp/.buildx-cache-SERVICE_NAME-new,mode=max - - - name: Move SERVICE_NAME cache - run: | - rm -rf /tmp/.buildx-cache-SERVICE_NAME - mv /tmp/.buildx-cache-SERVICE_NAME-new /tmp/.buildx-cache-SERVICE_NAME - - push: - name: Push Code Stage - needs: dockerhub - runs-on: ubuntu-latest - - steps: - - name: Sync local repo with remote repo - uses: appleboy/ssh-action@master - env: - PROJECT_DIR: ${{ secrets.PROJECT_DIR }} - with: - host: ${{ secrets.SSH_HOSTNAME }} - username: ${{ secrets.SSH_USERNAME }} - key: ${{ secrets.SSH_PRIVATE_KEY }} - passphrase: ${{ secrets.SSH_PRIVATE_KEY_PASSPHRASE }} - envs: PROJECT_DIR - script_stop: true - script: | - cd "${PROJECT_DIR}/" - sudo git fetch origin - sudo git reset --hard origin/main - - pull: - name: Pull Image Stage - needs: push - runs-on: ubuntu-latest - - steps: - - name: Pull the latest images(s) - uses: appleboy/ssh-action@master - env: - PROJECT_DIR: ${{ secrets.PROJECT_DIR }} - with: - host: ${{ secrets.SSH_HOSTNAME }} - username: ${{ secrets.SSH_USERNAME }} - key: ${{ secrets.SSH_PRIVATE_KEY }} - passphrase: ${{ secrets.SSH_PRIVATE_KEY_PASSPHRASE }} - envs: PROJECT_DIR - script_stop: true - script: | - cd "${PROJECT_DIR}/" - sudo docker compose pull - - deploy: - name: Deploy Stage - needs: pull - runs-on: ubuntu-latest - - steps: - - name: Deploy the latest build(s) - uses: appleboy/ssh-action@master - env: - PROJECT_DIR: ${{ secrets.PROJECT_DIR }} - with: - host: ${{ secrets.SSH_HOSTNAME }} - username: ${{ secrets.SSH_USERNAME }} - key: ${{ secrets.SSH_PRIVATE_KEY }} - passphrase: ${{ secrets.SSH_PRIVATE_KEY_PASSPHRASE }} - envs: PROJECT_DIR - script_stop: true - script: | - cd "${PROJECT_DIR}/" - sudo docker compose down - sudo docker compose up -d From a82444838686915ab579132460356b1b2fae8ab0 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Wed, 2 Oct 2024 11:34:54 +0530 Subject: [PATCH 18/72] feat: update docs --- README.md | 73 ++++++++++++++++++++++++++----------------------------- 1 file changed, 34 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 339cf3d..b3a70b1 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ [![Stargazers][stars-shield]][stars-url] [![Issues][issues-shield]][issues-url] [![MIT License][license-shield]][license-url] -[![Wiki][wiki-shield]][wiki-url] + @@ -17,19 +17,19 @@
- + image -

PROJECT_NAME

+

FNB

- Project one liner slogan goes here + Freaking NoticeBoard
Website · - Request Feature / Report Bug + Request Feature / Report Bug

@@ -61,21 +61,14 @@ -_Detailed explaination of the project goes here_ - +This a microservice designed to send notceboard messages for the internal noticeboard to Naarad (NTFY). It uses the SSO token and jsessionid to access the noticeboard present in the erp. It checks for a new message every 2 minutes.

(back to top)

-### Supports: - -1. Shells - * `bash` - * `zsh` -2. OS(s) - * any `*nix`[`GNU+Linux` and `Unix`] + -

(back to top)

+ ## Getting Started @@ -84,10 +77,7 @@ To set up a local instance of the application, follow the steps below. ### Prerequisites The following dependencies are required to be installed for the project to function properly: -* npm - ```sh - npm install npm@latest -g - ``` +* [golang](https://go.dev/doc/install)

(back to top)

@@ -97,16 +87,21 @@ _Now that the environment has been set up and configured to properly compile and 1. Clone the repository ```sh - git clone https://github.com/metakgp/PROJECT_NAME.git + git clone https://github.com/bikram-ghuku/fnb.git ``` -2. Make the script executable +2. Change directory to the folder ```sh - cd ./PROJECT_NAME - chmod +x ./PROJECT_NAME + cd ./fnb ``` -3. Execute the script +3. Copy the `.env.example` to `.env` file + ```shell + cp .env.example .env + ``` +4. Fill up the credentials by opening erp and checking cookies + +5. Execute the script ```sh - ./PROJECT_NAME + go run main.go ```

(back to top)

@@ -118,14 +113,14 @@ _Now that the environment has been set up and configured to properly compile and Use this space to show useful examples of how this project can be used. Additional screenshots, code examples and demos work well in this space.

(back to top)

-## Contact + ### Maintainer(s) The currently active maintainer(s) of this project. -- [NAME](https://github.com/GITHUB_USERNAME) +- [Bikram Ghuku](https://github.com/GITHUB_USERNAME) ### Creator(s) Honoring the original creator(s) and ideator(s) of this project. -- [NAME](https://github.com/GITHUB_USERNAME) +- [Arpit Bhardwaj](https://github.com/proffapt)

(back to top)

@@ -176,16 +171,16 @@ Honoring the original creator(s) and ideator(s) of this project. -[contributors-shield]: https://img.shields.io/github/contributors/metakgp/PROJECT_NAME.svg?style=for-the-badge -[contributors-url]: https://github.com/metakgp/PROJECT_NAME/graphs/contributors -[forks-shield]: https://img.shields.io/github/forks/metakgp/PROJECT_NAME.svg?style=for-the-badge +[contributors-shield]: https://img.shields.io/github/contributors/bikram-ghuku/fnb.svg?style=for-the-badge +[contributors-url]: https://github.com/bikram-ghuku/fnb/graphs/contributors +[forks-shield]: https://img.shields.io/github/forks/bikram-ghuku/fnb.svg?style=for-the-badge [forks-url]: https://github.com/metakgp/PROJECT_NAME/network/members -[stars-shield]: https://img.shields.io/github/stars/metakgp/PROJECT_NAME.svg?style=for-the-badge -[stars-url]: https://github.com/metakgp/PROJECT_NAME/stargazers -[issues-shield]: https://img.shields.io/github/issues/metakgp/PROJECT_NAME.svg?style=for-the-badge -[issues-url]: https://github.com/metakgp/PROJECT_NAME/issues -[license-shield]: https://img.shields.io/github/license/metakgp/PROJECT_NAME.svg?style=for-the-badge -[license-url]: https://github.com/metakgp/PROJECT_NAME/blob/master/LICENSE +[stars-shield]: https://img.shields.io/github/stars/bikram-ghuku/fnb.svg?style=for-the-badge +[stars-url]: https://github.com/bikram-ghuku/fnb/stargazers +[issues-shield]: https://img.shields.io/github/issues/bikram-ghuku/fnb.svg?style=for-the-badge +[issues-url]: https://github.com/bikram-ghuku/fnb/issues +[license-shield]: https://img.shields.io/github/license/bikram-ghuku/fnb.svg?style=for-the-badge +[license-url]: https://github.com/bikram-ghuku/fnb/blob/master/LICENSE [wiki-shield]: https://custom-icon-badges.demolab.com/badge/metakgp_wiki-grey?logo=metakgp_logo&style=for-the-badge [wiki-url]: https://wiki.metakgp.org [slack-url]: https://slack.metakgp.org From 682dede471f2e9d546a7f759ebe9fbfa43e3ae10 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Wed, 2 Oct 2024 11:35:28 +0530 Subject: [PATCH 19/72] feat: added example env file --- .env.example | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..a7603c1 --- /dev/null +++ b/.env.example @@ -0,0 +1,2 @@ +JSESSIONID= +ssoToken= \ No newline at end of file From 5c2ea5ec5777cae7cbba815170a07248c8f22159 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Wed, 2 Oct 2024 11:44:24 +0530 Subject: [PATCH 20/72] feat: made repeat after time a env var --- .env.example | 3 ++- main.go | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index a7603c1..cabdf81 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1,3 @@ JSESSIONID= -ssoToken= \ No newline at end of file +ssoToken= +REPEAT=120 \ No newline at end of file diff --git a/main.go b/main.go index c4c1a7a..ae1a37c 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,7 @@ import ( "net/http/cookiejar" "net/url" "os" + "strconv" "time" "github.com/joho/godotenv" @@ -33,6 +34,8 @@ var ( FileEndpoint string ERPCatCodeTopicMap map[int]string Client http.Client + TimeRepeat int64 + err error ) func RunCron() { @@ -42,7 +45,7 @@ func RunCron() { log.Printf("Getting notices for %s", value) getNewNotices(key) } - time.Sleep(30 * time.Second) + time.Sleep(time.Duration(TimeRepeat) * time.Second) } } @@ -160,6 +163,11 @@ func main() { godotenv.Load() ERPJSession = os.Getenv("JSESSIONID") ERPSSOToken = os.Getenv("ssoToken") + TimeRepeat, err = strconv.ParseInt(os.Getenv("REPEAT"), 10, 10) + if err != nil { + TimeRepeat = 120 + log.Printf("Error Parsing repeat time: %s", err.Error()) + } ERPCatCodeTopicMap = map[int]string{ 11: "Academic", From b869d91196e5937d2b3d1aa06eaaf787c107763b Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Wed, 2 Oct 2024 11:46:05 +0530 Subject: [PATCH 21/72] refactor: message --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index ae1a37c..a380c40 100644 --- a/main.go +++ b/main.go @@ -166,7 +166,7 @@ func main() { TimeRepeat, err = strconv.ParseInt(os.Getenv("REPEAT"), 10, 10) if err != nil { TimeRepeat = 120 - log.Printf("Error Parsing repeat time: %s", err.Error()) + log.Printf("Error Parsing repeat time, set to 2mins") } ERPCatCodeTopicMap = map[int]string{ From 3bb2808d33c72382d03c5dd6d3c7e900f1f75440 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Wed, 2 Oct 2024 11:51:32 +0530 Subject: [PATCH 22/72] feat: handle attachements --- main.go | 1 + 1 file changed, 1 insertion(+) diff --git a/main.go b/main.go index a380c40..81d2e09 100644 --- a/main.go +++ b/main.go @@ -69,6 +69,7 @@ func getNewNotices(channel int) { i := 0 for i < len(resBody) && resBody[i].MessageId != lastNoticeId && resBody[i].SerialNo != lastNoticeId { + resBody[i].AttachmentURL = fmt.Sprintf(FileEndpoint, resBody[i].Attachment) PrintNewMsg(ERPCatCodeTopicMap[channel], resBody[i]) i++ } From 6968777312692d6f0d37a174ef02e01418bd5378 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Thu, 3 Oct 2024 00:12:41 +0530 Subject: [PATCH 23/72] feat: require only sso token --- .env.example | 1 - main.go | 4 ---- 2 files changed, 5 deletions(-) diff --git a/.env.example b/.env.example index cabdf81..a4abbb1 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,2 @@ -JSESSIONID= ssoToken= REPEAT=120 \ No newline at end of file diff --git a/main.go b/main.go index 81d2e09..20ef2e5 100644 --- a/main.go +++ b/main.go @@ -148,10 +148,6 @@ func initClient() { func MakeCookies() []*http.Cookie { var Cookies []*http.Cookie - Cookies = append(Cookies, &http.Cookie{ - Name: "JSESSION", - Value: ERPJSession, - }) Cookies = append(Cookies, &http.Cookie{ Name: "ssoToken", From 80d85e44369d32aac66ec6d923f31ee2c898de8e Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Thu, 3 Oct 2024 00:40:53 +0530 Subject: [PATCH 24/72] feat: added modules --- go.mod | 7 ++++++- go.sum | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 7b75a8b..72a8d04 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,9 @@ module github.com/bikram-ghuku/finb go 1.23.1 -require github.com/joho/godotenv v1.5.1 +require ( + github.com/joho/godotenv v1.5.1 + golang.org/x/term v0.24.0 +) + +require golang.org/x/sys v0.25.0 // indirect diff --git a/go.sum b/go.sum index d61b19e..53b6c91 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,6 @@ github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= +golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= +golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.24.0 h1:Mh5cbb+Zk2hqqXNO7S1iTjEphVL+jb8ZWaqh/g+JWkM= +golang.org/x/term v0.24.0/go.mod h1:lOBK/LVxemqiMij05LGJ0tzNr8xlmwBRJ81PX6wVLH8= From 89dd64914f95ddccb3521fc005e0fa4bc5466fcb Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Thu, 3 Oct 2024 00:46:34 +0530 Subject: [PATCH 25/72] feat: added erp login --- endpoints.go | 10 +++++ erplogin.go | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+) create mode 100644 endpoints.go create mode 100644 erplogin.go diff --git a/endpoints.go b/endpoints.go new file mode 100644 index 0000000..4aadc31 --- /dev/null +++ b/endpoints.go @@ -0,0 +1,10 @@ +package main + +const ( + PING_URL = "iitkgp.ac.in" + HOMEPAGE_URL = "https://erp.iitkgp.ac.in/IIT_ERP3/" + WELCOMEPAGE_URL = "https://erp.iitkgp.ac.in/IIT_ERP3/welcome.jsp" + LOGIN_URL = "https://erp.iitkgp.ac.in/SSOAdministration/auth.htm" + SECRET_QUESTION_URL = "https://erp.iitkgp.ac.in/SSOAdministration/getSecurityQues.htm" + OTP_URL = "https://erp.iitkgp.ac.in/SSOAdministration/getEmilOTP.htm" +) diff --git a/erplogin.go b/erplogin.go new file mode 100644 index 0000000..6c6653d --- /dev/null +++ b/erplogin.go @@ -0,0 +1,109 @@ +package main + +import ( + "fmt" + "io" + "log" + "net/http" + "net/url" + "strings" + "syscall" + + "golang.org/x/term" +) + +type loginDetails struct { + user_id string + password string + answer string + requestedUrl string + email_otp string +} + +type erpCreds struct { + RollNumber string `json:"roll_number"` + Password string `json:"password"` + SecurityQuestionsAnswers map[string]string `json:"answers"` +} + +func getCreds(client *http.Client) loginDetails { + loginParams := loginDetails{ + requestedUrl: HOMEPAGE_URL, + } + + fmt.Print("Enter Roll No.: ") + fmt.Scan(&loginParams.user_id) + + fmt.Print("Enter ERP Password: ") + byte_password, err := term.ReadPassword(int(syscall.Stdin)) + if err != nil { + log.Printf(err.Error()) + } + + fmt.Printf("Your secret question: %s\n", getSecretQuestion(client, loginParams.user_id)) + fmt.Print("Enter answer to your secret question: ") + byte_answer, err := term.ReadPassword(int(syscall.Stdin)) + if err != nil { + log.Printf(err.Error()) + } + + fmt.Println("Enter your OTP sent to email: ") + byte_otp, err := term.ReadPassword(int(syscall.Stdin)) + if err != nil { + log.Printf(err.Error()) + } + + loginParams.answer = string(byte_answer) + loginParams.password = string(byte_password) + loginParams.email_otp = string(byte_otp) + + return loginParams +} + +func getSecretQuestion(client *http.Client, roll_number string) string { + data := map[string][]string{ + "user_id": {roll_number}, + } + + res, err := client.PostForm(SECRET_QUESTION_URL, data) + if err != nil { + log.Printf(err.Error()) + } + defer res.Body.Close() + + body, err := io.ReadAll(res.Body) + if err != nil { + log.Printf(err.Error()) + } + + return string(body) +} + +func ERPSession() string { + client := http.Client{} + loginParams := getCreds(&client) + data := url.Values{} + data.Set("user_id", loginParams.user_id) + data.Set("password", loginParams.password) + data.Set("answer", loginParams.answer) + data.Set("requestedUrl", loginParams.requestedUrl) + data.Set("email_otp", loginParams.email_otp) + + res, err := client.PostForm(LOGIN_URL, data) + if err != nil { + log.Printf(err.Error()) + } + defer res.Body.Close() + + body, err := io.ReadAll(res.Body) + if err != nil { + log.Printf(err.Error()) + } + + bodyStr := string(body) + idx := strings.Index(bodyStr, "ssoToken") + ssoToken := bodyStr[strings.LastIndex(bodyStr[:idx], "\"")+1 : strings.Index(bodyStr, "ssoToken")+strings.Index(bodyStr[idx:], "\"")] + + return ssoToken + +} From e81f446b618b8b4acbbd48d1bc19a5c6e75b2b78 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Thu, 3 Oct 2024 00:50:28 +0530 Subject: [PATCH 26/72] feat: add to new package --- endpoints.go => erplogin/endpoints.go | 2 +- erplogin.go => erplogin/erplogin.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename endpoints.go => erplogin/endpoints.go (96%) rename erplogin.go => erplogin/erplogin.go (99%) diff --git a/endpoints.go b/erplogin/endpoints.go similarity index 96% rename from endpoints.go rename to erplogin/endpoints.go index 4aadc31..eaa44e4 100644 --- a/endpoints.go +++ b/erplogin/endpoints.go @@ -1,4 +1,4 @@ -package main +package erplogin const ( PING_URL = "iitkgp.ac.in" diff --git a/erplogin.go b/erplogin/erplogin.go similarity index 99% rename from erplogin.go rename to erplogin/erplogin.go index 6c6653d..2551162 100644 --- a/erplogin.go +++ b/erplogin/erplogin.go @@ -1,4 +1,4 @@ -package main +package erplogin import ( "fmt" From b864d0821cad626fdfb45388c93ab8a4af1efb10 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Thu, 3 Oct 2024 00:50:51 +0530 Subject: [PATCH 27/72] feat: added erp creds --- main.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 20ef2e5..1fed8d3 100644 --- a/main.go +++ b/main.go @@ -11,6 +11,7 @@ import ( "strconv" "time" + "github.com/bikram-ghuku/finb/erplogin" "github.com/joho/godotenv" ) @@ -158,8 +159,8 @@ func MakeCookies() []*http.Cookie { func main() { godotenv.Load() - ERPJSession = os.Getenv("JSESSIONID") - ERPSSOToken = os.Getenv("ssoToken") + + ERPSSOToken = erplogin.ERPSession() TimeRepeat, err = strconv.ParseInt(os.Getenv("REPEAT"), 10, 10) if err != nil { TimeRepeat = 120 From 9954ae10abb2c064afc48e6ed26d2dc34d3d1183 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Thu, 3 Oct 2024 00:56:36 +0530 Subject: [PATCH 28/72] feat: add otp --- erplogin/erplogin.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/erplogin/erplogin.go b/erplogin/erplogin.go index 2551162..0038939 100644 --- a/erplogin/erplogin.go +++ b/erplogin/erplogin.go @@ -26,6 +26,21 @@ type erpCreds struct { SecurityQuestionsAnswers map[string]string `json:"answers"` } +func request_otp(client http.Client, loginParams loginDetails) { + data := url.Values{} + data.Set("typeee", "SI") + data.Set("user_id", loginParams.user_id) + data.Set("password", loginParams.password) + data.Set("answer", loginParams.answer) + + res, err := client.PostForm(OTP_URL, data) + if err != nil { + log.Printf(err.Error()) + } + + defer res.Body.Close() +} + func getCreds(client *http.Client) loginDetails { loginParams := loginDetails{ requestedUrl: HOMEPAGE_URL, @@ -47,14 +62,19 @@ func getCreds(client *http.Client) loginDetails { log.Printf(err.Error()) } + fmt.Println() + + loginParams.answer = string(byte_answer) + loginParams.password = string(byte_password) + + request_otp(*client, loginParams) + fmt.Println("Enter your OTP sent to email: ") byte_otp, err := term.ReadPassword(int(syscall.Stdin)) if err != nil { log.Printf(err.Error()) } - loginParams.answer = string(byte_answer) - loginParams.password = string(byte_password) loginParams.email_otp = string(byte_otp) return loginParams From b0a03773e1c445f1d835b9ac4abbd4686c224a5d Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Thu, 3 Oct 2024 11:29:46 +0530 Subject: [PATCH 29/72] feat: add empty security question checker --- erplogin/erplogin.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/erplogin/erplogin.go b/erplogin/erplogin.go index 0038939..425095b 100644 --- a/erplogin/erplogin.go +++ b/erplogin/erplogin.go @@ -55,8 +55,14 @@ func getCreds(client *http.Client) loginDetails { log.Printf(err.Error()) } - fmt.Printf("Your secret question: %s\n", getSecretQuestion(client, loginParams.user_id)) + quest := getSecretQuestion(client, loginParams.user_id) + if quest == "FALSE" { + return loginDetails{} + } + + fmt.Printf("Your secret question: %s\n", quest) fmt.Print("Enter answer to your secret question: ") + byte_answer, err := term.ReadPassword(int(syscall.Stdin)) if err != nil { log.Printf(err.Error()) From 5c80e0717e6aedf0b9f3e053ee7078bcdf911c4c Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Thu, 3 Oct 2024 20:34:13 +0530 Subject: [PATCH 30/72] feat: remove login scripts --- erplogin/endpoints.go | 10 ---- erplogin/erplogin.go | 135 ------------------------------------------ go.mod | 7 +-- go.sum | 4 -- main.go | 3 +- 5 files changed, 2 insertions(+), 157 deletions(-) delete mode 100644 erplogin/endpoints.go delete mode 100644 erplogin/erplogin.go diff --git a/erplogin/endpoints.go b/erplogin/endpoints.go deleted file mode 100644 index eaa44e4..0000000 --- a/erplogin/endpoints.go +++ /dev/null @@ -1,10 +0,0 @@ -package erplogin - -const ( - PING_URL = "iitkgp.ac.in" - HOMEPAGE_URL = "https://erp.iitkgp.ac.in/IIT_ERP3/" - WELCOMEPAGE_URL = "https://erp.iitkgp.ac.in/IIT_ERP3/welcome.jsp" - LOGIN_URL = "https://erp.iitkgp.ac.in/SSOAdministration/auth.htm" - SECRET_QUESTION_URL = "https://erp.iitkgp.ac.in/SSOAdministration/getSecurityQues.htm" - OTP_URL = "https://erp.iitkgp.ac.in/SSOAdministration/getEmilOTP.htm" -) diff --git a/erplogin/erplogin.go b/erplogin/erplogin.go deleted file mode 100644 index 425095b..0000000 --- a/erplogin/erplogin.go +++ /dev/null @@ -1,135 +0,0 @@ -package erplogin - -import ( - "fmt" - "io" - "log" - "net/http" - "net/url" - "strings" - "syscall" - - "golang.org/x/term" -) - -type loginDetails struct { - user_id string - password string - answer string - requestedUrl string - email_otp string -} - -type erpCreds struct { - RollNumber string `json:"roll_number"` - Password string `json:"password"` - SecurityQuestionsAnswers map[string]string `json:"answers"` -} - -func request_otp(client http.Client, loginParams loginDetails) { - data := url.Values{} - data.Set("typeee", "SI") - data.Set("user_id", loginParams.user_id) - data.Set("password", loginParams.password) - data.Set("answer", loginParams.answer) - - res, err := client.PostForm(OTP_URL, data) - if err != nil { - log.Printf(err.Error()) - } - - defer res.Body.Close() -} - -func getCreds(client *http.Client) loginDetails { - loginParams := loginDetails{ - requestedUrl: HOMEPAGE_URL, - } - - fmt.Print("Enter Roll No.: ") - fmt.Scan(&loginParams.user_id) - - fmt.Print("Enter ERP Password: ") - byte_password, err := term.ReadPassword(int(syscall.Stdin)) - if err != nil { - log.Printf(err.Error()) - } - - quest := getSecretQuestion(client, loginParams.user_id) - if quest == "FALSE" { - return loginDetails{} - } - - fmt.Printf("Your secret question: %s\n", quest) - fmt.Print("Enter answer to your secret question: ") - - byte_answer, err := term.ReadPassword(int(syscall.Stdin)) - if err != nil { - log.Printf(err.Error()) - } - - fmt.Println() - - loginParams.answer = string(byte_answer) - loginParams.password = string(byte_password) - - request_otp(*client, loginParams) - - fmt.Println("Enter your OTP sent to email: ") - byte_otp, err := term.ReadPassword(int(syscall.Stdin)) - if err != nil { - log.Printf(err.Error()) - } - - loginParams.email_otp = string(byte_otp) - - return loginParams -} - -func getSecretQuestion(client *http.Client, roll_number string) string { - data := map[string][]string{ - "user_id": {roll_number}, - } - - res, err := client.PostForm(SECRET_QUESTION_URL, data) - if err != nil { - log.Printf(err.Error()) - } - defer res.Body.Close() - - body, err := io.ReadAll(res.Body) - if err != nil { - log.Printf(err.Error()) - } - - return string(body) -} - -func ERPSession() string { - client := http.Client{} - loginParams := getCreds(&client) - data := url.Values{} - data.Set("user_id", loginParams.user_id) - data.Set("password", loginParams.password) - data.Set("answer", loginParams.answer) - data.Set("requestedUrl", loginParams.requestedUrl) - data.Set("email_otp", loginParams.email_otp) - - res, err := client.PostForm(LOGIN_URL, data) - if err != nil { - log.Printf(err.Error()) - } - defer res.Body.Close() - - body, err := io.ReadAll(res.Body) - if err != nil { - log.Printf(err.Error()) - } - - bodyStr := string(body) - idx := strings.Index(bodyStr, "ssoToken") - ssoToken := bodyStr[strings.LastIndex(bodyStr[:idx], "\"")+1 : strings.Index(bodyStr, "ssoToken")+strings.Index(bodyStr[idx:], "\"")] - - return ssoToken - -} diff --git a/go.mod b/go.mod index 72a8d04..7b75a8b 100644 --- a/go.mod +++ b/go.mod @@ -2,9 +2,4 @@ module github.com/bikram-ghuku/finb go 1.23.1 -require ( - github.com/joho/godotenv v1.5.1 - golang.org/x/term v0.24.0 -) - -require golang.org/x/sys v0.25.0 // indirect +require github.com/joho/godotenv v1.5.1 diff --git a/go.sum b/go.sum index 53b6c91..d61b19e 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,2 @@ github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= -golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= -golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.24.0 h1:Mh5cbb+Zk2hqqXNO7S1iTjEphVL+jb8ZWaqh/g+JWkM= -golang.org/x/term v0.24.0/go.mod h1:lOBK/LVxemqiMij05LGJ0tzNr8xlmwBRJ81PX6wVLH8= diff --git a/main.go b/main.go index 1fed8d3..21b0152 100644 --- a/main.go +++ b/main.go @@ -11,7 +11,6 @@ import ( "strconv" "time" - "github.com/bikram-ghuku/finb/erplogin" "github.com/joho/godotenv" ) @@ -160,7 +159,7 @@ func MakeCookies() []*http.Cookie { func main() { godotenv.Load() - ERPSSOToken = erplogin.ERPSession() + ERPSSOToken = os.Getenv("ssoToken") TimeRepeat, err = strconv.ParseInt(os.Getenv("REPEAT"), 10, 10) if err != nil { TimeRepeat = 120 From ec6ab4b3dbefb4b371ae6884841326b7fbe8a7ee Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Fri, 4 Oct 2024 11:39:21 +0530 Subject: [PATCH 31/72] fix: merge conflicts --- README.md | 44 -------------------------------------------- 1 file changed, 44 deletions(-) diff --git a/README.md b/README.md index d894946..b3a70b1 100644 --- a/README.md +++ b/README.md @@ -9,11 +9,7 @@ [![Stargazers][stars-shield]][stars-url] [![Issues][issues-shield]][issues-url] [![MIT License][license-shield]][license-url] -<<<<<<< HEAD -[![Wiki][wiki-shield]][wiki-url] -======= ->>>>>>> origin/main @@ -21,21 +17,6 @@
-<<<<<<< HEAD - - image - - -

PROJECT_NAME

- -

- - Project one liner slogan goes here -
- Website - · - Request Feature / Report Bug -======= image @@ -49,7 +30,6 @@ Website · Request Feature / Report Bug ->>>>>>> origin/main

@@ -81,31 +61,14 @@ -<<<<<<< HEAD -_Detailed explaination of the project goes here_ - -======= This a microservice designed to send notceboard messages for the internal noticeboard to Naarad (NTFY). It uses the SSO token and jsessionid to access the noticeboard present in the erp. It checks for a new message every 2 minutes. ->>>>>>> origin/main

(back to top)

-<<<<<<< HEAD -### Supports: - -1. Shells - * `bash` - * `zsh` -2. OS(s) - * any `*nix`[`GNU+Linux` and `Unix`] - -

(back to top)

-======= ->>>>>>> origin/main ## Getting Started @@ -114,14 +77,7 @@ To set up a local instance of the application, follow the steps below. ### Prerequisites The following dependencies are required to be installed for the project to function properly: -<<<<<<< HEAD -* npm - ```sh - npm install npm@latest -g - ``` -======= * [golang](https://go.dev/doc/install) ->>>>>>> origin/main

(back to top)

From d2b3419f8d352f27fd18c329cc0cf60bef4892d1 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Fri, 4 Oct 2024 11:44:13 +0530 Subject: [PATCH 32/72] docs(readme): update links --- README.md | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index b3a70b1..a01753e 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@
@@ -56,7 +56,7 @@ ## About The Project @@ -87,7 +87,7 @@ _Now that the environment has been set up and configured to properly compile and 1. Clone the repository ```sh - git clone https://github.com/bikram-ghuku/fnb.git + git clone https://github.com/metakgp/mfins.git ``` 2. Change directory to the folder ```sh @@ -113,43 +113,43 @@ _Now that the environment has been set up and configured to properly compile and Use this space to show useful examples of how this project can be used. Additional screenshots, code examples and demos work well in this space.

(back to top)

- + 📫 Metakgp - + + Metakgp's slack invite + + + Metakgp's email + + + metakgp's Facebook + + + metakgp's LinkedIn + + + metakgp's Twitter + + + metakgp's Instagram + +

### Maintainer(s) The currently active maintainer(s) of this project. -- [Bikram Ghuku](https://github.com/GITHUB_USERNAME) +- [Bikram Ghuku](https://github.com/bikram-ghuku) ### Creator(s) From 4f1415488814133e8eb19a82fd6e439efd0ced74 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Fri, 4 Oct 2024 11:45:35 +0530 Subject: [PATCH 33/72] docs(readme): update information --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a01753e..c6c5c02 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ [![Stargazers][stars-shield]][stars-url] [![Issues][issues-shield]][issues-url] [![MIT License][license-shield]][license-url] - +[![Wiki][wiki-shield]][wiki-url] @@ -91,7 +91,7 @@ _Now that the environment has been set up and configured to properly compile and ``` 2. Change directory to the folder ```sh - cd ./fnb + cd ./mfins ``` 3. Copy the `.env.example` to `.env` file ```shell From 1ace22957841101db8ab4e21b5d6fa38095d26f7 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Fri, 4 Oct 2024 11:49:23 +0530 Subject: [PATCH 34/72] docs(readme): update project details --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c6c5c02..faa4bdb 100644 --- a/README.md +++ b/README.md @@ -21,11 +21,11 @@ image -

FNB

+

MFINS

- Freaking NoticeBoard + My Freakin' Internal Noticeboard Scrapper
Website · From 1532dc2c32bc6b95b57068d9ee796c39efc1934e Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Fri, 4 Oct 2024 14:01:27 +0530 Subject: [PATCH 35/72] docs(readme): update stats links --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index faa4bdb..4054310 100644 --- a/README.md +++ b/README.md @@ -171,16 +171,16 @@ Honoring the original creator(s) and ideator(s) of this project. -[contributors-shield]: https://img.shields.io/github/contributors/bikram-ghuku/fnb.svg?style=for-the-badge -[contributors-url]: https://github.com/bikram-ghuku/fnb/graphs/contributors -[forks-shield]: https://img.shields.io/github/forks/bikram-ghuku/fnb.svg?style=for-the-badge +[contributors-shield]: https://img.shields.io/github/contributors/metakgp/mfins.svg?style=for-the-badge +[contributors-url]: https://github.com/metakgp/mfins/graphs/contributors +[forks-shield]: https://img.shields.io/github/forks/metakgp/mfins.svg?style=for-the-badge [forks-url]: https://github.com/metakgp/PROJECT_NAME/network/members -[stars-shield]: https://img.shields.io/github/stars/bikram-ghuku/fnb.svg?style=for-the-badge -[stars-url]: https://github.com/bikram-ghuku/fnb/stargazers -[issues-shield]: https://img.shields.io/github/issues/bikram-ghuku/fnb.svg?style=for-the-badge -[issues-url]: https://github.com/bikram-ghuku/fnb/issues -[license-shield]: https://img.shields.io/github/license/bikram-ghuku/fnb.svg?style=for-the-badge -[license-url]: https://github.com/bikram-ghuku/fnb/blob/master/LICENSE +[stars-shield]: https://img.shields.io/github/stars/metakgp/mfins.svg?style=for-the-badge +[stars-url]: https://github.com/metakgp/mfins/stargazers +[issues-shield]: https://img.shields.io/github/issues/metakgp/mfins.svg?style=for-the-badge +[issues-url]: https://github.com/metakgp/mfins/issues +[license-shield]: https://img.shields.io/github/license/metakgp/mfins.svg?style=for-the-badge +[license-url]: https://github.com/metakgp/mfins/blob/master/LICENSE [wiki-shield]: https://custom-icon-badges.demolab.com/badge/metakgp_wiki-grey?logo=metakgp_logo&style=for-the-badge [wiki-url]: https://wiki.metakgp.org [slack-url]: https://slack.metakgp.org From 6288ddbd6201333fc5cd39ae352a0343767d926e Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Fri, 4 Oct 2024 14:53:32 +0530 Subject: [PATCH 36/72] docs(readme): update logo link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4054310..d0977b1 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@

- image + image

MFINS

From 6c9565836bc15ffa57a522dce93e7004e3b2329a Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Sat, 5 Oct 2024 11:11:01 +0530 Subject: [PATCH 37/72] feat: added basic erp login --- .env.example | 3 +- erplogin/endpoints.go | 10 +++++ erplogin/login.go | 94 +++++++++++++++++++++++++++++++++++++++++++ main.go | 4 +- 4 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 erplogin/endpoints.go create mode 100644 erplogin/login.go diff --git a/.env.example b/.env.example index a4abbb1..b2ff5e2 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1,3 @@ -ssoToken= +rollno= +password= REPEAT=120 \ No newline at end of file diff --git a/erplogin/endpoints.go b/erplogin/endpoints.go new file mode 100644 index 0000000..c759550 --- /dev/null +++ b/erplogin/endpoints.go @@ -0,0 +1,10 @@ +package erplogin + +const ( + PING_URL = "iitkgp.ac.in" + HOMEPAGE_URL = "https://erp.iitkgp.ac.in/IIT_ERP3/" + WELCOMEPAGE_URL = "https://erp.iitkgp.ac.in/IIT_ERP3/welcome.jsp" + LOGIN_URL = "https://erp.iitkgp.ac.in/SSOAdministration/auth.htm" + SECRET_QUESTION_URL = "https://erp.iitkgp.ac.in/SSOAdministration/getSecurityQues.htm" + OTP_URL = "https://erp.iitkgp.ac.in/SSOAdministration/getEmilOTP.htm" // blame ERP for the typo +) diff --git a/erplogin/login.go b/erplogin/login.go new file mode 100644 index 0000000..4558f63 --- /dev/null +++ b/erplogin/login.go @@ -0,0 +1,94 @@ +package erplogin + +import ( + "fmt" + "io" + "log" + "net/http" + "net/url" + "os" +) + +var ( + rollNo string + password string + securiyAnswer string + emailOTP string +) + +func Login(client http.Client) string { + rollNo = os.Getenv("rollno") + password = os.Getenv("password") + + fmt.Printf("Security Question: %s", getSecurityQues(&client, rollNo)) + fmt.Println() + + fmt.Printf("Enter answer to security question: ") + fmt.Scan(&securiyAnswer) + + getOTP(&client) + + fmt.Printf("Enter OTP Sent to your email: ") + fmt.Scan(&emailOTP) + + loginBody(&client) + + return "" +} + +func getSecurityQues(client *http.Client, rollNo string) string { + data := url.Values{} + + data.Set("user_id", rollNo) + + res, err := client.PostForm(SECRET_QUESTION_URL, data) + + if err != nil { + log.Panic(err.Error()) + } + + byteResp, err := io.ReadAll(res.Body) + + defer res.Body.Close() + + return string(byteResp) +} + +func getOTP(client *http.Client) { + data := url.Values{} + data.Set("user_id", rollNo) + data.Set("password", password) + data.Set("answer", securiyAnswer) + data.Set("requestedUrl", HOMEPAGE_URL) + data.Set("typeee", "SI") + + res, err := client.PostForm(OTP_URL, data) + + if err != nil { + log.Panic(err.Error()) + } + + dataByte, _ := io.ReadAll(res.Body) + + log.Println(string(dataByte)) + + defer res.Body.Close() +} + +func loginBody(client *http.Client) { + data := url.Values{} + + data.Set("user_id", rollNo) + data.Set("password", password) + data.Set("answer", securiyAnswer) + data.Set("email_otp", emailOTP) + data.Set("requestedUrl", HOMEPAGE_URL) + + resp, err := client.PostForm(LOGIN_URL, data) + + if err != nil { + log.Panic(err.Error()) + } + + defer resp.Body.Close() +} diff --git a/main.go b/main.go index 21b0152..97a6e42 100644 --- a/main.go +++ b/main.go @@ -11,6 +11,7 @@ import ( "strconv" "time" + "github.com/bikram-ghuku/finb/erplogin" "github.com/joho/godotenv" ) @@ -159,7 +160,6 @@ func MakeCookies() []*http.Cookie { func main() { godotenv.Load() - ERPSSOToken = os.Getenv("ssoToken") TimeRepeat, err = strconv.ParseInt(os.Getenv("REPEAT"), 10, 10) if err != nil { TimeRepeat = 120 @@ -179,5 +179,7 @@ func main() { initClient() + erplogin.Login(Client) + RunCron() } From 2e7592c96bdb7935ac629d69c55035c75ad23b43 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Sat, 5 Oct 2024 11:21:40 +0530 Subject: [PATCH 38/72] feat: remove unwanted code --- main.go | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/main.go b/main.go index 97a6e42..458d2eb 100644 --- a/main.go +++ b/main.go @@ -6,7 +6,6 @@ import ( "log" "net/http" "net/http/cookiejar" - "net/url" "os" "strconv" "time" @@ -137,26 +136,11 @@ func initClient() { log.Fatalf("Error %s", err.Error()) } - parseURL, _ := url.Parse(NoticeEndpoint) - - jar.SetCookies(parseURL, MakeCookies()) - Client = http.Client{ Jar: jar, } } -func MakeCookies() []*http.Cookie { - - var Cookies []*http.Cookie - - Cookies = append(Cookies, &http.Cookie{ - Name: "ssoToken", - Value: ERPSSOToken, - }) - return Cookies -} - func main() { godotenv.Load() From ec329d7436267c135f1f355fc3dd67a130be6c8e Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Sat, 5 Oct 2024 11:24:27 +0530 Subject: [PATCH 39/72] feat: update pkg name --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 7b75a8b..05a8c1f 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/bikram-ghuku/finb +module github.com/metakgp/mfins go 1.23.1 From 230f21bbafa50dfcd66fa57605fde4b5b08a7382 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Sat, 5 Oct 2024 11:35:05 +0530 Subject: [PATCH 40/72] feat: added erplogin to cron --- main.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 458d2eb..14b4b17 100644 --- a/main.go +++ b/main.go @@ -10,8 +10,8 @@ import ( "strconv" "time" - "github.com/bikram-ghuku/finb/erplogin" "github.com/joho/godotenv" + "github.com/metakgp/mfins/erplogin" ) type NoticeElement struct { @@ -40,11 +40,17 @@ var ( func RunCron() { for true { + + log.Println("Logining Into ERP....") + erplogin.Login(Client) + log.Println("Getting messages....") + for key, value := range ERPCatCodeTopicMap { log.Printf("Getting notices for %s", value) getNewNotices(key) } + time.Sleep(time.Duration(TimeRepeat) * time.Second) } } @@ -163,7 +169,5 @@ func main() { initClient() - erplogin.Login(Client) - RunCron() } From 114e1201a5228b7ad8178287588db87206a57a74 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Sat, 5 Oct 2024 12:07:45 +0530 Subject: [PATCH 41/72] feat: continue session without relogin --- erplogin/login.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/erplogin/login.go b/erplogin/login.go index 4558f63..91177fb 100644 --- a/erplogin/login.go +++ b/erplogin/login.go @@ -16,7 +16,13 @@ var ( emailOTP string ) -func Login(client http.Client) string { +func Login(client http.Client) { + + if checkLogin(&client) { + log.Println("Already logged in, continuing without login") + return + } + rollNo = os.Getenv("rollno") password = os.Getenv("password") @@ -32,8 +38,6 @@ func Login(client http.Client) string { fmt.Scan(&emailOTP) loginBody(&client) - - return "" } func getSecurityQues(client *http.Client, rollNo string) string { @@ -92,3 +96,14 @@ func loginBody(client *http.Client) { defer resp.Body.Close() } + +func checkLogin(client *http.Client) bool { + + res, err := client.Get(WELCOMEPAGE_URL) + + if err != nil { + log.Panic(err.Error()) + } + + return res.ContentLength == 1034 +} From b2788663280f19d2143507df2fb616160498d5eb Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Sat, 5 Oct 2024 17:30:14 +0530 Subject: [PATCH 42/72] feat: added gmail libraries --- go.mod | 33 +++++++++++- go.sum | 156 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 188 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 05a8c1f..c454b9e 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,35 @@ module github.com/metakgp/mfins go 1.23.1 -require github.com/joho/godotenv v1.5.1 +require ( + github.com/joho/godotenv v1.5.1 + github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c + golang.org/x/oauth2 v0.23.0 + google.golang.org/api v0.199.0 +) + +require ( + cloud.google.com/go/auth v0.9.5 // indirect + cloud.google.com/go/auth/oauth2adapt v0.2.4 // indirect + cloud.google.com/go/compute/metadata v0.5.2 // indirect + github.com/felixge/httpsnoop v1.0.4 // indirect + github.com/go-logr/logr v1.4.2 // indirect + github.com/go-logr/stdr v1.2.2 // indirect + github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect + github.com/google/s2a-go v0.1.8 // indirect + github.com/google/uuid v1.6.0 // indirect + github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect + github.com/googleapis/gax-go/v2 v2.13.0 // indirect + go.opencensus.io v0.24.0 // indirect + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect + go.opentelemetry.io/otel v1.29.0 // indirect + go.opentelemetry.io/otel/metric v1.29.0 // indirect + go.opentelemetry.io/otel/trace v1.29.0 // indirect + golang.org/x/crypto v0.27.0 // indirect + golang.org/x/net v0.29.0 // indirect + golang.org/x/sys v0.25.0 // indirect + golang.org/x/text v0.18.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect + google.golang.org/grpc v1.67.0 // indirect + google.golang.org/protobuf v1.34.2 // indirect +) diff --git a/go.sum b/go.sum index d61b19e..7630e9b 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,158 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go/auth v0.9.5 h1:4CTn43Eynw40aFVr3GpPqsQponx2jv0BQpjvajsbbzw= +cloud.google.com/go/auth v0.9.5/go.mod h1:Xo0n7n66eHyOWWCnitop6870Ilwo3PiZyodVkkH1xWM= +cloud.google.com/go/auth/oauth2adapt v0.2.4 h1:0GWE/FUsXhf6C+jAkWgYm7X9tK8cuEIfy19DBn6B6bY= +cloud.google.com/go/auth/oauth2adapt v0.2.4/go.mod h1:jC/jOpwFP6JBxhB3P5Rr0a9HLMC/Pe3eaL4NmdvqPtc= +cloud.google.com/go/compute/metadata v0.5.2 h1:UxK4uu/Tn+I3p2dYWTfiX4wva7aYlKixAHn3fyqngqo= +cloud.google.com/go/compute/metadata v0.5.2/go.mod h1:C66sj2AluDcIqakBq/M8lw8/ybHgOZqin2obFxa/E5k= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= +github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/s2a-go v0.1.8 h1:zZDs9gcbt9ZPLV0ndSyQk6Kacx2g/X+SKYovpnz3SMM= +github.com/google/s2a-go v0.1.8/go.mod h1:6iNWHTpQ+nfNRN5E00MSdfDwVesa8hhS32PhPO8deJA= +github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/googleapis/enterprise-certificate-proxy v0.3.4 h1:XYIDZApgAnrN1c855gTgghdIA6Stxb52D5RnLI1SLyw= +github.com/googleapis/enterprise-certificate-proxy v0.3.4/go.mod h1:YKe7cfqYXjKGpGvmSg28/fFvhNzinZQm8DGnaburhGA= +github.com/googleapis/gax-go/v2 v2.13.0 h1:yitjD5f7jQHhyDsnhKEBU52NdvvdSeGzlAnDPT0hH1s= +github.com/googleapis/gax-go/v2 v2.13.0/go.mod h1:Z/fvTZXF8/uw7Xu5GuslPw+bplx6SS338j1Is2S+B7A= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= +github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ= +github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= +go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 h1:TT4fX+nBOA/+LUkobKGW1ydGcn+G3vRw9+g5HwCphpk= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0/go.mod h1:L7UH0GbB0p47T4Rri3uHjbpCFYrVrwc1I25QhNPiGK8= +go.opentelemetry.io/otel v1.29.0 h1:PdomN/Al4q/lN6iBJEN3AwPvUiHPMlt93c8bqTG5Llw= +go.opentelemetry.io/otel v1.29.0/go.mod h1:N/WtXPs1CNCUEx+Agz5uouwCba+i+bJGFicT8SR4NP8= +go.opentelemetry.io/otel/metric v1.29.0 h1:vPf/HFWTNkPu1aYeIsc98l4ktOQaL6LeSoeV2g+8YLc= +go.opentelemetry.io/otel/metric v1.29.0/go.mod h1:auu/QWieFVWx+DmQOUMgj0F8LHWdgalxXqvp7BII/W8= +go.opentelemetry.io/otel/trace v1.29.0 h1:J/8ZNK4XgR7a21DZUAsbF8pZ5Jcw1VhACmnYt39JTi4= +go.opentelemetry.io/otel/trace v1.29.0/go.mod h1:eHl3w0sp3paPkYstJOmAimxhiFXPg+MMTlEh3nsQgWQ= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A= +golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo= +golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs= +golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= +golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= +golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/api v0.199.0 h1:aWUXClp+VFJmqE0JPvpZOK3LDQMyFKYIow4etYd9qxs= +google.golang.org/api v0.199.0/go.mod h1:ohG4qSztDJmZdjK/Ar6MhbAmb/Rpi4JHOqagsh90K28= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/genproto v0.0.0-20240903143218-8af14fe29dc1 h1:BulPr26Jqjnd4eYDVe+YvyR7Yc2vJGkO5/0UxD0/jZU= +google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 h1:wKguEg1hsxI2/L3hUYrpo1RVi48K+uTyzKqprwLXsb8= +google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142/go.mod h1:d6be+8HhtEtucleCbxpPW9PA9XwISACu8nvpPqF0BVo= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 h1:pPJltXNxVzT4pK9yD8vR9X75DaWYYmLGMsEvBfFQZzQ= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= +google.golang.org/grpc v1.67.0 h1:IdH9y6PF5MPSdAntIcpjQ+tXO41pcQsfZV2RxtQgVcw= +google.golang.org/grpc v1.67.0/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= +google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= From 5069a7e8de033472cecc29f59692f53d02799b65 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Sat, 5 Oct 2024 17:49:44 +0530 Subject: [PATCH 43/72] feat: update gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 3e2f2e1..1c21911 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ node-modules/ .env lastmsg.json +client_secret.json +.token \ No newline at end of file From e4b07818fd7fad8763c2835fe6da34d5698f0e4e Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Sat, 5 Oct 2024 17:58:19 +0530 Subject: [PATCH 44/72] feat: added automated otp fetching --- erplogin/login.go | 11 +-- erplogin/optHandler.go | 181 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 183 insertions(+), 9 deletions(-) create mode 100644 erplogin/optHandler.go diff --git a/erplogin/login.go b/erplogin/login.go index 91177fb..474c3cd 100644 --- a/erplogin/login.go +++ b/erplogin/login.go @@ -32,10 +32,7 @@ func Login(client http.Client) { fmt.Printf("Enter answer to security question: ") fmt.Scan(&securiyAnswer) - getOTP(&client) - - fmt.Printf("Enter OTP Sent to your email: ") - fmt.Scan(&emailOTP) + emailOTP = GetOtp(&client) loginBody(&client) } @@ -58,7 +55,7 @@ func getSecurityQues(client *http.Client, rollNo string) string { return string(byteResp) } -func getOTP(client *http.Client) { +func SendOTP(client *http.Client) { data := url.Values{} data.Set("user_id", rollNo) data.Set("password", password) @@ -72,10 +69,6 @@ func getOTP(client *http.Client) { log.Panic(err.Error()) } - dataByte, _ := io.ReadAll(res.Body) - - log.Println(string(dataByte)) - defer res.Body.Close() } diff --git a/erplogin/optHandler.go b/erplogin/optHandler.go new file mode 100644 index 0000000..f585c9a --- /dev/null +++ b/erplogin/optHandler.go @@ -0,0 +1,181 @@ +package erplogin + +import ( + "context" + "encoding/base64" + "encoding/json" + "errors" + "fmt" + "log" + "net/http" + "os" + "regexp" + "time" + + "github.com/pkg/browser" + "golang.org/x/oauth2" + "golang.org/x/oauth2/google" + "google.golang.org/api/gmail/v1" + "google.golang.org/api/option" +) + +const ( + query = "from:erpkgp@adm.iitkgp.ac.in is:unread subject: otp" + RedirectURL = "http://localhost:7007" +) + +func GetOtp(client *http.Client) string { + if is_file("client_secret.json") || is_file(".token") { + return GetOtpEmail(client) + } else { + return GetOtpInput(client) + } +} + +func getMsgId(service *gmail.Service) string { + results, err := service.Users.Messages.List("me").Q(query).MaxResults(1).Do() + + if err != nil { + log.Fatal(err.Error()) + } + + if len(results.Messages) != 0 { + return results.Messages[0].Id + } + + return "" + +} + +func GetOtpEmail(client *http.Client) string { + ctx, cancel := context.WithCancel(context.Background()) + + conf := oauth2.Config{ + Scopes: []string{gmail.GmailReadonlyScope}, + Endpoint: google.Endpoint, + RedirectURL: RedirectURL, + } + + secretByte, err := os.ReadFile("client_secret.json") + + if err != nil { + log.Fatal(err.Error()) + } + + var secret map[string]map[string]json.RawMessage + err = json.Unmarshal(secretByte, &secret) + + _ = json.Unmarshal(secret["installed"]["client_id"], &conf.ClientID) + _ = json.Unmarshal(secret["installed"]["client_secret"], &conf.ClientSecret) + + var token *oauth2.Token + + if is_file(".token") { + + token_byte, err := os.ReadFile(".token") + if err != nil { + log.Fatal(err.Error()) + } + + err = json.Unmarshal(token_byte, &token) + if err != nil { + log.Fatal(err.Error()) + } + + } else { + token, err = generateToken(&ctx, cancel, &conf) + if err != nil { + log.Fatal(err.Error()) + } + + token_json, err := json.Marshal(*token) + if err != nil { + log.Fatal(err.Error()) + } + + err = os.WriteFile(".token", token_json, 0666) + if err != nil { + log.Fatal(err.Error()) + } + } + + if err != nil { + log.Fatal(err.Error()) + } + + service, err := gmail.NewService(ctx, option.WithTokenSource(conf.TokenSource(ctx, token))) + if err != nil { + log.Fatal(err.Error()) + } + + latestId := getMsgId(service) + SendOTP(client) + var mailId string + + for { + log.Println("Waiting for OTP...") + if mailId = getMsgId(service); mailId != latestId { + log.Println("OTP fetched") + break + } + time.Sleep(1 * time.Second) + } + + message, err := service.Users.Messages.Get("me", mailId).Do() + if err != nil { + log.Fatal(err.Error()) + } + + body, err := base64.URLEncoding.DecodeString(message.Payload.Body.Data) + if err != nil { + log.Fatal(err.Error()) + } + + reg := regexp.MustCompile("[0-9]+") + otp := reg.FindAllString(string(body), -1)[0] + + cancel() + return otp + +} + +func is_file(filename string) bool { + file, err := os.Open(filename) + defer file.Close() + return !errors.Is(err, os.ErrNotExist) +} + +func generateToken(ctx *context.Context, cancel context.CancelFunc, conf *oauth2.Config) (*oauth2.Token, error) { + authURL := conf.AuthCodeURL("666573902ekwjfn") + fmt.Println("Visit this URL for authentication: ", authURL) + browser.OpenURL(authURL) + + var token *oauth2.Token + var err error + + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + if r.URL.Query().Get("state") == "666573902ekwjfn" { + token, err = conf.Exchange(*ctx, r.URL.Query().Get("code")) + } + fmt.Fprintf(w, "Authentication complete. Check your terminal.") + cancel() + }) + + server := &http.Server{Addr: ":7007"} + go func() { + if err := server.ListenAndServe(); err != nil { + log.Fatal(err.Error()) + } + }() + <-(*ctx).Done() + return token, err +} + +func GetOtpInput(client *http.Client) string { + SendOTP(client) + var emailOTP string + fmt.Printf("Enter OTP Sent to your email: ") + fmt.Scan(&emailOTP) + + return emailOTP +} From 6a7c4f04b589119b53e03c2481b277fdf54a638c Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Sat, 5 Oct 2024 19:29:43 +0530 Subject: [PATCH 45/72] feat: confidential file --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1c21911..66f5b5f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ node-modules/ .env lastmsg.json client_secret.json -.token \ No newline at end of file +.token +security_question.json \ No newline at end of file From 6fdb456c4a5e3dfd435b372bbed00cc63ba63737 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Sat, 5 Oct 2024 19:30:10 +0530 Subject: [PATCH 46/72] feat: automatic security question handler --- erplogin/login.go | 24 +++++++------- erplogin/securityQuestion.go | 64 ++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 11 deletions(-) create mode 100644 erplogin/securityQuestion.go diff --git a/erplogin/login.go b/erplogin/login.go index 474c3cd..e07abcf 100644 --- a/erplogin/login.go +++ b/erplogin/login.go @@ -1,7 +1,6 @@ package erplogin import ( - "fmt" "io" "log" "net/http" @@ -10,10 +9,10 @@ import ( ) var ( - rollNo string - password string - securiyAnswer string - emailOTP string + rollNo string + password string + securityAnswer string + emailOTP string ) func Login(client http.Client) { @@ -26,11 +25,14 @@ func Login(client http.Client) { rollNo = os.Getenv("rollno") password = os.Getenv("password") - fmt.Printf("Security Question: %s", getSecurityQues(&client, rollNo)) - fmt.Println() + question := getSecurityQues(&client, rollNo) + securityAnswer = GetSecurityAnswer(question) - fmt.Printf("Enter answer to security question: ") - fmt.Scan(&securiyAnswer) + // fmt.Printf("Security Question: %s", getSecurityQues(&client, rollNo)) + // fmt.Println() + + // fmt.Printf("Enter answer to security question: ") + // fmt.Scan(&securityAnswer) emailOTP = GetOtp(&client) @@ -59,7 +61,7 @@ func SendOTP(client *http.Client) { data := url.Values{} data.Set("user_id", rollNo) data.Set("password", password) - data.Set("answer", securiyAnswer) + data.Set("answer", securityAnswer) data.Set("requestedUrl", HOMEPAGE_URL) data.Set("typeee", "SI") @@ -77,7 +79,7 @@ func loginBody(client *http.Client) { data.Set("user_id", rollNo) data.Set("password", password) - data.Set("answer", securiyAnswer) + data.Set("answer", securityAnswer) data.Set("email_otp", emailOTP) data.Set("requestedUrl", HOMEPAGE_URL) diff --git a/erplogin/securityQuestion.go b/erplogin/securityQuestion.go new file mode 100644 index 0000000..78523f7 --- /dev/null +++ b/erplogin/securityQuestion.go @@ -0,0 +1,64 @@ +package erplogin + +import ( + "encoding/json" + "fmt" + "log" + "os" +) + +var questionAnswer map[string]string + +const FILENAME = "security_question.json" + +func GetSecurityAnswer(question string) string { + + if is_file(FILENAME) { + + quesByte, err := os.ReadFile(FILENAME) + if err != nil { + log.Fatal(err.Error()) + } + + err = json.Unmarshal(quesByte, &questionAnswer) + if err != nil { + log.Fatal(err.Error()) + } + + questionAnswer[question] = inputAnswer(question) + + questionAnswerJson, err := json.Marshal(questionAnswer) + if err != nil { + log.Fatalf(err.Error()) + } + + os.WriteFile(FILENAME, questionAnswerJson, 0666) + + return questionAnswer[question] + + } else { + + questionAnswer[question] = inputAnswer(question) + + questionAnswerJson, err := json.Marshal(questionAnswer) + if err != nil { + log.Fatalf(err.Error()) + } + + os.WriteFile(FILENAME, questionAnswerJson, 0666) + + return questionAnswer[question] + + } + +} + +func inputAnswer(question string) string { + var answer string + fmt.Printf("Security question: %s", question) + fmt.Println() + fmt.Print("Enter answer to security question: ") + fmt.Scan(&answer) + + return answer +} From 0db5535810bc92c87c9e6a1b92e8ca403731e5d8 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Sat, 5 Oct 2024 19:38:14 +0530 Subject: [PATCH 47/72] feat: automatic security question handler --- erplogin/login.go | 6 ------ erplogin/securityQuestion.go | 11 ++++------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/erplogin/login.go b/erplogin/login.go index e07abcf..a948041 100644 --- a/erplogin/login.go +++ b/erplogin/login.go @@ -28,12 +28,6 @@ func Login(client http.Client) { question := getSecurityQues(&client, rollNo) securityAnswer = GetSecurityAnswer(question) - // fmt.Printf("Security Question: %s", getSecurityQues(&client, rollNo)) - // fmt.Println() - - // fmt.Printf("Enter answer to security question: ") - // fmt.Scan(&securityAnswer) - emailOTP = GetOtp(&client) loginBody(&client) diff --git a/erplogin/securityQuestion.go b/erplogin/securityQuestion.go index 78523f7..2ccd28e 100644 --- a/erplogin/securityQuestion.go +++ b/erplogin/securityQuestion.go @@ -25,7 +25,7 @@ func GetSecurityAnswer(question string) string { log.Fatal(err.Error()) } - questionAnswer[question] = inputAnswer(question) + inputAnswer(question) questionAnswerJson, err := json.Marshal(questionAnswer) if err != nil { @@ -37,8 +37,7 @@ func GetSecurityAnswer(question string) string { return questionAnswer[question] } else { - - questionAnswer[question] = inputAnswer(question) + inputAnswer(question) questionAnswerJson, err := json.Marshal(questionAnswer) if err != nil { @@ -48,17 +47,15 @@ func GetSecurityAnswer(question string) string { os.WriteFile(FILENAME, questionAnswerJson, 0666) return questionAnswer[question] - } - } -func inputAnswer(question string) string { +func inputAnswer(question string) { var answer string fmt.Printf("Security question: %s", question) fmt.Println() fmt.Print("Enter answer to security question: ") fmt.Scan(&answer) - return answer + questionAnswer[question] = answer } From 9b47023c62fca06903ee49defeece4e307a3e00d Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Sat, 5 Oct 2024 19:44:24 +0530 Subject: [PATCH 48/72] feat: read if already present --- erplogin/securityQuestion.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/erplogin/securityQuestion.go b/erplogin/securityQuestion.go index 2ccd28e..57f09bc 100644 --- a/erplogin/securityQuestion.go +++ b/erplogin/securityQuestion.go @@ -25,7 +25,11 @@ func GetSecurityAnswer(question string) string { log.Fatal(err.Error()) } - inputAnswer(question) + if val, ok := questionAnswer[question]; ok { + return val + } else { + inputAnswer(question) + } questionAnswerJson, err := json.Marshal(questionAnswer) if err != nil { From a55d9c03ae882efc3851e6fb2757def9f454859d Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Sat, 5 Oct 2024 19:49:54 +0530 Subject: [PATCH 49/72] feat: added logs --- erplogin/login.go | 3 +++ erplogin/optHandler.go | 4 ++++ erplogin/securityQuestion.go | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/erplogin/login.go b/erplogin/login.go index a948041..eb9ba7d 100644 --- a/erplogin/login.go +++ b/erplogin/login.go @@ -52,6 +52,7 @@ func getSecurityQues(client *http.Client, rollNo string) string { } func SendOTP(client *http.Client) { + log.Println("Requesting OTP....") data := url.Values{} data.Set("user_id", rollNo) data.Set("password", password) @@ -65,6 +66,8 @@ func SendOTP(client *http.Client) { log.Panic(err.Error()) } + log.Println("OTP requested successfully!") + defer res.Body.Close() } diff --git a/erplogin/optHandler.go b/erplogin/optHandler.go index f585c9a..3b94be6 100644 --- a/erplogin/optHandler.go +++ b/erplogin/optHandler.go @@ -26,8 +26,12 @@ const ( func GetOtp(client *http.Client) string { if is_file("client_secret.json") || is_file(".token") { + + log.Println("Found google OAuth credentials, Automatically reading OTP") + return GetOtpEmail(client) } else { + return GetOtpInput(client) } } diff --git a/erplogin/securityQuestion.go b/erplogin/securityQuestion.go index 57f09bc..cd390d7 100644 --- a/erplogin/securityQuestion.go +++ b/erplogin/securityQuestion.go @@ -15,6 +15,8 @@ func GetSecurityAnswer(question string) string { if is_file(FILENAME) { + log.Printf("Found %s, checking if question is present....", FILENAME) + quesByte, err := os.ReadFile(FILENAME) if err != nil { log.Fatal(err.Error()) @@ -26,6 +28,7 @@ func GetSecurityAnswer(question string) string { } if val, ok := questionAnswer[question]; ok { + log.Println("Found answer to security question!") return val } else { inputAnswer(question) @@ -41,6 +44,7 @@ func GetSecurityAnswer(question string) string { return questionAnswer[question] } else { + log.Printf("%s not found, creating.....", FILENAME) inputAnswer(question) questionAnswerJson, err := json.Marshal(questionAnswer) From be61f44c20884fed7b9c7f86ac7a52d5caa4638c Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Sun, 6 Oct 2024 10:34:08 +0530 Subject: [PATCH 50/72] docs(README): add installation instructions --- README.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d0977b1..ff6b8c0 100644 --- a/README.md +++ b/README.md @@ -97,9 +97,20 @@ _Now that the environment has been set up and configured to properly compile and ```shell cp .env.example .env ``` -4. Fill up the credentials by opening erp and checking cookies +4. Fill the .env files with your erp credentials -5. Execute the script +5. Create `lastmsg.json` and add `{}` in it + ```sh + touch lastmsg.json && echo {} > lastmsg.json + ``` +6. Create `security_question.json` and add `{}` to it + ```sh + touch security_question.json && echo {} > security_question.json + ``` + +7. Create a google OAuth client secret and client id and add it to `client_secret.json` + +8. Execute the script ```sh go run main.go ``` From 1926cba4d392e83cfe95dbffc5cec54d01621495 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Sun, 6 Oct 2024 11:11:49 +0530 Subject: [PATCH 51/72] feat: init ntfy --- .env.example | 1 + go.mod | 2 ++ go.sum | 4 ++++ 3 files changed, 7 insertions(+) diff --git a/.env.example b/.env.example index b2ff5e2..7fb762d 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,4 @@ rollno= password= +ntfyAddr= REPEAT=120 \ No newline at end of file diff --git a/go.mod b/go.mod index c454b9e..1dc4ebe 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/metakgp/mfins go 1.23.1 require ( + github.com/AnthonyHewins/gotfy v0.0.10 github.com/joho/godotenv v1.5.1 github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c golang.org/x/oauth2 v0.23.0 @@ -16,6 +17,7 @@ require ( github.com/felixge/httpsnoop v1.0.4 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect + github.com/goccy/go-json v0.10.2 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/google/s2a-go v0.1.8 // indirect github.com/google/uuid v1.6.0 // indirect diff --git a/go.sum b/go.sum index 7630e9b..c73d4e6 100644 --- a/go.sum +++ b/go.sum @@ -5,6 +5,8 @@ cloud.google.com/go/auth/oauth2adapt v0.2.4 h1:0GWE/FUsXhf6C+jAkWgYm7X9tK8cuEIfy cloud.google.com/go/auth/oauth2adapt v0.2.4/go.mod h1:jC/jOpwFP6JBxhB3P5Rr0a9HLMC/Pe3eaL4NmdvqPtc= cloud.google.com/go/compute/metadata v0.5.2 h1:UxK4uu/Tn+I3p2dYWTfiX4wva7aYlKixAHn3fyqngqo= cloud.google.com/go/compute/metadata v0.5.2/go.mod h1:C66sj2AluDcIqakBq/M8lw8/ybHgOZqin2obFxa/E5k= +github.com/AnthonyHewins/gotfy v0.0.10 h1:23ZjRVG7wuGuqn7CQq/bOrkXa3gg2XyYrrD3RYEmvE8= +github.com/AnthonyHewins/gotfy v0.0.10/go.mod h1:q2orErDDpl9/gZ5L4oJhejb7TaP/eBdtkzjWDruNRlg= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= @@ -23,6 +25,8 @@ github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= +github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= From 7321db3096d0a737b3cc272e7ba9ae112db640d7 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Sun, 6 Oct 2024 11:17:33 +0530 Subject: [PATCH 52/72] feat: add ntfy --- main.go | 7 ++++++- ntfy.go | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 ntfy.go diff --git a/main.go b/main.go index 14b4b17..73644ab 100644 --- a/main.go +++ b/main.go @@ -75,7 +75,10 @@ func getNewNotices(channel int) { i := 0 for i < len(resBody) && resBody[i].MessageId != lastNoticeId && resBody[i].SerialNo != lastNoticeId { - resBody[i].AttachmentURL = fmt.Sprintf(FileEndpoint, resBody[i].Attachment) + if resBody[i].Attachment != 0 { + resBody[i].AttachmentURL = fmt.Sprintf(FileEndpoint, resBody[i].Attachment) + } + PrintNewMsg(ERPCatCodeTopicMap[channel], resBody[i]) i++ } @@ -134,6 +137,8 @@ func setLastNotice(channel int, lastMsgId int) { func PrintNewMsg(channel string, content NoticeElement) { // this function is called upon receving a new message log.Printf("New message on channel %s: \n %v", channel, content.MessageSubject) + + PostData(channel, content) } func initClient() { diff --git a/ntfy.go b/ntfy.go new file mode 100644 index 0000000..c80f8f9 --- /dev/null +++ b/ntfy.go @@ -0,0 +1,56 @@ +package main + +import ( + "context" + "fmt" + "log" + "net/http" + "net/url" + "os" + + "github.com/AnthonyHewins/gotfy" +) + +func PostData(channel string, content NoticeElement) { + ctx, cancel := context.WithCancel(context.Background()) + + addr := os.Getenv("ntfyAddr") + server, _ := url.Parse(addr) + + client := http.DefaultClient + + tp, err := gotfy.NewPublisher(server, client) + + if err != nil { + log.Fatal(err.Error()) + } + + attachURL, _ := url.Parse(content.AttachmentURL) + + if err == nil { + _, err := tp.SendMessage(ctx, &gotfy.Message{ + Topic: "test", + Title: fmt.Sprintf("#%d | %s | %s | %s", content.MessageId, channel, content.MessageSubject, content.ApprovedOn), + Message: content.MessageBody, + AttachURL: attachURL, + AttachURLFilename: "Link 1", + }) + + if err != nil { + log.Fatal(err.Error()) + } + + } else { + _, err := tp.SendMessage(ctx, &gotfy.Message{ + Topic: "test", + Title: fmt.Sprintf("#%d | %s | %s", content.MessageId, content.MessageSubject, content.ApprovedOn), + Message: content.MessageBody, + }) + + if err != nil { + log.Fatal(err.Error()) + } + } + + cancel() +} From 6737d8790785a4e17bf74bbf622150bbd6c609a4 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Sun, 6 Oct 2024 11:24:00 +0530 Subject: [PATCH 53/72] docs(README): update run instruction --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ff6b8c0..435594c 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,7 @@ _Now that the environment has been set up and configured to properly compile and 8. Execute the script ```sh - go run main.go + go run . ```

(back to top)

From 53e19ec05fdb6e1b6795a980427fc98abcbeb690 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Sun, 6 Oct 2024 12:03:44 +0530 Subject: [PATCH 54/72] feat: add ntfy post --- go.mod | 2 -- go.sum | 4 --- ntfy.go | 75 ++++++++++++++++++++++++--------------------------------- 3 files changed, 32 insertions(+), 49 deletions(-) diff --git a/go.mod b/go.mod index 1dc4ebe..c454b9e 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,6 @@ module github.com/metakgp/mfins go 1.23.1 require ( - github.com/AnthonyHewins/gotfy v0.0.10 github.com/joho/godotenv v1.5.1 github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c golang.org/x/oauth2 v0.23.0 @@ -17,7 +16,6 @@ require ( github.com/felixge/httpsnoop v1.0.4 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect - github.com/goccy/go-json v0.10.2 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/google/s2a-go v0.1.8 // indirect github.com/google/uuid v1.6.0 // indirect diff --git a/go.sum b/go.sum index c73d4e6..7630e9b 100644 --- a/go.sum +++ b/go.sum @@ -5,8 +5,6 @@ cloud.google.com/go/auth/oauth2adapt v0.2.4 h1:0GWE/FUsXhf6C+jAkWgYm7X9tK8cuEIfy cloud.google.com/go/auth/oauth2adapt v0.2.4/go.mod h1:jC/jOpwFP6JBxhB3P5Rr0a9HLMC/Pe3eaL4NmdvqPtc= cloud.google.com/go/compute/metadata v0.5.2 h1:UxK4uu/Tn+I3p2dYWTfiX4wva7aYlKixAHn3fyqngqo= cloud.google.com/go/compute/metadata v0.5.2/go.mod h1:C66sj2AluDcIqakBq/M8lw8/ybHgOZqin2obFxa/E5k= -github.com/AnthonyHewins/gotfy v0.0.10 h1:23ZjRVG7wuGuqn7CQq/bOrkXa3gg2XyYrrD3RYEmvE8= -github.com/AnthonyHewins/gotfy v0.0.10/go.mod h1:q2orErDDpl9/gZ5L4oJhejb7TaP/eBdtkzjWDruNRlg= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= @@ -25,8 +23,6 @@ github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= -github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= -github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= diff --git a/ntfy.go b/ntfy.go index c80f8f9..d036fe8 100644 --- a/ntfy.go +++ b/ntfy.go @@ -1,56 +1,45 @@ package main import ( - "context" "fmt" - "log" "net/http" - "net/url" "os" - - "github.com/AnthonyHewins/gotfy" + "strings" ) -func PostData(channel string, content NoticeElement) { - ctx, cancel := context.WithCancel(context.Background()) +type ntfyMsg struct { + Title string + Body string + Tags []string + Priority int + Link string + Filename string +} +func PostData(channel string, content NoticeElement) { addr := os.Getenv("ntfyAddr") - server, _ := url.Parse(addr) - - client := http.DefaultClient - - tp, err := gotfy.NewPublisher(server, client) - if err != nil { - log.Fatal(err.Error()) - } - - attachURL, _ := url.Parse(content.AttachmentURL) - - if err == nil { - _, err := tp.SendMessage(ctx, &gotfy.Message{ - Topic: "test", - Title: fmt.Sprintf("#%d | %s | %s | %s", content.MessageId, channel, content.MessageSubject, content.ApprovedOn), - Message: content.MessageBody, - AttachURL: attachURL, - AttachURLFilename: "Link 1", - }) - - if err != nil { - log.Fatal(err.Error()) - } - - } else { - _, err := tp.SendMessage(ctx, &gotfy.Message{ - Topic: "test", - Title: fmt.Sprintf("#%d | %s | %s", content.MessageId, content.MessageSubject, content.ApprovedOn), - Message: content.MessageBody, - }) - - if err != nil { - log.Fatal(err.Error()) - } - } + postNtfy(addr, "test", ntfyMsg{ + Title: fmt.Sprintf("#%d | %s | %s | %s", content.MessageId, content.MessageSubject, channel, content.ApprovedOn), + Body: content.MessageBody, + Priority: 5, + Link: content.AttachmentURL, + Filename: "Link 1", + Tags: []string{"Warning", "cd"}, + }) +} - cancel() +func postNtfy(addr string, channel string, msg ntfyMsg) { + + body := fmt.Sprintf(`{ + "topic": "%s", + "message": "%s", + "title": "%s", + "priority": %d, + "attach": "%s", + "filename": "%s" + }`, channel, msg.Body, msg.Title, msg.Priority, msg.Link, msg.Filename) + req, _ := http.NewRequest("POST", addr, strings.NewReader(body)) + req.Header.Set("Markdown", "yes") + http.DefaultClient.Do(req) } From 561a385ad5ef2cf074b21f6fa157c648d1080e0d Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Sun, 6 Oct 2024 17:53:45 +0530 Subject: [PATCH 55/72] feat: restructure files --- docker-compose.yaml | 0 mfins-doctor/Dockerfile | 0 mfins-doctor/go.mod | 3 +++ mfins/.dockerignore | 0 mfins/Dockerfile | 27 +++++++++++++++++++ {erplogin => mfins/erplogin}/endpoints.go | 0 {erplogin => mfins/erplogin}/login.go | 0 {erplogin => mfins/erplogin}/optHandler.go | 0 .../erplogin}/securityQuestion.go | 0 go.mod => mfins/go.mod | 2 +- go.sum => mfins/go.sum | 0 main.go => mfins/main.go | 2 +- .../metaploy}/PROJECT_NAME.metaploy.conf | 0 {metaploy => mfins/metaploy}/postinstall.sh | 0 ntfy.go => mfins/ntfy.go | 0 15 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 docker-compose.yaml create mode 100644 mfins-doctor/Dockerfile create mode 100644 mfins-doctor/go.mod create mode 100644 mfins/.dockerignore create mode 100644 mfins/Dockerfile rename {erplogin => mfins/erplogin}/endpoints.go (100%) rename {erplogin => mfins/erplogin}/login.go (100%) rename {erplogin => mfins/erplogin}/optHandler.go (100%) rename {erplogin => mfins/erplogin}/securityQuestion.go (100%) rename go.mod => mfins/go.mod (97%) rename go.sum => mfins/go.sum (100%) rename main.go => mfins/main.go (98%) rename {metaploy => mfins/metaploy}/PROJECT_NAME.metaploy.conf (100%) rename {metaploy => mfins/metaploy}/postinstall.sh (100%) rename ntfy.go => mfins/ntfy.go (100%) diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..e69de29 diff --git a/mfins-doctor/Dockerfile b/mfins-doctor/Dockerfile new file mode 100644 index 0000000..e69de29 diff --git a/mfins-doctor/go.mod b/mfins-doctor/go.mod new file mode 100644 index 0000000..032c8de --- /dev/null +++ b/mfins-doctor/go.mod @@ -0,0 +1,3 @@ +module github.com/metakgp/mfins/mfins-doctor + +go 1.23.1 diff --git a/mfins/.dockerignore b/mfins/.dockerignore new file mode 100644 index 0000000..e69de29 diff --git a/mfins/Dockerfile b/mfins/Dockerfile new file mode 100644 index 0000000..cff6d4b --- /dev/null +++ b/mfins/Dockerfile @@ -0,0 +1,27 @@ +FROM golang:1.23.1 AS builder + +WORKDIR /src + +COPY go.mod go.sum ./ + +RUN go mod download + +COPY . . + +RUN CGO_ENABLED=1 GOOS=linux go build -o ./build --tags "fts5" -a -ldflags '-linkmode external -extldflags "-static"' . + +FROM alpine:latest AS app + +RUN apk --no-cache add tzdata ca-certificates bash + +ENV TZ="Asia/Kolkata" + +WORKDIR /app + +COPY metaploy/ ./ + +RUN chmod +x ./postinstall.sh + +COPY --from=builder /src/build . + +CMD ["./postinstall.sh", "./build"] \ No newline at end of file diff --git a/erplogin/endpoints.go b/mfins/erplogin/endpoints.go similarity index 100% rename from erplogin/endpoints.go rename to mfins/erplogin/endpoints.go diff --git a/erplogin/login.go b/mfins/erplogin/login.go similarity index 100% rename from erplogin/login.go rename to mfins/erplogin/login.go diff --git a/erplogin/optHandler.go b/mfins/erplogin/optHandler.go similarity index 100% rename from erplogin/optHandler.go rename to mfins/erplogin/optHandler.go diff --git a/erplogin/securityQuestion.go b/mfins/erplogin/securityQuestion.go similarity index 100% rename from erplogin/securityQuestion.go rename to mfins/erplogin/securityQuestion.go diff --git a/go.mod b/mfins/go.mod similarity index 97% rename from go.mod rename to mfins/go.mod index c454b9e..1803909 100644 --- a/go.mod +++ b/mfins/go.mod @@ -1,4 +1,4 @@ -module github.com/metakgp/mfins +module github.com/metakgp/mfins/mfins go 1.23.1 diff --git a/go.sum b/mfins/go.sum similarity index 100% rename from go.sum rename to mfins/go.sum diff --git a/main.go b/mfins/main.go similarity index 98% rename from main.go rename to mfins/main.go index 73644ab..a8a40fa 100644 --- a/main.go +++ b/mfins/main.go @@ -11,7 +11,7 @@ import ( "time" "github.com/joho/godotenv" - "github.com/metakgp/mfins/erplogin" + "github.com/metakgp/mfins/mfins/erplogin" ) type NoticeElement struct { diff --git a/metaploy/PROJECT_NAME.metaploy.conf b/mfins/metaploy/PROJECT_NAME.metaploy.conf similarity index 100% rename from metaploy/PROJECT_NAME.metaploy.conf rename to mfins/metaploy/PROJECT_NAME.metaploy.conf diff --git a/metaploy/postinstall.sh b/mfins/metaploy/postinstall.sh similarity index 100% rename from metaploy/postinstall.sh rename to mfins/metaploy/postinstall.sh diff --git a/ntfy.go b/mfins/ntfy.go similarity index 100% rename from ntfy.go rename to mfins/ntfy.go From 9746d9cbc3090868c1086e6974c1b9bca2236ec2 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Wed, 9 Oct 2024 10:09:54 +0530 Subject: [PATCH 56/72] feat: add docker compose --- .env.example | 3 ++- docker-compose.yaml | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 7fb762d..3ae78de 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,5 @@ rollno= password= ntfyAddr= -REPEAT=120 \ No newline at end of file +REPEAT=120 +MFINS_CONFIG= \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index e69de29..e087490 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -0,0 +1,20 @@ +services: + mfins: + build: + context: ./mfins + dockerfile: Dockerfile + image: metakgp/mfins + container_name: mfins + volumes: + - $MFINS_CONFIG/.env:/app/.env + - $MFINS_CONFIG/client_secret.json:/app/client_secret.json + - $MFINS_CONFIG/security_question.json:/app/security_question.json + - $MFINS_CONFIG/lastmsg.json:/app/lastmsg.json + - $MFINS_CONFIG/.token:/app/.token + + mfins_doctor: + build: + context: ./mfins-doctor + dockerfile: Dockerfile + image: metakgp/mfins-doctor + container_name: mfins-doctor \ No newline at end of file From 9cf4ded0d0b8684f7b428aa4d2eba54e817d1cdb Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Wed, 9 Oct 2024 10:24:00 +0530 Subject: [PATCH 57/72] feat: capitalise env vars --- .env.example | 6 +++--- mfins/erplogin/login.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.env.example b/.env.example index 3ae78de..c284421 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,5 @@ -rollno= -password= -ntfyAddr= +ROLL_NO= +PASSWORD= +NTFY_ADDR= REPEAT=120 MFINS_CONFIG= \ No newline at end of file diff --git a/mfins/erplogin/login.go b/mfins/erplogin/login.go index eb9ba7d..efd7851 100644 --- a/mfins/erplogin/login.go +++ b/mfins/erplogin/login.go @@ -22,8 +22,8 @@ func Login(client http.Client) { return } - rollNo = os.Getenv("rollno") - password = os.Getenv("password") + rollNo = os.Getenv("ROLL_NO") + password = os.Getenv("PASSWORD") question := getSecurityQues(&client, rollNo) securityAnswer = GetSecurityAnswer(question) From fd106ae58df57344b9931255015132ba97590f76 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Wed, 9 Oct 2024 10:24:26 +0530 Subject: [PATCH 58/72] feat: multimodule go --- go.work | 3 +++ go.work.sum | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 go.work create mode 100644 go.work.sum diff --git a/go.work b/go.work new file mode 100644 index 0000000..af59537 --- /dev/null +++ b/go.work @@ -0,0 +1,3 @@ +go 1.23.1 + +use ./mfins diff --git a/go.work.sum b/go.work.sum new file mode 100644 index 0000000..e0d2feb --- /dev/null +++ b/go.work.sum @@ -0,0 +1,22 @@ +cel.dev/expr v0.16.0/go.mod h1:TRSuuV7DlVCE/uwv5QbAiW/v8l5O8C4eEPHeu7gf7Sg= +cloud.google.com/go v0.115.1 h1:Jo0SM9cQnSkYfp44+v+NQXHpcHqlnRJk2qxh6yvxxxQ= +cloud.google.com/go v0.115.1/go.mod h1:DuujITeaufu3gL68/lOFIirVNJwQeyf5UXyi+Wbgknc= +cloud.google.com/go/longrunning v0.5.6/go.mod h1:vUaDrWYOMKRuhiv6JBnn49YxCPz2Ayn9GqyjaBT8/mA= +cloud.google.com/go/translate v1.10.3/go.mod h1:GW0vC1qvPtd3pgtypCv4k4U8B7EdgK9/QEF2aJEUovs= +github.com/census-instrumentation/opencensus-proto v0.4.1/go.mod h1:4T9NM4+4Vw91VeyqjLS6ao50K5bOcLKN6Q42XnYaRYw= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cncf/xds/go v0.0.0-20240723142845-024c85f92f20/go.mod h1:W+zGtBO5Y1IgJhy4+A9GOqVhqLpfZi+vwmdNXUehLA8= +github.com/envoyproxy/go-control-plane v0.13.0/go.mod h1:GRaKG3dwvFoTg4nj7aXdZnvMg4d7nvT/wl9WgVXn3Q8= +github.com/envoyproxy/protoc-gen-validate v1.1.0/go.mod h1:sXRDRVmzEbkM7CVcM06s9shE/m23dg3wzjl0UWqJ2q4= +github.com/golang/glog v1.2.2/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= +github.com/google/go-pkcs11 v0.3.0/go.mod h1:6eQoGcuNJpa7jnd5pMGdkSaQpNDYvPlXWMcjXXThLlY= +github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10/go.mod h1:t/avpk3KcrXxUnYOhZhMXJlSEyie6gQbtLq5NM3loB8= +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0/go.mod h1:B9yO6b04uB80CzjedvewuqDhxJxi11s7/GtiGa8bAjI= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/term v0.24.0/go.mod h1:lOBK/LVxemqiMij05LGJ0tzNr8xlmwBRJ81PX6wVLH8= +golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= +google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= +google.golang.org/genproto v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:hL97c3SYopEHblzpxRL4lSs523++l8DYxGM1FQiYmb4= +google.golang.org/genproto/googleapis/bytestream v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:q0eWNnCW04EJlyrmLT+ZHsjuoUiZ36/eAEdCCezZoco= From 5846d164363ce0e82425671c18932f5a87a0b32f Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Mon, 14 Oct 2024 18:03:53 +0530 Subject: [PATCH 59/72] feat: use erp login package go --- .gitignore | 3 +- go.work.sum | 3 +- mfins/erplogin/endpoints.go | 10 -- mfins/erplogin/login.go | 101 ---------------- mfins/erplogin/optHandler.go | 185 ----------------------------- mfins/erplogin/securityQuestion.go | 69 ----------- mfins/go.mod | 10 +- mfins/go.sum | 12 ++ mfins/main.go | 4 +- 9 files changed, 25 insertions(+), 372 deletions(-) delete mode 100644 mfins/erplogin/endpoints.go delete mode 100644 mfins/erplogin/login.go delete mode 100644 mfins/erplogin/optHandler.go delete mode 100644 mfins/erplogin/securityQuestion.go diff --git a/.gitignore b/.gitignore index 66f5b5f..ca4df95 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ node-modules/ lastmsg.json client_secret.json .token -security_question.json \ No newline at end of file +erpcreds.json +.session \ No newline at end of file diff --git a/go.work.sum b/go.work.sum index e0d2feb..1f1bd05 100644 --- a/go.work.sum +++ b/go.work.sum @@ -1,6 +1,8 @@ cel.dev/expr v0.16.0/go.mod h1:TRSuuV7DlVCE/uwv5QbAiW/v8l5O8C4eEPHeu7gf7Sg= cloud.google.com/go v0.115.1 h1:Jo0SM9cQnSkYfp44+v+NQXHpcHqlnRJk2qxh6yvxxxQ= cloud.google.com/go v0.115.1/go.mod h1:DuujITeaufu3gL68/lOFIirVNJwQeyf5UXyi+Wbgknc= +cloud.google.com/go/compute v1.23.3 h1:6sVlXXBmbd7jNX0Ipq0trII3e4n1/MsADLK6a+aiVlk= +cloud.google.com/go/compute v1.23.3/go.mod h1:VCgBUoMnIVIR0CscqQiPJLAG25E3ZRZMzcFZeQ+h8CI= cloud.google.com/go/longrunning v0.5.6/go.mod h1:vUaDrWYOMKRuhiv6JBnn49YxCPz2Ayn9GqyjaBT8/mA= cloud.google.com/go/translate v1.10.3/go.mod h1:GW0vC1qvPtd3pgtypCv4k4U8B7EdgK9/QEF2aJEUovs= github.com/census-instrumentation/opencensus-proto v0.4.1/go.mod h1:4T9NM4+4Vw91VeyqjLS6ao50K5bOcLKN6Q42XnYaRYw= @@ -14,7 +16,6 @@ github.com/google/go-pkcs11 v0.3.0/go.mod h1:6eQoGcuNJpa7jnd5pMGdkSaQpNDYvPlXWMc github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10/go.mod h1:t/avpk3KcrXxUnYOhZhMXJlSEyie6gQbtLq5NM3loB8= go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0/go.mod h1:B9yO6b04uB80CzjedvewuqDhxJxi11s7/GtiGa8bAjI= golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= -golang.org/x/term v0.24.0/go.mod h1:lOBK/LVxemqiMij05LGJ0tzNr8xlmwBRJ81PX6wVLH8= golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= diff --git a/mfins/erplogin/endpoints.go b/mfins/erplogin/endpoints.go deleted file mode 100644 index c759550..0000000 --- a/mfins/erplogin/endpoints.go +++ /dev/null @@ -1,10 +0,0 @@ -package erplogin - -const ( - PING_URL = "iitkgp.ac.in" - HOMEPAGE_URL = "https://erp.iitkgp.ac.in/IIT_ERP3/" - WELCOMEPAGE_URL = "https://erp.iitkgp.ac.in/IIT_ERP3/welcome.jsp" - LOGIN_URL = "https://erp.iitkgp.ac.in/SSOAdministration/auth.htm" - SECRET_QUESTION_URL = "https://erp.iitkgp.ac.in/SSOAdministration/getSecurityQues.htm" - OTP_URL = "https://erp.iitkgp.ac.in/SSOAdministration/getEmilOTP.htm" // blame ERP for the typo -) diff --git a/mfins/erplogin/login.go b/mfins/erplogin/login.go deleted file mode 100644 index efd7851..0000000 --- a/mfins/erplogin/login.go +++ /dev/null @@ -1,101 +0,0 @@ -package erplogin - -import ( - "io" - "log" - "net/http" - "net/url" - "os" -) - -var ( - rollNo string - password string - securityAnswer string - emailOTP string -) - -func Login(client http.Client) { - - if checkLogin(&client) { - log.Println("Already logged in, continuing without login") - return - } - - rollNo = os.Getenv("ROLL_NO") - password = os.Getenv("PASSWORD") - - question := getSecurityQues(&client, rollNo) - securityAnswer = GetSecurityAnswer(question) - - emailOTP = GetOtp(&client) - - loginBody(&client) -} - -func getSecurityQues(client *http.Client, rollNo string) string { - data := url.Values{} - - data.Set("user_id", rollNo) - - res, err := client.PostForm(SECRET_QUESTION_URL, data) - - if err != nil { - log.Panic(err.Error()) - } - - byteResp, err := io.ReadAll(res.Body) - - defer res.Body.Close() - - return string(byteResp) -} - -func SendOTP(client *http.Client) { - log.Println("Requesting OTP....") - data := url.Values{} - data.Set("user_id", rollNo) - data.Set("password", password) - data.Set("answer", securityAnswer) - data.Set("requestedUrl", HOMEPAGE_URL) - data.Set("typeee", "SI") - - res, err := client.PostForm(OTP_URL, data) - - if err != nil { - log.Panic(err.Error()) - } - - log.Println("OTP requested successfully!") - - defer res.Body.Close() -} - -func loginBody(client *http.Client) { - data := url.Values{} - - data.Set("user_id", rollNo) - data.Set("password", password) - data.Set("answer", securityAnswer) - data.Set("email_otp", emailOTP) - data.Set("requestedUrl", HOMEPAGE_URL) - - resp, err := client.PostForm(LOGIN_URL, data) - - if err != nil { - log.Panic(err.Error()) - } - - defer resp.Body.Close() -} - -func checkLogin(client *http.Client) bool { - - res, err := client.Get(WELCOMEPAGE_URL) - - if err != nil { - log.Panic(err.Error()) - } - - return res.ContentLength == 1034 -} diff --git a/mfins/erplogin/optHandler.go b/mfins/erplogin/optHandler.go deleted file mode 100644 index 3b94be6..0000000 --- a/mfins/erplogin/optHandler.go +++ /dev/null @@ -1,185 +0,0 @@ -package erplogin - -import ( - "context" - "encoding/base64" - "encoding/json" - "errors" - "fmt" - "log" - "net/http" - "os" - "regexp" - "time" - - "github.com/pkg/browser" - "golang.org/x/oauth2" - "golang.org/x/oauth2/google" - "google.golang.org/api/gmail/v1" - "google.golang.org/api/option" -) - -const ( - query = "from:erpkgp@adm.iitkgp.ac.in is:unread subject: otp" - RedirectURL = "http://localhost:7007" -) - -func GetOtp(client *http.Client) string { - if is_file("client_secret.json") || is_file(".token") { - - log.Println("Found google OAuth credentials, Automatically reading OTP") - - return GetOtpEmail(client) - } else { - - return GetOtpInput(client) - } -} - -func getMsgId(service *gmail.Service) string { - results, err := service.Users.Messages.List("me").Q(query).MaxResults(1).Do() - - if err != nil { - log.Fatal(err.Error()) - } - - if len(results.Messages) != 0 { - return results.Messages[0].Id - } - - return "" - -} - -func GetOtpEmail(client *http.Client) string { - ctx, cancel := context.WithCancel(context.Background()) - - conf := oauth2.Config{ - Scopes: []string{gmail.GmailReadonlyScope}, - Endpoint: google.Endpoint, - RedirectURL: RedirectURL, - } - - secretByte, err := os.ReadFile("client_secret.json") - - if err != nil { - log.Fatal(err.Error()) - } - - var secret map[string]map[string]json.RawMessage - err = json.Unmarshal(secretByte, &secret) - - _ = json.Unmarshal(secret["installed"]["client_id"], &conf.ClientID) - _ = json.Unmarshal(secret["installed"]["client_secret"], &conf.ClientSecret) - - var token *oauth2.Token - - if is_file(".token") { - - token_byte, err := os.ReadFile(".token") - if err != nil { - log.Fatal(err.Error()) - } - - err = json.Unmarshal(token_byte, &token) - if err != nil { - log.Fatal(err.Error()) - } - - } else { - token, err = generateToken(&ctx, cancel, &conf) - if err != nil { - log.Fatal(err.Error()) - } - - token_json, err := json.Marshal(*token) - if err != nil { - log.Fatal(err.Error()) - } - - err = os.WriteFile(".token", token_json, 0666) - if err != nil { - log.Fatal(err.Error()) - } - } - - if err != nil { - log.Fatal(err.Error()) - } - - service, err := gmail.NewService(ctx, option.WithTokenSource(conf.TokenSource(ctx, token))) - if err != nil { - log.Fatal(err.Error()) - } - - latestId := getMsgId(service) - SendOTP(client) - var mailId string - - for { - log.Println("Waiting for OTP...") - if mailId = getMsgId(service); mailId != latestId { - log.Println("OTP fetched") - break - } - time.Sleep(1 * time.Second) - } - - message, err := service.Users.Messages.Get("me", mailId).Do() - if err != nil { - log.Fatal(err.Error()) - } - - body, err := base64.URLEncoding.DecodeString(message.Payload.Body.Data) - if err != nil { - log.Fatal(err.Error()) - } - - reg := regexp.MustCompile("[0-9]+") - otp := reg.FindAllString(string(body), -1)[0] - - cancel() - return otp - -} - -func is_file(filename string) bool { - file, err := os.Open(filename) - defer file.Close() - return !errors.Is(err, os.ErrNotExist) -} - -func generateToken(ctx *context.Context, cancel context.CancelFunc, conf *oauth2.Config) (*oauth2.Token, error) { - authURL := conf.AuthCodeURL("666573902ekwjfn") - fmt.Println("Visit this URL for authentication: ", authURL) - browser.OpenURL(authURL) - - var token *oauth2.Token - var err error - - http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - if r.URL.Query().Get("state") == "666573902ekwjfn" { - token, err = conf.Exchange(*ctx, r.URL.Query().Get("code")) - } - fmt.Fprintf(w, "Authentication complete. Check your terminal.") - cancel() - }) - - server := &http.Server{Addr: ":7007"} - go func() { - if err := server.ListenAndServe(); err != nil { - log.Fatal(err.Error()) - } - }() - <-(*ctx).Done() - return token, err -} - -func GetOtpInput(client *http.Client) string { - SendOTP(client) - var emailOTP string - fmt.Printf("Enter OTP Sent to your email: ") - fmt.Scan(&emailOTP) - - return emailOTP -} diff --git a/mfins/erplogin/securityQuestion.go b/mfins/erplogin/securityQuestion.go deleted file mode 100644 index cd390d7..0000000 --- a/mfins/erplogin/securityQuestion.go +++ /dev/null @@ -1,69 +0,0 @@ -package erplogin - -import ( - "encoding/json" - "fmt" - "log" - "os" -) - -var questionAnswer map[string]string - -const FILENAME = "security_question.json" - -func GetSecurityAnswer(question string) string { - - if is_file(FILENAME) { - - log.Printf("Found %s, checking if question is present....", FILENAME) - - quesByte, err := os.ReadFile(FILENAME) - if err != nil { - log.Fatal(err.Error()) - } - - err = json.Unmarshal(quesByte, &questionAnswer) - if err != nil { - log.Fatal(err.Error()) - } - - if val, ok := questionAnswer[question]; ok { - log.Println("Found answer to security question!") - return val - } else { - inputAnswer(question) - } - - questionAnswerJson, err := json.Marshal(questionAnswer) - if err != nil { - log.Fatalf(err.Error()) - } - - os.WriteFile(FILENAME, questionAnswerJson, 0666) - - return questionAnswer[question] - - } else { - log.Printf("%s not found, creating.....", FILENAME) - inputAnswer(question) - - questionAnswerJson, err := json.Marshal(questionAnswer) - if err != nil { - log.Fatalf(err.Error()) - } - - os.WriteFile(FILENAME, questionAnswerJson, 0666) - - return questionAnswer[question] - } -} - -func inputAnswer(question string) { - var answer string - fmt.Printf("Security question: %s", question) - fmt.Println() - fmt.Print("Enter answer to security question: ") - fmt.Scan(&answer) - - questionAnswer[question] = answer -} diff --git a/mfins/go.mod b/mfins/go.mod index 1803909..2071780 100644 --- a/mfins/go.mod +++ b/mfins/go.mod @@ -4,9 +4,7 @@ go 1.23.1 require ( github.com/joho/godotenv v1.5.1 - github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c - golang.org/x/oauth2 v0.23.0 - google.golang.org/api v0.199.0 + github.com/metakgp/iitkgp-erp-login-go v1.0.2 ) require ( @@ -16,11 +14,13 @@ require ( github.com/felixge/httpsnoop v1.0.4 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect + github.com/go-ping/ping v1.1.0 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/google/s2a-go v0.1.8 // indirect github.com/google/uuid v1.6.0 // indirect github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect github.com/googleapis/gax-go/v2 v2.13.0 // indirect + github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect go.opencensus.io v0.24.0 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect go.opentelemetry.io/otel v1.29.0 // indirect @@ -28,8 +28,12 @@ require ( go.opentelemetry.io/otel/trace v1.29.0 // indirect golang.org/x/crypto v0.27.0 // indirect golang.org/x/net v0.29.0 // indirect + golang.org/x/oauth2 v0.23.0 // indirect + golang.org/x/sync v0.8.0 // indirect golang.org/x/sys v0.25.0 // indirect + golang.org/x/term v0.24.0 // indirect golang.org/x/text v0.18.0 // indirect + google.golang.org/api v0.199.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect google.golang.org/grpc v1.67.0 // indirect google.golang.org/protobuf v1.34.2 // indirect diff --git a/mfins/go.sum b/mfins/go.sum index 7630e9b..f1cea09 100644 --- a/mfins/go.sum +++ b/mfins/go.sum @@ -23,6 +23,8 @@ github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/go-ping/ping v1.1.0 h1:3MCGhVX4fyEUuhsfwPrsEdQw6xspHkv5zHsiSoDFZYw= +github.com/go-ping/ping v1.1.0/go.mod h1:xIFjORFzTxqIV/tDVGO4eDy/bLuSyawEeojSm3GfRGk= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= @@ -48,6 +50,7 @@ github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN github.com/google/s2a-go v0.1.8 h1:zZDs9gcbt9ZPLV0ndSyQk6Kacx2g/X+SKYovpnz3SMM= github.com/google/s2a-go v0.1.8/go.mod h1:6iNWHTpQ+nfNRN5E00MSdfDwVesa8hhS32PhPO8deJA= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/enterprise-certificate-proxy v0.3.4 h1:XYIDZApgAnrN1c855gTgghdIA6Stxb52D5RnLI1SLyw= @@ -56,6 +59,8 @@ github.com/googleapis/gax-go/v2 v2.13.0 h1:yitjD5f7jQHhyDsnhKEBU52NdvvdSeGzlAnDP github.com/googleapis/gax-go/v2 v2.13.0/go.mod h1:Z/fvTZXF8/uw7Xu5GuslPw+bplx6SS338j1Is2S+B7A= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= +github.com/metakgp/iitkgp-erp-login-go v1.0.2 h1:oTSmIH8p2wNEXJCF2+aMS5aJBmDt6HpHV31ppT25eN8= +github.com/metakgp/iitkgp-erp-login-go v1.0.2/go.mod h1:Hv6VaTwC866ZeQeh69MXV2kbx+mjlT+YbfkPUnqSacM= github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ= github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -93,6 +98,7 @@ golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc= golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo= golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -101,15 +107,21 @@ golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbht golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.24.0 h1:Mh5cbb+Zk2hqqXNO7S1iTjEphVL+jb8ZWaqh/g+JWkM= +golang.org/x/term v0.24.0/go.mod h1:lOBK/LVxemqiMij05LGJ0tzNr8xlmwBRJ81PX6wVLH8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= diff --git a/mfins/main.go b/mfins/main.go index a8a40fa..ba4ac34 100644 --- a/mfins/main.go +++ b/mfins/main.go @@ -11,7 +11,7 @@ import ( "time" "github.com/joho/godotenv" - "github.com/metakgp/mfins/mfins/erplogin" + erp "github.com/metakgp/iitkgp-erp-login-go" ) type NoticeElement struct { @@ -42,7 +42,7 @@ func RunCron() { for true { log.Println("Logining Into ERP....") - erplogin.Login(Client) + _, ERPSSOToken = erp.ERPSession() log.Println("Getting messages....") From 68711b5f94d41d04eeb90e495cff1efdad4b2ae3 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Mon, 14 Oct 2024 18:52:34 +0530 Subject: [PATCH 60/72] feat: add new login script --- mfins/main.go | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/mfins/main.go b/mfins/main.go index ba4ac34..17028b9 100644 --- a/mfins/main.go +++ b/mfins/main.go @@ -6,8 +6,10 @@ import ( "log" "net/http" "net/http/cookiejar" + "net/url" "os" "strconv" + "strings" "time" "github.com/joho/godotenv" @@ -29,7 +31,7 @@ type NoticeElement struct { var ( ERPJSession string - ERPSSOToken string + ERPSSOToken []string NoticeEndpoint string FileEndpoint string ERPCatCodeTopicMap map[int]string @@ -42,7 +44,7 @@ func RunCron() { for true { log.Println("Logining Into ERP....") - _, ERPSSOToken = erp.ERPSession() + ERPLogin() log.Println("Getting messages....") @@ -141,6 +143,29 @@ func PrintNewMsg(channel string, content NoticeElement) { PostData(channel, content) } +func ERPLogin() { + + _, ERPSSOTokenString := erp.ERPSession() + + ERPSSOToken = strings.Split(ERPSSOTokenString, "=") + + cookies := []*http.Cookie{ + { + Name: ERPSSOToken[0], + Value: ERPSSOToken[1], + }, + } + + urlParse, err := url.Parse(NoticeEndpoint) + + if err != nil { + log.Fatalf("Error parsing endpoint url") + } + + Client.Jar.SetCookies(urlParse, cookies) + +} + func initClient() { jar, err := cookiejar.New(nil) if err != nil { From 7a495ee64a9840189f7435439b71a0a2c6ac0e60 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Mon, 14 Oct 2024 18:53:10 +0530 Subject: [PATCH 61/72] feat: update .env.example --- .env.example | 2 -- 1 file changed, 2 deletions(-) diff --git a/.env.example b/.env.example index c284421..5e19d74 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,3 @@ -ROLL_NO= -PASSWORD= NTFY_ADDR= REPEAT=120 MFINS_CONFIG= \ No newline at end of file From cf165cd96f40664e037cff8a8f4b53cd180ac09d Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Mon, 14 Oct 2024 18:54:15 +0530 Subject: [PATCH 62/72] feat: update docker compose --- docker-compose.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index e087490..bdda965 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -8,9 +8,10 @@ services: volumes: - $MFINS_CONFIG/.env:/app/.env - $MFINS_CONFIG/client_secret.json:/app/client_secret.json - - $MFINS_CONFIG/security_question.json:/app/security_question.json + - $MFINS_CONFIG/erpcreds.json:/app/erpcreds.json - $MFINS_CONFIG/lastmsg.json:/app/lastmsg.json - $MFINS_CONFIG/.token:/app/.token + - $MFINS_CONFIG/.session:/app/.session mfins_doctor: build: From 751a3b7dab57d9b53e744e5ab713f0bfef79f738 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Mon, 14 Oct 2024 18:55:50 +0530 Subject: [PATCH 63/72] docs(README): update instructions --- README.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 435594c..af48175 100644 --- a/README.md +++ b/README.md @@ -103,16 +103,13 @@ _Now that the environment has been set up and configured to properly compile and ```sh touch lastmsg.json && echo {} > lastmsg.json ``` -6. Create `security_question.json` and add `{}` to it - ```sh - touch security_question.json && echo {} > security_question.json - ``` +6. Create `erpcreds.json` and add roll_no, password, answers 7. Create a google OAuth client secret and client id and add it to `client_secret.json` 8. Execute the script ```sh - go run . + go run ./mfins ```

(back to top)

From 626b101131100f4ee04716b6101c1dbedc254f7c Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Tue, 15 Oct 2024 18:00:46 +0530 Subject: [PATCH 64/72] feat: update workflow --- .github/workflows/deploy.yaml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 97cbca0..0819c44 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -31,27 +31,27 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_PASSWORD }} - - name: Cache Docker layers SERVICE_NAME + - name: Cache Docker layers mfins uses: actions/cache@v3 with: - path: /tmp/.buildx-cache-SERVICE_NAME - key: ${{ runner.os }}-buildx-SERVICE_NAME-${{ github.sha }} + path: /tmp/.buildx-cache-mfins + key: ${{ runner.os }}-buildx-mfins-${{ github.sha }} restore-keys: | - ${{ runner.os }}-buildx-SERVICE_NAME- + ${{ runner.os }}-buildx-mfins- - - name: Build & Push SERVICE_NAME + - name: Build & Push mfins uses: docker/build-push-action@v5 with: - context: . + context: ./mfins/ push: true - tags: ${{ secrets.DOCKERHUB_USERNAME }}/SERVICE_NAME:latest - cache-from: type=local,src=/tmp/.buildx-cache-SERVICE_NAME - cache-to: type=local,dest=/tmp/.buildx-cache-SERVICE_NAME-new,mode=max + tags: ${{ secrets.DOCKERHUB_USERNAME }}/mfins:latest + cache-from: type=local,src=/tmp/.buildx-cache-mfins + cache-to: type=local,dest=/tmp/.buildx-cache-mfins-new,mode=max - - name: Move SERVICE_NAME cache + - name: Move mfins cache run: | - rm -rf /tmp/.buildx-cache-SERVICE_NAME - mv /tmp/.buildx-cache-SERVICE_NAME-new /tmp/.buildx-cache-SERVICE_NAME + rm -rf /tmp/.buildx-cache-mfins + mv /tmp/.buildx-cache-mfins-new /tmp/.buildx-cache-mfins push: name: Push Code Stage From 31bcf2afba501626f2f39456c4d941b2343ede4c Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Tue, 15 Oct 2024 18:01:01 +0530 Subject: [PATCH 65/72] fix: remove dockerignore --- mfins/.dockerignore | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 mfins/.dockerignore diff --git a/mfins/.dockerignore b/mfins/.dockerignore deleted file mode 100644 index e69de29..0000000 From 9c245c4a5526345397a0b3cf1b6e6a330bdc135c Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Sat, 19 Oct 2024 23:16:21 +0530 Subject: [PATCH 66/72] fix: remove metaploy, update dockerfile --- mfins/Dockerfile | 16 +--------------- mfins/metaploy/PROJECT_NAME.metaploy.conf | 16 ---------------- mfins/metaploy/postinstall.sh | 14 -------------- 3 files changed, 1 insertion(+), 45 deletions(-) delete mode 100644 mfins/metaploy/PROJECT_NAME.metaploy.conf delete mode 100755 mfins/metaploy/postinstall.sh diff --git a/mfins/Dockerfile b/mfins/Dockerfile index cff6d4b..aca6d67 100644 --- a/mfins/Dockerfile +++ b/mfins/Dockerfile @@ -1,27 +1,13 @@ FROM golang:1.23.1 AS builder - WORKDIR /src - COPY go.mod go.sum ./ - RUN go mod download - COPY . . - RUN CGO_ENABLED=1 GOOS=linux go build -o ./build --tags "fts5" -a -ldflags '-linkmode external -extldflags "-static"' . FROM alpine:latest AS app - RUN apk --no-cache add tzdata ca-certificates bash - ENV TZ="Asia/Kolkata" - WORKDIR /app - -COPY metaploy/ ./ - -RUN chmod +x ./postinstall.sh - COPY --from=builder /src/build . - -CMD ["./postinstall.sh", "./build"] \ No newline at end of file +CMD ["./build"] \ No newline at end of file diff --git a/mfins/metaploy/PROJECT_NAME.metaploy.conf b/mfins/metaploy/PROJECT_NAME.metaploy.conf deleted file mode 100644 index 3f25c81..0000000 --- a/mfins/metaploy/PROJECT_NAME.metaploy.conf +++ /dev/null @@ -1,16 +0,0 @@ -upstream PROJECT_NAME { - server PROJECT-NAME:5173; -} - -server { - server_name PROJECT-NAME.metakgp.org; - - location / { - proxy_pass http://PROJECT_NAME; - - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Original-URI $request_uri; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - } -} \ No newline at end of file diff --git a/mfins/metaploy/postinstall.sh b/mfins/metaploy/postinstall.sh deleted file mode 100755 index a5468f0..0000000 --- a/mfins/metaploy/postinstall.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -cleanup() { - echo "Container stopped. Removing nginx configuration." - rm /etc/nginx/sites-enabled/PROJECT_NAME.metaploy.conf -} - -trap 'cleanup' SIGQUIT SIGTERM SIGHUP - -"${@}" & - -cp ./PROJECT_NAME.metaploy.conf /etc/nginx/sites-enabled - -wait $! From 486207e2ad583f8e328d3d2cd90156658257c1ef Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Sat, 19 Oct 2024 23:37:04 +0530 Subject: [PATCH 67/72] refactor: error messages --- mfins/main.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/mfins/main.go b/mfins/main.go index 17028b9..6c9ea59 100644 --- a/mfins/main.go +++ b/mfins/main.go @@ -60,18 +60,18 @@ func RunCron() { func getNewNotices(channel int) { req, err := http.NewRequest("GET", fmt.Sprintf(NoticeEndpoint, channel), nil) if err != nil { - log.Fatalf("Error %s", err.Error()) + log.Fatalf("Failed to generate request ~ %s", err.Error()) } resp, err := Client.Do(req) if err != nil { - log.Fatalf("Error %s", err.Error()) + log.Fatalf("Failed to access noticeboard ~ %s", err.Error()) } var resBody []NoticeElement if err := json.NewDecoder(resp.Body).Decode(&resBody); err != nil { - log.Fatalf("Error %s", err.Error()) + log.Fatalf("Failed to decode notices ~ %s", err.Error()) } lastNoticeId := getLastNotice(channel) @@ -100,12 +100,12 @@ func getLastNotice(channel int) int { file, err := os.OpenFile("lastmsg.json", os.O_RDWR|os.O_CREATE, os.ModePerm) defer file.Close() if err != nil { - log.Panicf("Error opening file: %s", err.Error()) + log.Panicf("Failed to open last msg file ~ %s", err.Error()) } var fileContent map[int]int if err = json.NewDecoder(file).Decode(&fileContent); err != nil { - log.Panicf("Error decoding file: %s", err.Error()) + log.Panicf("Failed to decode last msg file ~ %s", err.Error()) } return fileContent[channel] @@ -115,24 +115,24 @@ func setLastNotice(channel int, lastMsgId int) { file, err := os.OpenFile("lastmsg.json", os.O_RDWR|os.O_CREATE, os.ModePerm) defer file.Close() if err != nil { - log.Panicf("Error opening file: %s", err.Error()) + log.Panicf("Failed to open last msg file ~ %s", err.Error()) } var fileContent map[int]int if err = json.NewDecoder(file).Decode(&fileContent); err != nil { - log.Panicf("Error decoding file: %s", err.Error()) + log.Panicf("Failed to decode last msg file ~ %s", err.Error()) } fileContent[channel] = lastMsgId txt, err := json.Marshal(fileContent) if err != nil { - log.Panicf("Error writing file: %s", err.Error()) + log.Panicf("Error writing last msg file ~ %s", err.Error()) } file.Seek(0, 0) if _, err = file.Write(txt); err != nil { - log.Panicf("Error writing file: %s", err.Error()) + log.Panicf("Error writing last msg file ~ %s", err.Error()) } } @@ -169,7 +169,7 @@ func ERPLogin() { func initClient() { jar, err := cookiejar.New(nil) if err != nil { - log.Fatalf("Error %s", err.Error()) + log.Fatalf("Error Building cookie storage for request ~ %s", err.Error()) } Client = http.Client{ From 835e518748f691b8becc29fed7b9a71cfdacc1c5 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Fri, 6 Dec 2024 21:46:10 +0530 Subject: [PATCH 68/72] feat: add monitoring service --- mfins-doctor/Dockerfile | 13 +++++ mfins-doctor/go.mod | 29 ++++++++++ mfins-doctor/go.sum | 123 ++++++++++++++++++++++++++++++++++++++++ mfins-doctor/main.go | 85 +++++++++++++++++++++++++++ 4 files changed, 250 insertions(+) create mode 100644 mfins-doctor/go.sum create mode 100644 mfins-doctor/main.go diff --git a/mfins-doctor/Dockerfile b/mfins-doctor/Dockerfile index e69de29..aca6d67 100644 --- a/mfins-doctor/Dockerfile +++ b/mfins-doctor/Dockerfile @@ -0,0 +1,13 @@ +FROM golang:1.23.1 AS builder +WORKDIR /src +COPY go.mod go.sum ./ +RUN go mod download +COPY . . +RUN CGO_ENABLED=1 GOOS=linux go build -o ./build --tags "fts5" -a -ldflags '-linkmode external -extldflags "-static"' . + +FROM alpine:latest AS app +RUN apk --no-cache add tzdata ca-certificates bash +ENV TZ="Asia/Kolkata" +WORKDIR /app +COPY --from=builder /src/build . +CMD ["./build"] \ No newline at end of file diff --git a/mfins-doctor/go.mod b/mfins-doctor/go.mod index 032c8de..fc04701 100644 --- a/mfins-doctor/go.mod +++ b/mfins-doctor/go.mod @@ -1,3 +1,32 @@ module github.com/metakgp/mfins/mfins-doctor go 1.23.1 + +require github.com/docker/docker v27.3.1+incompatible + +require ( + github.com/Microsoft/go-winio v0.4.14 // indirect + github.com/containerd/log v0.1.0 // indirect + github.com/distribution/reference v0.6.0 // indirect + github.com/docker/go-connections v0.5.0 // indirect + github.com/docker/go-units v0.5.0 // indirect + github.com/felixge/httpsnoop v1.0.4 // indirect + github.com/go-logr/logr v1.4.2 // indirect + github.com/go-logr/stdr v1.2.2 // indirect + github.com/gogo/protobuf v1.3.2 // indirect + github.com/moby/docker-image-spec v1.3.1 // indirect + github.com/moby/term v0.5.0 // indirect + github.com/morikuni/aec v1.0.0 // indirect + github.com/opencontainers/go-digest v1.0.0 // indirect + github.com/opencontainers/image-spec v1.1.0 // indirect + github.com/pkg/errors v0.9.1 // indirect + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.57.0 // indirect + go.opentelemetry.io/otel v1.32.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.32.0 // indirect + go.opentelemetry.io/otel/metric v1.32.0 // indirect + go.opentelemetry.io/otel/sdk v1.32.0 // indirect + go.opentelemetry.io/otel/trace v1.32.0 // indirect + golang.org/x/sys v0.27.0 // indirect + golang.org/x/time v0.8.0 // indirect + gotest.tools/v3 v3.5.1 // indirect +) diff --git a/mfins-doctor/go.sum b/mfins-doctor/go.sum new file mode 100644 index 0000000..4acbdbf --- /dev/null +++ b/mfins-doctor/go.sum @@ -0,0 +1,123 @@ +github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= +github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= +github.com/Microsoft/go-winio v0.4.14 h1:+hMXMk01us9KgxGb7ftKQt2Xpf5hH/yky+TDA+qxleU= +github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= +github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= +github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= +github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I= +github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk= +github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E= +github.com/docker/docker v27.3.1+incompatible h1:KttF0XoteNTicmUtBO0L2tP+J7FGRFTjaEF4k6WdhfI= +github.com/docker/docker v27.3.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c= +github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc= +github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= +github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= +github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= +github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.23.0 h1:ad0vkEBuk23VJzZR9nkLVG0YAoN9coASF1GusYX6AlU= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.23.0/go.mod h1:igFoXX2ELCW06bol23DWPB5BEWfZISOzSP5K2sbLea0= +github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0= +github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo= +github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0= +github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y= +github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= +github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= +github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= +github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= +github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug= +github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= +github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= +github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.57.0 h1:DheMAlT6POBP+gh8RUH19EOTnQIor5QE0uSRPtzCpSw= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.57.0/go.mod h1:wZcGmeVO9nzP67aYSLDqXNWK87EZWhi7JWj1v7ZXf94= +go.opentelemetry.io/otel v1.32.0 h1:WnBN+Xjcteh0zdk01SVqV55d/m62NJLJdIyb4y/WO5U= +go.opentelemetry.io/otel v1.32.0/go.mod h1:00DCVSB0RQcnzlwyTfqtxSm+DRr9hpYrHjNGiBHVQIg= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.32.0 h1:IJFEoHiytixx8cMiVAO+GmHR6Frwu+u5Ur8njpFO6Ac= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.32.0/go.mod h1:3rHrKNtLIoS0oZwkY2vxi+oJcwFRWdtUyRII+so45p8= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.32.0 h1:cMyu9O88joYEaI47CnQkxO1XZdpoTF9fEnW2duIddhw= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.32.0/go.mod h1:6Am3rn7P9TVVeXYG+wtcGE7IE1tsQ+bP3AuWcKt/gOI= +go.opentelemetry.io/otel/metric v1.32.0 h1:xV2umtmNcThh2/a/aCP+h64Xx5wsj8qqnkYZktzNa0M= +go.opentelemetry.io/otel/metric v1.32.0/go.mod h1:jH7CIbbK6SH2V2wE16W05BHCtIDzauciCRLoc/SyMv8= +go.opentelemetry.io/otel/sdk v1.32.0 h1:RNxepc9vK59A8XsgZQouW8ue8Gkb4jpWtJm9ge5lEG4= +go.opentelemetry.io/otel/sdk v1.32.0/go.mod h1:LqgegDBjKMmb2GC6/PrTnteJG39I8/vJCAP9LlJXEjU= +go.opentelemetry.io/otel/trace v1.32.0 h1:WIC9mYrXf8TmY/EXuULKc8hR17vE+Hjv2cssQDe03fM= +go.opentelemetry.io/otel/trace v1.32.0/go.mod h1:+i4rkvCraA+tG6AzwloGaCtkx53Fa+L+V8e9a7YvhT8= +go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeXrui0= +go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4= +golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s= +golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug= +golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4= +golang.org/x/time v0.8.0 h1:9i3RxcPv3PZnitoVGMPDKZSq1xW1gK1Xy3ArNOGZfEg= +golang.org/x/time v0.8.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28 h1:M0KvPgPmDZHPlbRbaNU1APr28TvwvvdUPlSv7PUvy8g= +google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28/go.mod h1:dguCy7UOdZhTvLzDyt15+rOrawrpM4q7DD9dQ1P11P4= +google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28 h1:XVhgTWWV3kGQlwJHR3upFWZeTsei6Oks1apkZSeonIE= +google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI= +google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E= +google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA= +google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= +google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU= +gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU= diff --git a/mfins-doctor/main.go b/mfins-doctor/main.go new file mode 100644 index 0000000..bcb6e53 --- /dev/null +++ b/mfins-doctor/main.go @@ -0,0 +1,85 @@ +package main + +import ( + "bufio" + "context" + "fmt" + "io" + "log" + "strings" + "time" + + "github.com/docker/docker/api/types/container" + "github.com/docker/docker/client" +) + +var ( + suffix = " :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::" + end_suffix = "================ <<: :>> ================" + chk_words = [3]string{"Failed", "Error", "panic"} + lastStartDate time.Time +) + +func getDate(line string) time.Time { + line_s := strings.TrimSuffix(line, suffix) + dateTimeString := strings.TrimPrefix(line_s, "\x02\x00\x00\x00\x00\x00\x00R") + + layout := "2006/01/02 15:04:05" + + t, err := time.Parse(layout, dateTimeString) + + if err != nil { + fmt.Println("Error parsing date-time:", err) + } + + return t +} + +func main() { + cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) + if err != nil { + fmt.Printf("Error creating Docker client: %v\n", err) + return + } + + containerID := "mfins" + + logOptions := container.LogsOptions{ + ShowStdout: true, + ShowStderr: true, + Follow: true, + Timestamps: false, + } + + logs, err := cli.ContainerLogs(context.Background(), containerID, logOptions) + if err != nil { + fmt.Printf("Error fetching logs: %v\n", err) + return + } + defer logs.Close() + + scanner := bufio.NewScanner(logs) + + for scanner.Scan() { + line := scanner.Text() + + if strings.HasSuffix(line, suffix) { + lastStartDate = getDate(line) + } + + for _, word := range chk_words { + if strings.Contains(line, word) { + err_trim := strings.TrimPrefix(line, "\x02\x00\x00\x00\x00\x00\x00R") + log.Printf("Error: MFINS service failed: %s", err_trim) + } + } + + if strings.HasSuffix(line, end_suffix) { + log.Printf("Last successful run: %s", lastStartDate.String()) + } + } + + if err := scanner.Err(); err != nil && err != io.EOF { + fmt.Printf("Error reading logs: %v\n", err) + } +} From 501a4acfd583574ccbb67492a621da0c7ca98385 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Fri, 6 Dec 2024 21:51:06 +0530 Subject: [PATCH 69/72] feat: monitoring service run always --- mfins-doctor/main.go | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/mfins-doctor/main.go b/mfins-doctor/main.go index bcb6e53..eb8f205 100644 --- a/mfins-doctor/main.go +++ b/mfins-doctor/main.go @@ -18,6 +18,7 @@ var ( end_suffix = "================ <<: :>> ================" chk_words = [3]string{"Failed", "Error", "panic"} lastStartDate time.Time + containerID string ) func getDate(line string) time.Time { @@ -35,14 +36,7 @@ func getDate(line string) time.Time { return t } -func main() { - cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) - if err != nil { - fmt.Printf("Error creating Docker client: %v\n", err) - return - } - - containerID := "mfins" +func CheckLogs(cli *client.Client) { logOptions := container.LogsOptions{ ShowStdout: true, @@ -83,3 +77,18 @@ func main() { fmt.Printf("Error reading logs: %v\n", err) } } + +func main() { + cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) + if err != nil { + fmt.Printf("Error creating Docker client: %v\n", err) + return + } + + containerID = "mfins" + + for { + CheckLogs(cli) + } + +} From a4e2e3bf074ada5bc004951259a3c501fbbe96f2 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Fri, 6 Dec 2024 21:51:45 +0530 Subject: [PATCH 70/72] feat: add monitoring service to go work --- go.work | 5 ++++- go.work.sum | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/go.work b/go.work index af59537..f793d8b 100644 --- a/go.work +++ b/go.work @@ -1,3 +1,6 @@ go 1.23.1 -use ./mfins +use ( + ./mfins + ./mfins-doctor +) diff --git a/go.work.sum b/go.work.sum index 1f1bd05..7a7fb8d 100644 --- a/go.work.sum +++ b/go.work.sum @@ -3,21 +3,59 @@ cloud.google.com/go v0.115.1 h1:Jo0SM9cQnSkYfp44+v+NQXHpcHqlnRJk2qxh6yvxxxQ= cloud.google.com/go v0.115.1/go.mod h1:DuujITeaufu3gL68/lOFIirVNJwQeyf5UXyi+Wbgknc= cloud.google.com/go/compute v1.23.3 h1:6sVlXXBmbd7jNX0Ipq0trII3e4n1/MsADLK6a+aiVlk= cloud.google.com/go/compute v1.23.3/go.mod h1:VCgBUoMnIVIR0CscqQiPJLAG25E3ZRZMzcFZeQ+h8CI= +cloud.google.com/go/compute/metadata v0.3.0/go.mod h1:zFmK7XCadkQkj6TtorcaGlCW1hT1fIilQDwofLpJ20k= +cloud.google.com/go/compute/metadata v0.5.0/go.mod h1:aHnloV2TPI38yx4s9+wAZhHykWvVCfu7hQbF+9CWoiY= cloud.google.com/go/longrunning v0.5.6/go.mod h1:vUaDrWYOMKRuhiv6JBnn49YxCPz2Ayn9GqyjaBT8/mA= cloud.google.com/go/translate v1.10.3/go.mod h1:GW0vC1qvPtd3pgtypCv4k4U8B7EdgK9/QEF2aJEUovs= github.com/census-instrumentation/opencensus-proto v0.4.1/go.mod h1:4T9NM4+4Vw91VeyqjLS6ao50K5bOcLKN6Q42XnYaRYw= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cncf/xds/go v0.0.0-20240723142845-024c85f92f20/go.mod h1:W+zGtBO5Y1IgJhy4+A9GOqVhqLpfZi+vwmdNXUehLA8= +github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= github.com/envoyproxy/go-control-plane v0.13.0/go.mod h1:GRaKG3dwvFoTg4nj7aXdZnvMg4d7nvT/wl9WgVXn3Q8= github.com/envoyproxy/protoc-gen-validate v1.1.0/go.mod h1:sXRDRVmzEbkM7CVcM06s9shE/m23dg3wzjl0UWqJ2q4= github.com/golang/glog v1.2.2/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-pkcs11 v0.3.0/go.mod h1:6eQoGcuNJpa7jnd5pMGdkSaQpNDYvPlXWMcjXXThLlY= +github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/lyft/protoc-gen-star/v2 v2.0.4-0.20230330145011-496ad1ac90a4/go.mod h1:amey7yeodaJhXSbf/TlLvWiqQfLOSpEk//mLlc+axEk= github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10/go.mod h1:t/avpk3KcrXxUnYOhZhMXJlSEyie6gQbtLq5NM3loB8= +github.com/prometheus/client_model v0.6.0/go.mod h1:NTQHnmxFpouOD0DpvP4XujX3CdOAGQPoaGhyTchlyt8= +github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY= +github.com/spf13/afero v1.10.0/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= +github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= +github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= +github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0/go.mod h1:B9yO6b04uB80CzjedvewuqDhxJxi11s7/GtiGa8bAjI= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw= +golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U= golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= +golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= +golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ= +golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE= +golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24= +golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M= +golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= google.golang.org/genproto v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:hL97c3SYopEHblzpxRL4lSs523++l8DYxGM1FQiYmb4= google.golang.org/genproto/googleapis/bytestream v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:q0eWNnCW04EJlyrmLT+ZHsjuoUiZ36/eAEdCCezZoco= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU= +google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= From f183115210b6e86bcc0341777d527005ab982e12 Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Fri, 6 Dec 2024 21:52:00 +0530 Subject: [PATCH 71/72] feat: add delimiters --- mfins/main.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mfins/main.go b/mfins/main.go index 6c9ea59..57dfbdb 100644 --- a/mfins/main.go +++ b/mfins/main.go @@ -41,7 +41,8 @@ var ( ) func RunCron() { - for true { + for { + log.Println(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::") log.Println("Logining Into ERP....") ERPLogin() @@ -53,6 +54,8 @@ func RunCron() { getNewNotices(key) } + log.Println("================ <<: :>> ================") + time.Sleep(time.Duration(TimeRepeat) * time.Second) } } @@ -98,11 +101,12 @@ func getNewNotices(channel int) { func getLastNotice(channel int) int { file, err := os.OpenFile("lastmsg.json", os.O_RDWR|os.O_CREATE, os.ModePerm) - defer file.Close() if err != nil { log.Panicf("Failed to open last msg file ~ %s", err.Error()) } + defer file.Close() + var fileContent map[int]int if err = json.NewDecoder(file).Decode(&fileContent); err != nil { log.Panicf("Failed to decode last msg file ~ %s", err.Error()) @@ -113,11 +117,12 @@ func getLastNotice(channel int) int { func setLastNotice(channel int, lastMsgId int) { file, err := os.OpenFile("lastmsg.json", os.O_RDWR|os.O_CREATE, os.ModePerm) - defer file.Close() if err != nil { log.Panicf("Failed to open last msg file ~ %s", err.Error()) } + defer file.Close() + var fileContent map[int]int if err = json.NewDecoder(file).Decode(&fileContent); err != nil { log.Panicf("Failed to decode last msg file ~ %s", err.Error()) From 4d4066786d58b1101e3ebdeffa302a636984aa7c Mon Sep 17 00:00:00 2001 From: Bikram Ghuku Date: Fri, 6 Dec 2024 21:59:27 +0530 Subject: [PATCH 72/72] feat: allow docker daemon connection --- docker-compose.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index bdda965..9ad573a 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -18,4 +18,6 @@ services: context: ./mfins-doctor dockerfile: Dockerfile image: metakgp/mfins-doctor - container_name: mfins-doctor \ No newline at end of file + container_name: mfins-doctor + volumes: + - /var/run/docker.sock:/var/run/docker.sock \ No newline at end of file