@@ -126,6 +126,8 @@ type IWebsiteService interface {
126126 ChangeDatabase (req request.ChangeDatabase ) error
127127
128128 OperateCrossSiteAccess (req request.CrossSiteAccessOp ) error
129+
130+ ExecComposer (req request.ExecComposerReq ) error
129131}
130132
131133func NewIWebsiteService () IWebsiteService {
@@ -466,15 +468,15 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error)
466468 website .Protocol = constant .ProtocolHTTPS
467469 website .WebsiteSSLID = create .WebsiteSSLID
468470 appSSLReq := request.WebsiteHTTPSOp {
469- WebsiteID : website .ID ,
470- Enable : true ,
471- WebsiteSSLID : websiteModel .ID ,
472- Type : "existed" ,
473- HttpConfig : "HTTPToHTTPS" ,
474- SSLProtocol : []string {"TLSv1.3" , "TLSv1.2" },
475- Algorithm : "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:!aNULL:!eNULL:!EXPORT:!DSS:!DES:!RC4:!3DES:!MD5:!PSK:!KRB5:!SRP:!CAMELLIA:!SEED" ,
476- Hsts : true ,
477- HstsIncludeSubDomains : true ,
471+ WebsiteID : website .ID ,
472+ Enable : true ,
473+ WebsiteSSLID : websiteModel .ID ,
474+ Type : "existed" ,
475+ HttpConfig : "HTTPToHTTPS" ,
476+ SSLProtocol : []string {"TLSv1.3" , "TLSv1.2" },
477+ Algorithm : "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:!aNULL:!eNULL:!EXPORT:!DSS:!DES:!RC4:!3DES:!MD5:!PSK:!KRB5:!SRP:!CAMELLIA:!SEED" ,
478+ Hsts : true ,
479+ HstsIncludeSubDomains : true ,
478480 }
479481 if err = applySSL (website , * websiteModel , appSSLReq ); err != nil {
480482 return err
@@ -960,7 +962,6 @@ func (w WebsiteService) GetWebsiteHTTPS(websiteId uint) (response.WebsiteHTTPS,
960962 if p .Name == "add_header" && len (p .Params ) > 0 {
961963 if p .Params [0 ] == "Strict-Transport-Security" {
962964 res .Hsts = true
963- //增加HSTS下子域名检查逻辑
964965 if len (p .Params ) > 1 {
965966 hstsValue := p .Params [1 ]
966967 if strings .Contains (hstsValue , "includeSubDomains" ) {
@@ -3319,3 +3320,50 @@ func (w WebsiteService) OperateCrossSiteAccess(req request.CrossSiteAccessOp) er
33193320 }
33203321 return nil
33213322}
3323+
3324+ func (w WebsiteService ) ExecComposer (req request.ExecComposerReq ) error {
3325+ website , err := websiteRepo .GetFirst (repo .WithByID (req .WebsiteID ))
3326+ if err != nil {
3327+ return err
3328+ }
3329+ sitePath := GetSitePath (website , SiteDir )
3330+ if ! strings .Contains (req .Dir , sitePath ) {
3331+ return buserr .New ("ErrWebsiteDir" )
3332+ }
3333+ if ! files .NewFileOp ().Stat (path .Join (req .Dir , "composer.json" )) {
3334+ return buserr .New ("ErrComposerFileNotFound" )
3335+ }
3336+ if task .CheckResourceTaskIsExecuting (task .TaskExec , req .Command , website .ID ) {
3337+ return buserr .New ("ErrInstallExtension" )
3338+ }
3339+ runtime , err := runtimeRepo .GetFirst (context .Background (), repo .WithByID (website .RuntimeID ))
3340+ if err != nil {
3341+ return err
3342+ }
3343+ var command string
3344+ if req .Command != "custom" {
3345+ command = fmt .Sprintf ("%s %s" , req .Command , req .ExtCommand )
3346+ } else {
3347+ command = req .ExtCommand
3348+ }
3349+ resourceName := fmt .Sprintf ("composer %s" , command )
3350+ composerTask , err := task .NewTaskWithOps (resourceName , task .TaskExec , req .Command , req .TaskID , website .ID )
3351+ if err != nil {
3352+ return err
3353+ }
3354+ cmdMgr := cmd .NewCommandMgr (cmd .WithTask (* composerTask ), cmd .WithTimeout (20 * time .Minute ))
3355+ siteDir , _ := settingRepo .Get (settingRepo .WithByKey ("WEBSITE_DIR" ))
3356+ execDir := strings .ReplaceAll (req .Dir , siteDir .Value , "/www" )
3357+ composerTask .AddSubTask ("" , func (t * task.Task ) error {
3358+ cmdStr := fmt .Sprintf ("docker exec -u %s %s sh -c 'composer config -g repo.packagist composer %s && composer %s --working-dir=%s'" , req .User , runtime .ContainerName , req .Mirror , command , execDir )
3359+ err = cmdMgr .RunBashCf (cmdStr )
3360+ if err != nil {
3361+ return err
3362+ }
3363+ return nil
3364+ }, nil )
3365+ go func () {
3366+ _ = composerTask .Execute ()
3367+ }()
3368+ return nil
3369+ }
0 commit comments