Skip to content

Commit

Permalink
[fix] ipv4,ipv6の登録情報検索機能の大幅な修正(これに伴う影響で他の機能は使用不可)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoneyan committed Jan 10, 2022
1 parent aa78942 commit bd7a2ff
Show file tree
Hide file tree
Showing 5 changed files with 1,732 additions and 1,407 deletions.
51 changes: 44 additions & 7 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/tls"
"crypto/x509"
"fmt"
"github.com/PuerkitoBio/goquery"
"golang.org/x/crypto/pkcs12"
"io/ioutil"
"net/http"
Expand All @@ -23,10 +24,10 @@ type request struct {
ServerSessionID string
}

func (c *Config) initAccess() (*http.Client, error) {
func (c *Config) initAccess(menuName string) (*http.Client, string, error) {
sessionID, err := randomStr()
if err != nil {
return nil, err
return nil, "", err
}

cookies := []*http.Cookie{
Expand All @@ -40,27 +41,27 @@ func (c *Config) initAccess() (*http.Client, error) {
urlObj, _ := url.Parse("https://iphostmaster.nic.ad.jp/")
jar, err := cookiejar.New(nil)
if err != nil {
return nil, err
return nil, "", err
}

jar.SetCookies(urlObj, cookies)

// Load .p12 File
p12Bytes, err := ioutil.ReadFile(c.PfxFilePath)
if err != nil {
return nil, err
return nil, "", err
}

// .p12 decode
key, cert, err := pkcs12.Decode(p12Bytes, c.PfxPass)
if err != nil {
return nil, err
return nil, "", err
}

// Load CA
caCertBytes, err := ioutil.ReadFile(c.CAFilePath)
if err != nil {
return nil, err
return nil, "", err
}
caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caCertBytes)
Expand All @@ -78,7 +79,43 @@ func (c *Config) initAccess() (*http.Client, error) {
transport := &http.Transport{TLSClientConfig: tlsConfig}
client := &http.Client{Transport: transport, Jar: jar}

return client, nil
// Login
r := request{
Client: client,
URL: baseURL + "/jpnic/certmemberlogin.do",
Body: "",
UserAgent: userAgent,
ContentType: contentType,
}

resp, err := r.get()
if err != nil {
return nil, "", err
}
defer resp.Body.Close()

result, _, err := readShiftJIS(resp.Body)
if err != nil {
return nil, "", err
}

doc, err := goquery.NewDocumentFromReader(strings.NewReader(result))
if err != nil {
return nil, "", err
}
resultContent, isExists := doc.Find("meta").Attr("content")
if !isExists {
return nil, "", fmt.Errorf("エラーが発生しました")
}
refreshURL := strings.Split(resultContent, "=")[1]

// menu
menuURL, err := getLink(client, refreshURL, menuName)
if err != nil {
return nil, "", err
}

return client, menuURL, nil
}

func getJSessionID(cookies []*http.Cookie) string {
Expand Down
87 changes: 65 additions & 22 deletions interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,32 +142,75 @@ type JPNICHandleDetail struct {
UpdateDate string `json:"update_date"`
}

type SearchIPv4 struct {
IPAddress string `json:"ip_address"`
SizeStart string `json:"size_start"`
SizeEnd string `json:"size_end"`
NetworkName string `json:"network_name"`
RegStart string `json:"reg_start"`
RegEnd string `json:"reg_end"`
ReturnStart string `json:"return_start"`
ReturnEnd string `json:"return_end"`
Org string `json:"org"`
Ryakusho string `json:"ryakusho"`
RecepNo string `json:"recep_no"`
DeliNo string `json:"deli_no"`
IsPA bool `json:"is_pa"` // 割り振り
IsAllocate bool `json:"is_allocate"` // 割り振り
IsAssignInfra bool `json:"is_assign_infra"` //インフラ割当
IsAssignUser bool `json:"is_assign_user"` //ユーザ割当
IsSubAllocate bool `json:"is_sub_allocate"` //SUBA
IsHistoricalPI bool `json:"is_historical_pi"` //歴史的PI
IsSpecialPI bool `json:"is_special_pi"` //特殊用途PI
}

type InfoIPv4 struct {
IPAddress string `json:"ip_address"`
DetailLink string `json:"detail_link"`
Size string `json:"size"`
NetworkName string `json:"network_name"`
AssignDate string `json:"assign_date"`
ReturnDate string `json:"return_date"`
OrgName string `json:"org_name"`
Ryakusho string `json:"ryakusho"`
RecepNo string `json:"recep_no"`
DeliNo string `json:"deli_no"`
Type string `json:"type"`
KindID string `json:"kind_id"`
IPAddress string `json:"ip_address"`
DetailLink string `json:"detail_link"`
Size string `json:"size"`
NetworkName string `json:"network_name"`
AssignDate string `json:"assign_date"`
ReturnDate string `json:"return_date"`
OrgName string `json:"org_name"`
Ryakusho string `json:"ryakusho"`
RecepNo string `json:"recep_no"`
DeliNo string `json:"deli_no"`
Type string `json:"type"`
KindID string `json:"kind_id"`
InfoDetail InfoDetail `json:"info_detail"`
}

type SearchIPv6 struct {
IPAddress string `json:"ip_address"`
SizeStart string `json:"size_start"`
SizeEnd string `json:"size_end"`
NetworkName string `json:"network_name"`
RegStart string `json:"reg_start"`
RegEnd string `json:"reg_end"`
ReturnStart string `json:"return_start"`
ReturnEnd string `json:"return_end"`
Org string `json:"org"`
Ryakusho string `json:"ryakusho"`
RecepNo string `json:"recep_no"`
DeliNo string `json:"deli_no"`
IsAllocate bool `json:"is_allocate"` // 割振
IsAssignInfra bool `json:"is_assign_infra"` //インフラ割当
IsAssignUser bool `json:"is_assign_user"` //ユーザ割当
IsSubAllocate bool `json:"is_sub_allocate"` //再割当
}

type InfoIPv6 struct {
IPAddress string `json:"ip_address"`
DetailLink string `json:"detail_link"`
NetworkName string `json:"network_name"`
AssignDate string `json:"assign_date"`
ReturnDate string `json:"return_date"`
OrgName string `json:"org_name"`
Ryakusho string `json:"ryakusho"`
RecepNo string `json:"recep_no"`
DeliNo string `json:"deli_no"`
KindID string `json:"kind_id"`
IPAddress string `json:"ip_address"`
DetailLink string `json:"detail_link"`
NetworkName string `json:"network_name"`
AssignDate string `json:"assign_date"`
ReturnDate string `json:"return_date"`
OrgName string `json:"org_name"`
Ryakusho string `json:"ryakusho"`
RecepNo string `json:"recep_no"`
DeliNo string `json:"deli_no"`
KindID string `json:"kind_id"`
InfoDetail InfoDetail `json:"info_detail"`
}

type RequestInfo struct {
Expand Down
Loading

0 comments on commit bd7a2ff

Please sign in to comment.