diff --git a/.env.template b/.env.template index 2ead8de..a560670 100644 --- a/.env.template +++ b/.env.template @@ -1,6 +1,8 @@ #Scrapers LOGIN_NETID= LOGIN_PASSWORD= +LOGIN_ASTRA_USERNAME= +LOGIN_ASTRA_PASSWORD= HEADLESS_MODE=false #Uploader diff --git a/main.go b/main.go index 04e4271..ff46c56 100644 --- a/main.go +++ b/main.go @@ -36,6 +36,8 @@ func main() { scrapeOrganizations := flag.Bool("organizations", false, "Alongside -scrape, signifies that SOC organizations should be scraped.") // Flag for event scraping scrapeEvents := flag.Bool("events", false, "Alongside -scrape, signifies that events should be scraped.") + // Flag for astra scraping + scrapeAstra := flag.Bool("astra", false, "Alongside -scrape, signifies that Astra should be scraped.") // Flags for parsing parse := flag.Bool("parse", false, "Puts the tool into parsing mode.") @@ -92,6 +94,8 @@ func main() { scrapers.ScrapeOrganizations(*outDir) case *scrapeEvents: scrapers.ScrapeEvents(*outDir) + case *scrapeAstra: + scrapers.ScrapeAstra(*outDir) default: log.Panic("You must specify which type of scraping you would like to perform with one of the scraping flags!") } diff --git a/scrapers/astra.go b/scrapers/astra.go new file mode 100644 index 0000000..23794ec --- /dev/null +++ b/scrapers/astra.go @@ -0,0 +1,26 @@ +/* + This file contains the code for the Astra scraper. +*/ + +package scrapers + +import ( + "log" + + "github.com/UTDNebula/api-tools/utils" + "github.com/joho/godotenv" +) + +func ScrapeAstra(outDir string) { + + // Load env vars + if err := godotenv.Load(); err != nil { + log.Panic("Error loading .env file") + } + + // Start chromedp + chromedpCtx, cancel := utils.InitChromeDp() + defer cancel() + + utils.SignInAstra(chromedpCtx) +} diff --git a/utils/methods.go b/utils/methods.go index cebe6b2..12a83af 100644 --- a/utils/methods.go +++ b/utils/methods.go @@ -100,6 +100,39 @@ func RefreshToken(chromedpCtx context.Context) map[string][]string { } } +// This function signs into Astra +func SignInAstra(chromedpCtx context.Context) error { + // Get username and password + username, present := os.LookupEnv("LOGIN_ASTRA_USERNAME") + if !present { + log.Panic("LOGIN_ASTRA_USERNAME is missing from .env!") + } + password, present := os.LookupEnv("LOGIN_ASTRA_PASSWORD") + if !present { + log.Panic("LOGIN_ASTRA_PASSWORD is missing from .env!") + } + + // Sign in + VPrintf("Signing in...") + _, err := chromedp.RunResponse(chromedpCtx, + chromedp.ActionFunc(func(ctx context.Context) error { + err := network.ClearBrowserCookies().Do(ctx) + return err + }), + chromedp.Navigate(`https://www.aaiscloud.com/UTXDallas/logon.aspx?ReturnUrl=%2futxdallas%2fcalendars%2fdailygridcalendar.aspx`), + chromedp.WaitVisible(`input#userNameField-inputEl`), + chromedp.SendKeys(`input#userNameField-inputEl`, username), + chromedp.SendKeys(`input#textfield-1029-inputEl`, password), + chromedp.WaitVisible(`a#logonButton`), + chromedp.Click(`a#logonButton`), + chromedp.WaitVisible(`body`), + ) + if err != nil { + panic(err) + } + return nil +} + // Encodes and writes the given data as tab-indented JSON to the given filepath. func WriteJSON(filepath string, data interface{}) error { fptr, err := os.Create(filepath)