Skip to content

Commit

Permalink
Log in to Astra
Browse files Browse the repository at this point in the history
  • Loading branch information
TyHil committed Sep 25, 2024
1 parent e89f7b8 commit d6750ab
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#Scrapers
LOGIN_NETID=
LOGIN_PASSWORD=
LOGIN_ASTRA_USERNAME=
LOGIN_ASTRA_PASSWORD=
HEADLESS_MODE=false

#Uploader
Expand Down
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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!")
}
Expand Down
26 changes: 26 additions & 0 deletions scrapers/astra.go
Original file line number Diff line number Diff line change
@@ -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)
}
33 changes: 33 additions & 0 deletions utils/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d6750ab

Please sign in to comment.