Skip to content
This repository has been archived by the owner on Jan 7, 2024. It is now read-only.

Commit

Permalink
Upload do código-fonte funcional.
Browse files Browse the repository at this point in the history
  • Loading branch information
lostdusty committed Feb 4, 2022
1 parent 377d82d commit a5b32c6
Show file tree
Hide file tree
Showing 6 changed files with 319 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*.dll
*.so
*.dylib
*.syso

# Test binary, built with `go test -c`
*.test
Expand Down
17 changes: 17 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module github.com/alternativeon/turmafinder

go 1.17

require (
github.com/gonutz/w32/v2 v2.2.4
github.com/ncruces/zenity v0.7.12
)

require (
github.com/akavel/rsrc v0.10.2 // indirect
github.com/dchest/jsmin v0.0.0-20160823214000-faeced883947 // indirect
github.com/josephspurrier/goversioninfo v1.3.0 // indirect
github.com/randall77/makefat v0.0.0-20210315173500-7ddd0e42c844 // indirect
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d // indirect
golang.org/x/sys v0.0.0-20210909193231-528a39cd75f3 // indirect
)
63 changes: 63 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
github.com/akavel/rsrc v0.10.2 h1:Zxm8V5eI1hW4gGaYsJQUhxpjkENuG91ki8B4zCrvEsw=
github.com/akavel/rsrc v0.10.2/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dchest/jsmin v0.0.0-20160823214000-faeced883947 h1:Fm10/KNuoAyBm2P5P5H91Xy21hGcZnBdjR+cMdytv1M=
github.com/dchest/jsmin v0.0.0-20160823214000-faeced883947/go.mod h1:Dv9D0NUlAsaQcGQZa5kc5mqR9ua72SmA8VXi4cd+cBw=
github.com/gonutz/w32/v2 v2.2.4 h1:VvM3+PS2wmm94HaA4eSYtbpR6uiKqk7vAboNAm9vzjQ=
github.com/gonutz/w32/v2 v2.2.4/go.mod h1:MgtHx0AScDVNKyB+kjyPder4xIi3XAcHS6LDDU2DmdE=
github.com/josephspurrier/goversioninfo v1.3.0 h1:pmgDhWnG8I59p5kCR09J73s/gy9JqRPAtiaUK8jixtE=
github.com/josephspurrier/goversioninfo v1.3.0/go.mod h1:JWzv5rKQr+MmW+LvM412ToT/IkYDZjaclF2pKDss8IY=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/ncruces/zenity v0.7.12 h1:NITUYXHby0Wlb+4lWsBs53U4n8hGqDPrnyxuHT1geHs=
github.com/ncruces/zenity v0.7.12/go.mod h1:218cld52IfyQ5Mkdt/koDUBSz93sM81DZ3OQNkj8o+c=
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/randall77/makefat v0.0.0-20210315173500-7ddd0e42c844 h1:GranzK4hv1/pqTIhMTXt2X8MmMOuH3hMeUR0o9SP5yc=
github.com/randall77/makefat v0.0.0-20210315173500-7ddd0e42c844/go.mod h1:T1TLSfyWVBRXVGzWd0o9BI4kfoO9InEgfQe4NV3mLz8=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
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/image v0.0.0-20210628002857-a66eb6448b8d h1:RNPAfi2nHY7C2srAV8A49jpsYr0ADedCk1wq6fTMTvs=
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
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-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
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/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-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210909193231-528a39cd75f3 h1:3Ad41xy2WCESpufXwgs7NpDSu+vjxqLt2UFqUV+20bI=
golang.org/x/sys v0.0.0-20210909193231-528a39cd75f3/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
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.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
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-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
178 changes: 178 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
//Versão 1.0
//Program to find what is your class
package main

import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"strings"

"github.com/gonutz/w32/v2"
"github.com/ncruces/zenity"
)

type Token struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
ExpiresIn int `json:"expires_in"`
TokenType string `json:"token_type"`
JSON string `json:"json"`
}

type Error struct {
Error string `json:"error"`
ErrorDescription string `json:"error_description"`
}

type AutoGenerated []struct {
Value string `json:"value"`
Label string `json:"label"`
Turmas []Turmas `json:"turmas"`
}
type Turmas struct {
NomeTurma string `json:"nomeTurma"`
TurmaValida bool `json:"turmaValida"`
NomeSerie string `json:"nomeSerie"`
}

