Skip to content

Commit

Permalink
(Closed #4) Added -include-account option
Browse files Browse the repository at this point in the history
  • Loading branch information
hahwul committed Feb 22, 2021
1 parent f1c4784 commit d8a5d4f
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 42 deletions.
54 changes: 25 additions & 29 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
package main

import (
"strings"
"fmt"
"bufio"
"flag"
"fmt"
"os"
"bufio"
"strings"

printing "github.com/hahwul/gitls/pkg/printing"
module "github.com/hahwul/gitls/pkg/modules"
model "github.com/hahwul/gitls/pkg/model"
module "github.com/hahwul/gitls/pkg/modules"
printing "github.com/hahwul/gitls/pkg/printing"
)

func main(){
list := flag.String("l","","List of targets (e.g -l sample.lst)")
output := flag.String("o","","write output file (optional)")
version := flag.Bool("version",false,"version of gitls")
proxy := flag.String("proxy","","using custom proxy")
useTor := flag.Bool("tor",false,"using tor proxy / localhost:9050")
func main() {
list := flag.String("l", "", "List of targets (e.g -l sample.lst)")
output := flag.String("o", "", "write output file (optional)")
version := flag.Bool("version", false, "version of gitls")
proxy := flag.String("proxy", "", "using custom proxy")
useTor := flag.Bool("tor", false, "using tor proxy / localhost:9050")
includeAccount := flag.Bool("include-account", false, "include repo of account in targeet")
flag.Parse()
options := model.Options{
Proxy: *proxy,
UseTor: *useTor,
Output: *output,
Proxy: *proxy,
UseTor: *useTor,
Output: *output,
IncludeAccount: *includeAccount,
}
if *version {
fmt.Println(printing.VERSION)
Expand All @@ -34,28 +36,22 @@ func main(){
for sc.Scan() {
line := strings.ToLower(sc.Text())
if line != "" {
checkURL(line, options)
module.CheckURL(line, options)
}
if *includeAccount {
module.CheckAccount(line, options)
}
}
} else {
target, err := module.ReadLinesOrLiteral(*list)
_ = err
for i, v := range target {
_ = i
checkURL(v, options)
}
}
}
func checkURL(s string, options model.Options) {
str := strings.Split(s,"/")
size := len(str) // 4 is user/org , 5 is repository
if size == 4 {
if strings.Contains(str[2],"github") {
module.GetRepoListFromUser(str[3], str[2], options)
} else if strings.Contains(str[2], "gitlab") {
// TODO gitlab getting repos
module.CheckURL(v, options)
if *includeAccount {
module.CheckAccount(v, options)
}
}
} else if size == 5 {
fmt.Println(s)

}
}
7 changes: 4 additions & 3 deletions pkg/model/model.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package model

type Options struct {
Proxy string
UseTor bool
Output string
Proxy string
UseTor bool
Output string
IncludeAccount bool
}
38 changes: 38 additions & 0 deletions pkg/modules/check.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package modules

import (
"fmt"
"strings"

"github.com/hahwul/gitls/pkg/model"
)

// CheckAccount is repo list of accounts in target
func CheckAccount(s string, options model.Options) {
str := strings.Split(s, "/")
size := len(str) // 4 is user/org , 5 is repository
if size == 4 {
if strings.Contains(str[2], "github") {
GetRepoListFromIncludeAccount(str[3], str[2], options)
} else if strings.Contains(str[2], "gitlab") {
// TODO gitlab getting repos
}
} else if size == 5 {
fmt.Println(s)
}
}

// CheckURL is repo list of target
func CheckURL(s string, options model.Options) {
str := strings.Split(s, "/")
size := len(str) // 4 is user/org , 5 is repository
if size == 4 {
if strings.Contains(str[2], "github") {
GetRepoListFromUser(str[3], str[2], options)
} else if strings.Contains(str[2], "gitlab") {
// TODO gitlab getting repos
}
} else if size == 5 {
fmt.Println(s)
}
}
57 changes: 47 additions & 10 deletions pkg/modules/github.go
Original file line number Diff line number Diff line change
@@ -1,36 +1,73 @@
package modules

import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"time"
"io/ioutil"
"encoding/json"

model "github.com/hahwul/gitls/pkg/model"
transport "github.com/hahwul/gitls/pkg/transport"
)

// GithubObject is json object of github api
type GithubObject struct {
Html_URL string `"json:html_url"`
Fork bool `"json:fork"`
URL string `json:"html_url"`
Fork bool `json:"fork"`
}

// GetRepoListFromIncludeAccount is get repo list from account of org
func GetRepoListFromIncludeAccount(user, repoHost string, options model.Options) {
check := true
for i := 1; check; i++ {
apiAddress := fmt.Sprintf("https://api."+repoHost+"/orgs/%v/members?page=%v&per_page=100", user, i)
req, err := http.NewRequest("GET", apiAddress, nil)
transport := transport.GetTransport(options)
client := &http.Client{
Timeout: 5 * time.Second,
Transport: transport,
}

resp, err := client.Do(req)
if err != nil {

}

defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
if string(data) == "[]" {
check = false
}
var objects []GithubObject
json.Unmarshal(data, &objects)
for k, v := range objects {
_ = k
if !v.Fork {
fmt.Println(v.URL)
CheckURL(v.URL, options)
}
}
}
}

// GetRepoListFromUser is gettting repo list from github
func GetRepoListFromUser(user,repoHost string, options model.Options){
func GetRepoListFromUser(user, repoHost string, options model.Options) {
check := true
for i:=1 ; check ; i++ {
for i := 1; check; i++ {
apiAddress := fmt.Sprintf("https://api."+repoHost+"/users/%v/repos?page=%v&per_page=100", user, i)
req, err := http.NewRequest("GET",apiAddress,nil)
req, err := http.NewRequest("GET", apiAddress, nil)
transport := transport.GetTransport(options)
client := &http.Client{
Timeout: 5 * time.Second,
Transport: transport,
}

resp, err := client.Do(req)
if err != nil {
if err != nil {

}

Expand All @@ -43,11 +80,11 @@ func GetRepoListFromUser(user,repoHost string, options model.Options){
check = false
}
var objects []GithubObject
json.Unmarshal(data,&objects)
json.Unmarshal(data, &objects)
for k, v := range objects {
_ = k
if !v.Fork {
fmt.Println(v.Html_URL)
fmt.Println(v.URL)
}
}
}
Expand Down
Binary file removed pkg/modules/modules
Binary file not shown.

0 comments on commit d8a5d4f

Please sign in to comment.