@@ -345,10 +345,16 @@ func (w WebsiteSSLService) Update(update request.WebsiteSSLUpdate) error {
345345}
346346
347347func (w WebsiteSSLService ) Upload (req request.WebsiteSSLUpload ) error {
348- newSSL := & model.WebsiteSSL {
348+ websiteSSL := & model.WebsiteSSL {
349349 Provider : constant .Manual ,
350350 }
351-
351+ var err error
352+ if req .SSLID > 0 {
353+ websiteSSL , err = websiteSSLRepo .GetFirst (commonRepo .WithByID (req .SSLID ))
354+ if err != nil {
355+ return err
356+ }
357+ }
352358 if req .Type == "local" {
353359 fileOp := files .NewFileOp ()
354360 if ! fileOp .Stat (req .PrivateKeyPath ) {
@@ -360,48 +366,48 @@ func (w WebsiteSSLService) Upload(req request.WebsiteSSLUpload) error {
360366 if content , err := fileOp .GetContent (req .PrivateKeyPath ); err != nil {
361367 return err
362368 } else {
363- newSSL .PrivateKey = string (content )
369+ websiteSSL .PrivateKey = string (content )
364370 }
365371 if content , err := fileOp .GetContent (req .CertificatePath ); err != nil {
366372 return err
367373 } else {
368- newSSL .Pem = string (content )
374+ websiteSSL .Pem = string (content )
369375 }
370376 } else {
371- newSSL .PrivateKey = req .PrivateKey
372- newSSL .Pem = req .Certificate
377+ websiteSSL .PrivateKey = req .PrivateKey
378+ websiteSSL .Pem = req .Certificate
373379 }
374380
375- privateKeyCertBlock , _ := pem .Decode ([]byte (newSSL .PrivateKey ))
381+ privateKeyCertBlock , _ := pem .Decode ([]byte (websiteSSL .PrivateKey ))
376382 if privateKeyCertBlock == nil {
377383 return buserr .New ("ErrSSLKeyFormat" )
378384 }
379385
380- certBlock , _ := pem .Decode ([]byte (newSSL .Pem ))
386+ certBlock , _ := pem .Decode ([]byte (websiteSSL .Pem ))
381387 if certBlock == nil {
382388 return buserr .New ("ErrSSLCertificateFormat" )
383389 }
384390 cert , err := x509 .ParseCertificate (certBlock .Bytes )
385391 if err != nil {
386392 return err
387393 }
388- newSSL .ExpireDate = cert .NotAfter
389- newSSL .StartDate = cert .NotBefore
390- newSSL .Type = cert .Issuer .CommonName
394+ websiteSSL .ExpireDate = cert .NotAfter
395+ websiteSSL .StartDate = cert .NotBefore
396+ websiteSSL .Type = cert .Issuer .CommonName
391397 if len (cert .Issuer .Organization ) > 0 {
392- newSSL .Organization = cert .Issuer .Organization [0 ]
398+ websiteSSL .Organization = cert .Issuer .Organization [0 ]
393399 } else {
394- newSSL .Organization = cert .Issuer .CommonName
400+ websiteSSL .Organization = cert .Issuer .CommonName
395401 }
396402
397403 var domains []string
398404 if len (cert .DNSNames ) > 0 {
399- newSSL .PrimaryDomain = cert .DNSNames [0 ]
405+ websiteSSL .PrimaryDomain = cert .DNSNames [0 ]
400406 domains = cert .DNSNames [1 :]
401407 }
402408 if len (cert .IPAddresses ) > 0 {
403- if newSSL .PrimaryDomain == "" {
404- newSSL .PrimaryDomain = cert .IPAddresses [0 ].String ()
409+ if websiteSSL .PrimaryDomain == "" {
410+ websiteSSL .PrimaryDomain = cert .IPAddresses [0 ].String ()
405411 for _ , ip := range cert .IPAddresses [1 :] {
406412 domains = append (domains , ip .String ())
407413 }
@@ -411,9 +417,12 @@ func (w WebsiteSSLService) Upload(req request.WebsiteSSLUpload) error {
411417 }
412418 }
413419 }
414- newSSL .Domains = strings .Join (domains , "," )
420+ websiteSSL .Domains = strings .Join (domains , "," )
415421
416- return websiteSSLRepo .Create (context .Background (), newSSL )
422+ if websiteSSL .ID > 0 {
423+ return websiteSSLRepo .Save (websiteSSL )
424+ }
425+ return websiteSSLRepo .Create (context .Background (), websiteSSL )
417426}
418427
419428func (w WebsiteSSLService ) SyncForRestart () error {
0 commit comments