Skip to content
This repository was archived by the owner on Apr 10, 2025. It is now read-only.

Commit d8a5d4f

Browse files
committed
(Closed #4) Added -include-account option
1 parent f1c4784 commit d8a5d4f

File tree

5 files changed

+114
-42
lines changed

5 files changed

+114
-42
lines changed

main.go

+25-29
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
package main
22

33
import (
4-
"strings"
5-
"fmt"
4+
"bufio"
65
"flag"
6+
"fmt"
77
"os"
8-
"bufio"
8+
"strings"
99

10-
printing "github.com/hahwul/gitls/pkg/printing"
11-
module "github.com/hahwul/gitls/pkg/modules"
1210
model "github.com/hahwul/gitls/pkg/model"
11+
module "github.com/hahwul/gitls/pkg/modules"
12+
printing "github.com/hahwul/gitls/pkg/printing"
1313
)
1414

15-
func main(){
16-
list := flag.String("l","","List of targets (e.g -l sample.lst)")
17-
output := flag.String("o","","write output file (optional)")
18-
version := flag.Bool("version",false,"version of gitls")
19-
proxy := flag.String("proxy","","using custom proxy")
20-
useTor := flag.Bool("tor",false,"using tor proxy / localhost:9050")
15+
func main() {
16+
list := flag.String("l", "", "List of targets (e.g -l sample.lst)")
17+
output := flag.String("o", "", "write output file (optional)")
18+
version := flag.Bool("version", false, "version of gitls")
19+
proxy := flag.String("proxy", "", "using custom proxy")
20+
useTor := flag.Bool("tor", false, "using tor proxy / localhost:9050")
21+
includeAccount := flag.Bool("include-account", false, "include repo of account in targeet")
2122
flag.Parse()
2223
options := model.Options{
23-
Proxy: *proxy,
24-
UseTor: *useTor,
25-
Output: *output,
24+
Proxy: *proxy,
25+
UseTor: *useTor,
26+
Output: *output,
27+
IncludeAccount: *includeAccount,
2628
}
2729
if *version {
2830
fmt.Println(printing.VERSION)
@@ -34,28 +36,22 @@ func main(){
3436
for sc.Scan() {
3537
line := strings.ToLower(sc.Text())
3638
if line != "" {
37-
checkURL(line, options)
39+
module.CheckURL(line, options)
40+
}
41+
if *includeAccount {
42+
module.CheckAccount(line, options)
3843
}
3944
}
4045
} else {
4146
target, err := module.ReadLinesOrLiteral(*list)
4247
_ = err
4348
for i, v := range target {
4449
_ = i
45-
checkURL(v, options)
46-
}
47-
}
48-
}
49-
func checkURL(s string, options model.Options) {
50-
str := strings.Split(s,"/")
51-
size := len(str) // 4 is user/org , 5 is repository
52-
if size == 4 {
53-
if strings.Contains(str[2],"github") {
54-
module.GetRepoListFromUser(str[3], str[2], options)
55-
} else if strings.Contains(str[2], "gitlab") {
56-
// TODO gitlab getting repos
50+
module.CheckURL(v, options)
51+
if *includeAccount {
52+
module.CheckAccount(v, options)
53+
}
5754
}
58-
} else if size == 5 {
59-
fmt.Println(s)
55+
6056
}
6157
}

pkg/model/model.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package model
22

33
type Options struct {
4-
Proxy string
5-
UseTor bool
6-
Output string
4+
Proxy string
5+
UseTor bool
6+
Output string
7+
IncludeAccount bool
78
}

pkg/modules/check.go

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package modules
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
7+
"github.com/hahwul/gitls/pkg/model"
8+
)
9+
10+
// CheckAccount is repo list of accounts in target
11+
func CheckAccount(s string, options model.Options) {
12+
str := strings.Split(s, "/")
13+
size := len(str) // 4 is user/org , 5 is repository
14+
if size == 4 {
15+
if strings.Contains(str[2], "github") {
16+
GetRepoListFromIncludeAccount(str[3], str[2], options)
17+
} else if strings.Contains(str[2], "gitlab") {
18+
// TODO gitlab getting repos
19+
}
20+
} else if size == 5 {
21+
fmt.Println(s)
22+
}
23+
}
24+
25+
// CheckURL is repo list of target
26+
func CheckURL(s string, options model.Options) {
27+
str := strings.Split(s, "/")
28+
size := len(str) // 4 is user/org , 5 is repository
29+
if size == 4 {
30+
if strings.Contains(str[2], "github") {
31+
GetRepoListFromUser(str[3], str[2], options)
32+
} else if strings.Contains(str[2], "gitlab") {
33+
// TODO gitlab getting repos
34+
}
35+
} else if size == 5 {
36+
fmt.Println(s)
37+
}
38+
}

pkg/modules/github.go

+47-10
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,73 @@
11
package modules
22

33
import (
4+
"encoding/json"
45
"fmt"
6+
"io/ioutil"
57
"net/http"
68
"time"
7-
"io/ioutil"
8-
"encoding/json"
99

1010
model "github.com/hahwul/gitls/pkg/model"
1111
transport "github.com/hahwul/gitls/pkg/transport"
1212
)
1313

1414
// GithubObject is json object of github api
1515
type GithubObject struct {
16-
Html_URL string `"json:html_url"`
17-
Fork bool `"json:fork"`
16+
URL string `json:"html_url"`
17+
Fork bool `json:"fork"`
18+
}
19+
20+
// GetRepoListFromIncludeAccount is get repo list from account of org
21+
func GetRepoListFromIncludeAccount(user, repoHost string, options model.Options) {
22+
check := true
23+
for i := 1; check; i++ {
24+
apiAddress := fmt.Sprintf("https://api."+repoHost+"/orgs/%v/members?page=%v&per_page=100", user, i)
25+
req, err := http.NewRequest("GET", apiAddress, nil)
26+
transport := transport.GetTransport(options)
27+
client := &http.Client{
28+
Timeout: 5 * time.Second,
29+
Transport: transport,
30+
}
31+
32+
resp, err := client.Do(req)
33+
if err != nil {
34+
35+
}
36+
37+
defer resp.Body.Close()
38+
data, err := ioutil.ReadAll(resp.Body)
39+
if err != nil {
40+
panic(err)
41+
}
42+
if string(data) == "[]" {
43+
check = false
44+
}
45+
var objects []GithubObject
46+
json.Unmarshal(data, &objects)
47+
for k, v := range objects {
48+
_ = k
49+
if !v.Fork {
50+
fmt.Println(v.URL)
51+
CheckURL(v.URL, options)
52+
}
53+
}
54+
}
1855
}
1956

2057
// GetRepoListFromUser is gettting repo list from github
21-
func GetRepoListFromUser(user,repoHost string, options model.Options){
58+
func GetRepoListFromUser(user, repoHost string, options model.Options) {
2259
check := true
23-
for i:=1 ; check ; i++ {
60+
for i := 1; check; i++ {
2461
apiAddress := fmt.Sprintf("https://api."+repoHost+"/users/%v/repos?page=%v&per_page=100", user, i)
25-
req, err := http.NewRequest("GET",apiAddress,nil)
62+
req, err := http.NewRequest("GET", apiAddress, nil)
2663
transport := transport.GetTransport(options)
2764
client := &http.Client{
2865
Timeout: 5 * time.Second,
2966
Transport: transport,
3067
}
3168

3269
resp, err := client.Do(req)
33-
if err != nil {
70+
if err != nil {
3471

3572
}
3673

@@ -43,11 +80,11 @@ func GetRepoListFromUser(user,repoHost string, options model.Options){
4380
check = false
4481
}
4582
var objects []GithubObject
46-
json.Unmarshal(data,&objects)
83+
json.Unmarshal(data, &objects)
4784
for k, v := range objects {
4885
_ = k
4986
if !v.Fork {
50-
fmt.Println(v.Html_URL)
87+
fmt.Println(v.URL)
5188
}
5289
}
5390
}

pkg/modules/modules

-6.56 MB
Binary file not shown.

0 commit comments

Comments
 (0)