Advertisement
FlyFar

tangalanga.go

Dec 28th, 2023
935
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 2.42 KB | Cybersecurity | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "io/ioutil"
  6.     "net/http"
  7.     "net/url"
  8.     "strconv"
  9.     "strings"
  10.     "time"
  11.  
  12.     pb "github.com/elcuervo/tangalanga/proto"
  13.     "github.com/golang/protobuf/proto"
  14. )
  15.  
  16. type Option func(*Tangalanga)
  17.  
  18. func WithTransport(transport *http.Transport) Option {
  19.     return func(t *Tangalanga) {
  20.         t.client = &http.Client{
  21.             Transport: transport,
  22.             Timeout:   5 * time.Second,
  23.         }
  24.     }
  25. }
  26.  
  27. type Tangalanga struct {
  28.     Found      int
  29.     Missing    int
  30.     Suspicious int
  31.  
  32.     ExpiredToken bool
  33.  
  34.     client *http.Client
  35. }
  36.  
  37. func (t *Tangalanga) Close() {
  38. }
  39.  
  40. func NewTangalanga(opts ...Option) (*Tangalanga, error) {
  41.     c := &Tangalanga{
  42.         Found:      0,
  43.         Missing:    0,
  44.         Suspicious: 0,
  45.  
  46.         ExpiredToken: false,
  47.     }
  48.  
  49.     for _, opt := range opts {
  50.         opt(c)
  51.     }
  52.  
  53.     return c, nil
  54. }
  55.  
  56. func (t *Tangalanga) FindMeeting(id int) (*pb.Meeting, error) {
  57.     meetId := strconv.Itoa(id)
  58.     p := url.Values{"cv": {"5.0.25694.0524"}, "mn": {meetId}, "uname": {"tangalanga"}}
  59.  
  60.     req, err := http.NewRequest("POST", zoomUrl, strings.NewReader(p.Encode()))
  61.  
  62.     if err != nil {
  63.         if *debugFlag {
  64.             fmt.Printf("%s\nerror: %s\n", color.Red("bad request"), err.Error())
  65.         }
  66.         return nil, err
  67.     }
  68.  
  69.     cookie := fmt.Sprintf("zpk=%s", *token)
  70.  
  71.     req.Header.Add("Cookie", cookie)
  72.     req.Header.Add("ZM-CAP", "2535978022733895607,32676")
  73.     req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
  74.  
  75.     resp, err := t.client.Do(req)
  76.  
  77.     if err != nil {
  78.         if *debugFlag {
  79.             fmt.Printf("%s\nerror: %s\n", color.Red("can't connect to Zoom!!"), err.Error())
  80.         }
  81.         return nil, err
  82.     }
  83.  
  84.     body, err := ioutil.ReadAll(resp.Body)
  85.  
  86.     if err != nil {
  87.         if *debugFlag {
  88.             fmt.Printf("%s\nerror: %s\n", color.Red("bad body"), err.Error())
  89.         }
  90.         return nil, err
  91.     }
  92.  
  93.     m := &pb.Meeting{}
  94.     err = proto.Unmarshal(body, m)
  95.  
  96.     if err != nil {
  97.         if *debugFlag {
  98.             fmt.Printf("%s\nerror: %s\n", color.Red("can't unpack protobuf"), err.Error())
  99.         }
  100.         return nil, err
  101.     }
  102.  
  103.     missing := m.GetError() != 0
  104.  
  105.     if missing {
  106.         t.Missing++
  107.  
  108.         info := m.GetInformation()
  109.  
  110.         if m.GetError() == 124 {
  111.             t.ExpiredToken = true
  112.         }
  113.  
  114.         // suspicious not found when there are too many
  115.         if info == "Meeting not existed." {
  116.             t.Suspicious++
  117.         } else {
  118.             t.Suspicious = 0
  119.         }
  120.  
  121.         return nil, fmt.Errorf("%s: %s", color.Blue("zoom"), color.Red(info))
  122.     } else {
  123.         // Reset suspicious counter when found
  124.         t.Suspicious = 0
  125.         t.Found++
  126.     }
  127.  
  128.     return m, nil
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement