88
99use OCA \GDataVaas \Service \TagService ;
1010use OCA \GDataVaas \Service \VerdictService ;
11+ use OCA \GDataVaas \Settings \VaasOperator ;
1112use OCP \AppFramework \Controller ;
13+ use OCP \AppFramework \Http \Attribute \AuthorizedAdminSetting ;
1214use OCP \AppFramework \Http \JSONResponse ;
1315use OCP \DB \Exception ;
1416use OCP \IAppConfig ;
@@ -40,29 +42,17 @@ public function __construct(
4042 $ this ->verdictService = $ verdictService ;
4143 }
4244
43- public function setconfig (
45+ public function setAdminSettings (
4446 $ username ,
4547 $ password ,
4648 $ clientId ,
4749 $ clientSecret ,
4850 $ authMethod ,
49- $ quarantineFolder ,
50- $ scanOnlyThis ,
51- $ doNotScanThis ,
52- $ notifyMails ,
5351 $ maxScanSize ,
5452 $ timeout ,
5553 bool $ cache ,
5654 bool $ hashlookup ,
5755 ): JSONResponse {
58- if (!empty ($ notifyMails )) {
59- $ mails = explode (', ' , preg_replace ('/\s+/ ' , '' , $ notifyMails ));
60- foreach ($ mails as $ mail ) {
61- if ($ this ->mailer ->validateMailAddress ($ mail ) === false ) {
62- return new JSONResponse (['status ' => 'error ' , 'message ' => 'Invalid email address: ' . $ mail ]);
63- }
64- }
65- }
6656 if ((int )$ maxScanSize < 1 ) {
6757 return new JSONResponse (['status ' => 'error ' , 'message ' => 'Invalid max scan size: ' . $ maxScanSize ]);
6858 }
@@ -74,37 +64,59 @@ public function setconfig(
7464 $ this ->config ->setValueString ($ this ->appName , 'clientId ' , $ clientId );
7565 $ this ->config ->setValueString ($ this ->appName , 'clientSecret ' , $ clientSecret );
7666 $ this ->config ->setValueString ($ this ->appName , 'authMethod ' , $ authMethod );
77- $ this ->config ->setValueString ($ this ->appName , 'quarantineFolder ' , $ quarantineFolder );
78- $ this ->config ->setValueString ($ this ->appName , 'scanOnlyThis ' , $ scanOnlyThis );
79- $ this ->config ->setValueString ($ this ->appName , 'doNotScanThis ' , $ doNotScanThis );
80- $ this ->config ->setValueString ($ this ->appName , 'notifyMails ' , $ notifyMails );
8167 $ this ->config ->setValueInt ($ this ->appName , 'maxScanSizeInMB ' , (int )$ maxScanSize );
8268 $ this ->config ->setValueInt ($ this ->appName , 'timeout ' , (int )$ timeout );
8369 $ this ->config ->setValueBool ($ this ->appName , 'cache ' , $ cache );
8470 $ this ->config ->setValueBool ($ this ->appName , 'hashlookup ' , $ hashlookup );
8571 return new JSONResponse (['status ' => 'success ' ]);
8672 }
8773
88- public function setadvancedconfig ($ tokenEndpoint , $ vaasUrl ): JSONResponse {
74+ public function setAdvancedConfig ($ tokenEndpoint , $ vaasUrl ): JSONResponse {
8975 $ this ->config ->setValueString ($ this ->appName , 'tokenEndpoint ' , $ tokenEndpoint );
9076 $ this ->config ->setValueString ($ this ->appName , 'vaasUrl ' , $ vaasUrl );
9177 return new JSONResponse (['status ' => 'success ' ]);
9278 }
9379
80+ #[AuthorizedAdminSetting(settings: VaasOperator::class)]
81+ public function setOperatorSettings (
82+ $ quarantineFolder ,
83+ $ scanOnlyThis ,
84+ $ doNotScanThis ,
85+ $ notifyMails ,
86+ ): JSONResponse {
87+ if (!empty ($ notifyMails )) {
88+ $ mails = explode (', ' , preg_replace ('/\s+/ ' , '' , $ notifyMails ));
89+ foreach ($ mails as $ mail ) {
90+ if ($ this ->mailer ->validateMailAddress ($ mail ) === false ) {
91+ return new JSONResponse (['status ' => 'error ' , 'message ' => 'Invalid email address: ' . $ mail ]);
92+ }
93+ }
94+ }
95+ $ this ->config ->setValueString ($ this ->appName , 'quarantineFolder ' , $ quarantineFolder );
96+ $ this ->config ->setValueString ($ this ->appName , 'scanOnlyThis ' , $ scanOnlyThis );
97+ $ this ->config ->setValueString ($ this ->appName , 'doNotScanThis ' , $ doNotScanThis );
98+ $ this ->config ->setValueString ($ this ->appName , 'notifyMails ' , $ notifyMails );
99+ return new JSONResponse (['status ' => 'success ' ]);
100+ }
101+
102+ #[AuthorizedAdminSetting(settings: VaasOperator::class)]
94103 public function setAutoScan (bool $ autoScanFiles ): JSONResponse {
95104 $ this ->config ->setValueBool ($ this ->appName , 'autoScanFiles ' , $ autoScanFiles );
96105 return new JSONResponse (['status ' => 'success ' ]);
97106 }
98107
108+ #[AuthorizedAdminSetting(settings: VaasOperator::class)]
99109 public function getAutoScan (): JSONResponse {
100110 return new JSONResponse (['status ' => $ this ->config ->getValueBool ($ this ->appName , 'autoScanFiles ' )]);
101111 }
102112
113+ #[AuthorizedAdminSetting(settings: VaasOperator::class)]
103114 public function setPrefixMalicious (bool $ prefixMalicious ): JSONResponse {
104115 $ this ->config ->setValueBool ($ this ->appName , 'prefixMalicious ' , $ prefixMalicious );
105116 return new JSONResponse (['status ' => 'success ' ]);
106117 }
107118
119+ #[AuthorizedAdminSetting(settings: VaasOperator::class)]
108120 public function getPrefixMalicious (): JSONResponse {
109121 return new JSONResponse (['status ' => $ this ->config ->getValueBool ($ this ->appName , 'prefixMalicious ' )]);
110122 }
@@ -113,11 +125,13 @@ public function getAuthMethod(): JSONResponse {
113125 return new JSONResponse (['status ' => $ this ->config ->getValueString ($ this ->appName , 'authMethod ' )]);
114126 }
115127
128+ #[AuthorizedAdminSetting(settings: VaasOperator::class)]
116129 public function setDisableUnscannedTag (bool $ disableUnscannedTag ): JSONResponse {
117130 $ this ->config ->setValueBool ($ this ->appName , 'disableUnscannedTag ' , $ disableUnscannedTag );
118131 return new JSONResponse (['status ' => 'success ' ]);
119132 }
120133
134+ #[AuthorizedAdminSetting(settings: VaasOperator::class)]
121135 public function getDisableUnscannedTag (): JSONResponse {
122136 return new JSONResponse (['status ' => $ this ->config ->getValueBool ($ this ->appName , 'disableUnscannedTag ' )]);
123137 }
@@ -127,6 +141,7 @@ public function resetAllTags(): JSONResponse {
127141 return new JSONResponse (['status ' => 'success ' ]);
128142 }
129143
144+ #[AuthorizedAdminSetting(settings: VaasOperator::class)]
130145 public function getCounters (): JSONResponse {
131146 try {
132147 $ filesCount = $ this ->tagService ->getScannedFilesCount ();
@@ -143,12 +158,14 @@ public function getCounters(): JSONResponse {
143158 ]);
144159 }
145160
161+ #[AuthorizedAdminSetting(settings: VaasOperator::class)]
146162 public function getSendMailOnVirusUpload (): JSONResponse {
147163 return new JSONResponse (
148164 ['status ' => $ this ->config ->getValueBool ($ this ->appName , 'sendMailOnVirusUpload ' )]
149165 );
150166 }
151167
168+ #[AuthorizedAdminSetting(settings: VaasOperator::class)]
152169 public function setSendMailOnVirusUpload (bool $ sendMailOnVirusUpload ): JSONResponse {
153170 $ this ->config ->setValueBool ($ this ->appName , 'sendMailOnVirusUpload ' , $ sendMailOnVirusUpload );
154171 return new JSONResponse (['status ' => 'success ' ]);
0 commit comments