Skip to content

Commit

Permalink
Merge pull request #8 from smarthouse/UpdateUnixTimeToDateTime
Browse files Browse the repository at this point in the history
Update unix time to date time
  • Loading branch information
Siggi81 authored Feb 22, 2019
2 parents 69f439d + 76e8540 commit 608688e
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 19 deletions.
8 changes: 6 additions & 2 deletions apis/crawler/crawler.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,12 @@ func openURL(myURL string) (TableRow, error) {
results.LastURL = hooks.Truncate(myURL, 200)
results.LastStatusCode = int16(resp.StatusCode)
urlStr, _ := url.Parse(myURL)
myIP, _ := net.LookupIP(urlStr.Hostname())
results.IP = hooks.Truncate(myIP[0].String(), 30)
myIP, err := net.LookupIP(urlStr.Hostname())
if err != nil {
hooks.LogIfNeeded(manager.Logger, fmt.Sprintf("No IP found for %v: %v", results.LastURL , err), manager.LogLevel, hooks.LogError)
} else {
results.IP = hooks.Truncate(myIP[0].String(), 30)
}
rCodes = append(rCodes, fmt.Sprintf("%d", resp.StatusCode))

if resp.StatusCode/100 == 3 {
Expand Down
5 changes: 3 additions & 2 deletions apis/ssllabs/Certificates.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ CREATE TABLE [CertificatesV10](
[Issues] [smallint] NULL,
[KeyStrength] [smallint] NULL,
[DebianInsecure] [bit] NULL,
[NotBefore] [bigint] NULL,
[NotAfter] [bigint] NULL,
[NextThumbprint] [nchar](40) NULL,
[ValidFrom] [Datetime] NULL,
[ValidTo] [DateTime] NULL,
[AltNames] nvarchar(MAX) NULL,
CONSTRAINT [PK_CertificatesV10] PRIMARY KEY CLUSTERED
(
[Thumbprint] ASC
Expand Down
4 changes: 2 additions & 2 deletions apis/ssllabs/SSLLabs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ CREATE TABLE [SSLLabsV10](
[DomainReachable] [tinyint] NOT NULL,
[ScanStatus] [tinyint] NOT NULL,
[IP] [nvarchar](30) NULL,
[StartTime] [bigint] NULL,
[TestTime] [bigint] NULL,
[StartTime] [DateTime] NULL,
[TestTime] [DateTime] NULL,
[Grade] [nvarchar](2) NULL,
[GradeTrustIgnored] [nvarchar](2) NULL,
[FutureGrade] [nvarchar](2) NULL,
Expand Down
15 changes: 8 additions & 7 deletions apis/ssllabs/ssllabsscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ func (e LabsErrorResponse) Error() string {

type TableRow struct {
IP string
StartTime int64
TestTime int64
StartTime string
TestTime string
Grade string
GradeTrustIgnored string
FutureGrade string
Expand Down Expand Up @@ -907,15 +907,16 @@ func makeCertificateRows(report *LabsReport) []*hooks.CertificateRow {
row.Issues = int16(cert.Issues)
row.KeyStrength = int16(cert.KeyStrength)
row.DebianInsecure = cert.KeyKnownDebianInsecure
row.NotAfter = cert.NotAfter
row.NotBefore = cert.NotBefore
row.ValidTo = time.Unix(cert.NotAfter/1000, 0).Format("2006-01-02 15:04:05")
row.ValidFrom = time.Unix(cert.NotBefore/1000, 0).Format("2006-01-02 15:04:05")
row.AltNames = strings.Join(cert.AltNames, ", ")
if i+1 < chainLength {
row.NextThumbprint = sql.NullString{
String: hooks.Truncate(report.Certs[i+1].Sha1Hash, 40),
Valid: true,
}
}

res = append([]*hooks.CertificateRow{row}, res...)
}
return res
Expand All @@ -932,8 +933,8 @@ func makeSSLLabsRow(report *LabsReport) *TableRow {
details := endpoint.Details
row := &TableRow{}
row.IP = hooks.Truncate(endpoint.IpAddress, 15)
row.StartTime = report.StartTime
row.TestTime = report.TestTime
row.StartTime = time.Unix(report.StartTime/1000, 0).Format("2006-01-02 15:04:05")
row.TestTime = time.Unix(report.TestTime/1000, 0).Format("2006-01-02 15:04:05")
row.Grade = hooks.Truncate(endpoint.Grade, 2)
row.GradeTrustIgnored = hooks.Truncate(endpoint.GradeTrustIgnored, 2)
row.FutureGrade = hooks.Truncate(endpoint.FutureGrade, 2)
Expand Down
8 changes: 4 additions & 4 deletions backend/sqlWriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,22 +386,22 @@ func SaveCertificates(rows []*hooks.CertificateRow, table string) error {
IF NOT EXISTS (SELECT * FROM %[1]v WHERE Thumbprint = ?)
BEGIN
INSERT INTO %[1]v
(Thumbprint, SerialNumber, Subject, Issuer, SigAlg, RevocationStatus, Issues, KeyStrength, DebianInsecure, NotBefore, NotAfter, NextThumbprint)
(Thumbprint, SerialNumber, Subject, Issuer, SigAlg, RevocationStatus, Issues, KeyStrength, DebianInsecure, NextThumbprint, ValidFrom, ValidTo, AltNames)
VALUES
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
END
ELSE
BEGIN
UPDATE %[1]v
SET Issues = ?
SET Issues = ?, ValidFrom = ?, ValidTo = ?, AltNames = ?
WHERE Thumbprint = ?
END
`
var err error
_, err = globalDatabase.ExecContext(ctx,
fmt.Sprintf(query, table),
row.Thumbprint, row.Thumbprint, row.SerialNumber, row.Subject, row.Issuer, row.SigAlg, row.RevocationStatus, row.Issues,
row.KeyStrength, row.DebianInsecure, row.NotBefore, row.NotAfter, row.NextThumbprint, row.Issues, row.Thumbprint)
row.KeyStrength, row.DebianInsecure, row.NextThumbprint, row.ValidFrom, row.ValidTo, row.AltNames, row.Issues, row.ValidFrom, row.ValidTo, row.AltNames, row.Thumbprint)
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions hooks/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,10 @@ type CertificateRow struct {
Issues int16
KeyStrength int16
DebianInsecure bool
NotBefore int64
NotAfter int64
NextThumbprint sql.NullString
ValidFrom string
ValidTo string
AltNames string
}

type DomainsRowMetaInfo struct {
Expand Down

0 comments on commit 608688e

Please sign in to comment.