func main() {
//Dialog asking for the username and password
user, err := zenity.Entry("Qual o seu usuário do Positivo On?", zenity.Title("Descubra sua turma"), zenity.EntryText("Usuário"))
if err != nil {
fmt.Println("[i] {username}", err)
os.Exit(0)
}
if user == "" {
zenity.Error("Usuário não informado", zenity.Title("Erro"), zenity.ErrorIcon)
fmt.Println("[w] Usuário não informado")
main()
}
_, pass, err := zenity.Password(zenity.Title("Qual a sua senha do Positivo On?"))
if err != nil {
fmt.Println("[i] {password}", err)
os.Exit(0)
}
if pass == "" {
zenity.Error("Senha não informada", zenity.Title("Erro"), zenity.ErrorIcon)
fmt.Println("[w] Senha não informada")
main()
}
//Do a x-www-form-urlencoded request to https://sso.specomunica.com.br/connect/token using requests package
token, err := postReq("https://sso.specomunica.com.br/connect/token", "POST", "username="+user+"&password="+pass+"&grant_type=password&client_id=hubpsd&client_secret=DA5730D8-90FF-4A41-BFED-147B8E0E2A08&scope=openid%20offline_access%20integration_info")
if err != nil {
fmt.Println("[E] Login falhou", err)
os.Exit(1)
}
//do a GET request to https://apihub.positivoon.com.br/api/NivelEnsino?usuarioId=1485 using bearer token
turma, err := authReq("https://apihub.positivoon.com.br/api/NivelEnsino?usuarioId=1485", "GET", token)
if err != nil {
fmt.Println("[E] Erro ao buscar turma", err)
os.Exit(1)
}
//Unmarshal response

var turmaAutoGenerated AutoGenerated
err = json.Unmarshal([]byte(turma), &turmaAutoGenerated)
if err != nil {
fmt.Println("[E] Erro ao deserializar", err)
os.Exit(1)
}
//Print nome da turma
fmt.Println("[i] Sua turma é:", turmaAutoGenerated[0].Value)
//Print nome da série
fmt.Println("[i] Sua série é:", turmaAutoGenerated[0].Label)
//Print nome da turma
fmt.Println("[i] Sua turma é:", turmaAutoGenerated[0].Turmas[0].NomeTurma)
//Print nome da série
fmt.Println("[i] Sua série é:", turmaAutoGenerated[0].Turmas[0].NomeSerie)
//Print nome da turma
fmt.Println("[i] Sua turma é:", turmaAutoGenerated[0].Turmas[0].TurmaValida)
zenity.Info("Sua turma é: "+turmaAutoGenerated[0].Turmas[0].NomeTurma+" ("+turmaAutoGenerated[0].Label+" - "+turmaAutoGenerated[0].Value+""+turmaAutoGenerated[0].Turmas[0].NomeSerie+")", zenity.Title("Sucesso! Sua turma é:"), zenity.InfoIcon)
//Ask if you want to see another project in github
openBrowser := zenity.Question("Deseja ver um cliente alternativo ao Positivo On?", zenity.Title("Deseja ver um cliente alternativo ao Positivo On?"), zenity.QuestionIcon)
switch {
case openBrowser != zenity.ErrCanceled:
//Open link in browser
err := w32.ShellExecute(0, "open", "https://github.com/PrincessMortix/AlternativeOn", "", "", w32.SW_SHOW)
if err != nil {
fmt.Println("[E]", err)
}
default:
os.Exit(0)
}

}

func postReq(url string, method string, payload string) (string, error) {

client := &http.Client{}
fmt.Println("[d | postReq] Payload:", payload)
req, err := http.NewRequest(method, url, strings.NewReader(payload))

if err != nil {
fmt.Println("[e | postReq]", err)
return "Failed to create request:", err
}
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")

res, err := client.Do(req)
if err != nil {
fmt.Println("[e | postReq]", err)
return "Failed to send request: ", err
}
defer res.Body.Close()

body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println("[e | postReq]", err)
return "Failed to read response: ", err
}

//fmt.Println("[d] Response:", string(body))
//Check if response is valid
if res.StatusCode != 200 {
//Unmarshal error response
var errResp Error
json.Unmarshal(body, &errResp)
fmt.Println("[e | postReq] Error:", errResp.Error)
fmt.Println("[e | postReq] Error description:", errResp.ErrorDescription)
zenity.Error(errResp.ErrorDescription, zenity.Title("Erro"), zenity.ErrorIcon)
return errResp.Error + ": " + errResp.ErrorDescription, err
}
//Unmarshal response
var token Token
json.Unmarshal(body, &token)
//convert int to string
expiresIn := fmt.Sprintf("%d", token.ExpiresIn)
fmt.Println("[d | postReq] Token: "+token.AccessToken, "\n[d | postReq] Refresh Token: "+token.RefreshToken, "\n[d | postReq] Expires In: "+expiresIn, "\n[d | postReq] Token Type: "+token.TokenType)
//zenity.Info("Login realizado com sucesso!\n\nIremos agora tentar carregar as soluções...", zenity.Title("Login realizado com sucesso!"), zenity.InfoIcon)
return token.AccessToken, nil
}

func authReq(url string, method string, token string) (string, error) {

client := &http.Client{}
req, err := http.NewRequest(method, url, nil)

if err != nil {
return "", err
}
req.Header.Add("Authorization", "Bearer "+token)

res, err := client.Do(req)
if err != nil {
fmt.Println("[e | authReq]", err)
return "", err
}
defer res.Body.Close()

body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println("[e | authReq]", err)
return "", err
}
return string(body), nil
}
Binary file added winres/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 60 additions & 0 deletions winres/winres.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"RT_GROUP_ICON": {
"APP": {
"0000": [
"icon.png"
]
}
},
"RT_MANIFEST": {
"#1": {
"0409": {
"identity": {
"name": "Turma Finder",
"version": "1.0"
},
"description": "Descubra sua turma de forma rápida e fácil",
"minimum-os": "win7",
"execution-level": "",
"ui-access": false,
"auto-elevate": false,
"dpi-awareness": "per monitor v2",
"disable-theming": false,
"disable-window-filtering": false,
"high-resolution-scrolling-aware": false,
"ultra-high-resolution-scrolling-aware": false,
"long-path-aware": false,
"printer-driver-isolation": false,
"gdi-scaling": false,
"segment-heap": true,
"use-common-controls-v6": true
}
}
},
"RT_VERSION": {
"#1": {
"0000": {
"fixed": {
"file_version": "1.0",
"product_version": "1.0"
},
"info": {
"0409": {
"Comments": "Descubra sua turma de forma rápida e fácil",
"CompanyName": "Princess Mortix",
"FileDescription": "",
"FileVersion": "1.0",
"InternalName": "turmafinder.exe",
"LegalCopyright": "Princess Mortix, 2022",
"LegalTrademarks": "Princess Mortix",
"OriginalFilename": "",
"PrivateBuild": "",
"ProductName": "TurmaFinder",
"ProductVersion": "1.0",
"SpecialBuild": ""
}
}
}
}
}
}

0 comments on commit a5b32c6

Please sign in to comment.