@@ -117,8 +117,8 @@ |
||
117 | 117 | if ($aChunk !== $bChunk) { |
118 | 118 | // test first character (character comparison, not number comparison) |
119 | 119 | if ($aChunk[0] >= '0' && $aChunk[0] <= '9' && $bChunk[0] >= '0' && $bChunk[0] <= '9') { |
120 | - $aNum = (int)$aChunk; |
|
121 | - $bNum = (int)$bChunk; |
|
120 | + $aNum = (int) $aChunk; |
|
121 | + $bNum = (int) $bChunk; |
|
122 | 122 | return $aNum - $bNum; |
123 | 123 | } |
124 | 124 | return self::getCollator()->compare($aChunk, $bChunk); |
@@ -31,112 +31,112 @@ |
||
31 | 31 | use OCP\ILogger; |
32 | 32 | |
33 | 33 | class NaturalSort { |
34 | - private static $instance; |
|
35 | - private $collator; |
|
36 | - private $cache = []; |
|
34 | + private static $instance; |
|
35 | + private $collator; |
|
36 | + private $cache = []; |
|
37 | 37 | |
38 | - /** |
|
39 | - * Instantiate a new \OC\NaturalSort instance. |
|
40 | - * @param object $injectedCollator |
|
41 | - */ |
|
42 | - public function __construct($injectedCollator = null) { |
|
43 | - // inject an instance of \Collator('en_US') to force using the php5-intl Collator |
|
44 | - // or inject an instance of \OC\NaturalSort_DefaultCollator to force using Owncloud's default collator |
|
45 | - if (isset($injectedCollator)) { |
|
46 | - $this->collator = $injectedCollator; |
|
47 | - \OCP\Util::writeLog('core', 'forced use of '.get_class($injectedCollator), ILogger::DEBUG); |
|
48 | - } |
|
49 | - } |
|
38 | + /** |
|
39 | + * Instantiate a new \OC\NaturalSort instance. |
|
40 | + * @param object $injectedCollator |
|
41 | + */ |
|
42 | + public function __construct($injectedCollator = null) { |
|
43 | + // inject an instance of \Collator('en_US') to force using the php5-intl Collator |
|
44 | + // or inject an instance of \OC\NaturalSort_DefaultCollator to force using Owncloud's default collator |
|
45 | + if (isset($injectedCollator)) { |
|
46 | + $this->collator = $injectedCollator; |
|
47 | + \OCP\Util::writeLog('core', 'forced use of '.get_class($injectedCollator), ILogger::DEBUG); |
|
48 | + } |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Split the given string in chunks of numbers and strings |
|
53 | - * @param string $t string |
|
54 | - * @return array of strings and number chunks |
|
55 | - */ |
|
56 | - private function naturalSortChunkify($t) { |
|
57 | - // Adapted and ported to PHP from |
|
58 | - // http://my.opera.com/GreyWyvern/blog/show.dml/1671288 |
|
59 | - if (isset($this->cache[$t])) { |
|
60 | - return $this->cache[$t]; |
|
61 | - } |
|
62 | - $tz = []; |
|
63 | - $x = 0; |
|
64 | - $y = -1; |
|
65 | - $n = null; |
|
51 | + /** |
|
52 | + * Split the given string in chunks of numbers and strings |
|
53 | + * @param string $t string |
|
54 | + * @return array of strings and number chunks |
|
55 | + */ |
|
56 | + private function naturalSortChunkify($t) { |
|
57 | + // Adapted and ported to PHP from |
|
58 | + // http://my.opera.com/GreyWyvern/blog/show.dml/1671288 |
|
59 | + if (isset($this->cache[$t])) { |
|
60 | + return $this->cache[$t]; |
|
61 | + } |
|
62 | + $tz = []; |
|
63 | + $x = 0; |
|
64 | + $y = -1; |
|
65 | + $n = null; |
|
66 | 66 | |
67 | - while (isset($t[$x])) { |
|
68 | - $c = $t[$x]; |
|
69 | - // only include the dot in strings |
|
70 | - $m = ((!$n && $c === '.') || ($c >= '0' && $c <= '9')); |
|
71 | - if ($m !== $n) { |
|
72 | - // next chunk |
|
73 | - $y++; |
|
74 | - $tz[$y] = ''; |
|
75 | - $n = $m; |
|
76 | - } |
|
77 | - $tz[$y] .= $c; |
|
78 | - $x++; |
|
79 | - } |
|
80 | - $this->cache[$t] = $tz; |
|
81 | - return $tz; |
|
82 | - } |
|
67 | + while (isset($t[$x])) { |
|
68 | + $c = $t[$x]; |
|
69 | + // only include the dot in strings |
|
70 | + $m = ((!$n && $c === '.') || ($c >= '0' && $c <= '9')); |
|
71 | + if ($m !== $n) { |
|
72 | + // next chunk |
|
73 | + $y++; |
|
74 | + $tz[$y] = ''; |
|
75 | + $n = $m; |
|
76 | + } |
|
77 | + $tz[$y] .= $c; |
|
78 | + $x++; |
|
79 | + } |
|
80 | + $this->cache[$t] = $tz; |
|
81 | + return $tz; |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * Returns the string collator |
|
86 | - * @return \Collator string collator |
|
87 | - */ |
|
88 | - private function getCollator() { |
|
89 | - if (!isset($this->collator)) { |
|
90 | - // looks like the default is en_US_POSIX which yields wrong sorting with |
|
91 | - // German umlauts, so using en_US instead |
|
92 | - if (class_exists('Collator')) { |
|
93 | - $this->collator = new \Collator('en_US'); |
|
94 | - } else { |
|
95 | - $this->collator = new \OC\NaturalSort_DefaultCollator(); |
|
96 | - } |
|
97 | - } |
|
98 | - return $this->collator; |
|
99 | - } |
|
84 | + /** |
|
85 | + * Returns the string collator |
|
86 | + * @return \Collator string collator |
|
87 | + */ |
|
88 | + private function getCollator() { |
|
89 | + if (!isset($this->collator)) { |
|
90 | + // looks like the default is en_US_POSIX which yields wrong sorting with |
|
91 | + // German umlauts, so using en_US instead |
|
92 | + if (class_exists('Collator')) { |
|
93 | + $this->collator = new \Collator('en_US'); |
|
94 | + } else { |
|
95 | + $this->collator = new \OC\NaturalSort_DefaultCollator(); |
|
96 | + } |
|
97 | + } |
|
98 | + return $this->collator; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Compare two strings to provide a natural sort |
|
103 | - * @param string $a first string to compare |
|
104 | - * @param string $b second string to compare |
|
105 | - * @return int -1 if $b comes before $a, 1 if $a comes before $b |
|
106 | - * or 0 if the strings are identical |
|
107 | - */ |
|
108 | - public function compare($a, $b) { |
|
109 | - // Needed because PHP doesn't sort correctly when numbers are enclosed in |
|
110 | - // parenthesis, even with NUMERIC_COLLATION enabled. |
|
111 | - // For example it gave ["test (2).txt", "test.txt"] |
|
112 | - // instead of ["test.txt", "test (2).txt"] |
|
113 | - $aa = self::naturalSortChunkify($a); |
|
114 | - $bb = self::naturalSortChunkify($b); |
|
101 | + /** |
|
102 | + * Compare two strings to provide a natural sort |
|
103 | + * @param string $a first string to compare |
|
104 | + * @param string $b second string to compare |
|
105 | + * @return int -1 if $b comes before $a, 1 if $a comes before $b |
|
106 | + * or 0 if the strings are identical |
|
107 | + */ |
|
108 | + public function compare($a, $b) { |
|
109 | + // Needed because PHP doesn't sort correctly when numbers are enclosed in |
|
110 | + // parenthesis, even with NUMERIC_COLLATION enabled. |
|
111 | + // For example it gave ["test (2).txt", "test.txt"] |
|
112 | + // instead of ["test.txt", "test (2).txt"] |
|
113 | + $aa = self::naturalSortChunkify($a); |
|
114 | + $bb = self::naturalSortChunkify($b); |
|
115 | 115 | |
116 | - for ($x = 0; isset($aa[$x]) && isset($bb[$x]); $x++) { |
|
117 | - $aChunk = $aa[$x]; |
|
118 | - $bChunk = $bb[$x]; |
|
119 | - if ($aChunk !== $bChunk) { |
|
120 | - // test first character (character comparison, not number comparison) |
|
121 | - if ($aChunk[0] >= '0' && $aChunk[0] <= '9' && $bChunk[0] >= '0' && $bChunk[0] <= '9') { |
|
122 | - $aNum = (int)$aChunk; |
|
123 | - $bNum = (int)$bChunk; |
|
124 | - return $aNum - $bNum; |
|
125 | - } |
|
126 | - return self::getCollator()->compare($aChunk, $bChunk); |
|
127 | - } |
|
128 | - } |
|
129 | - return count($aa) - count($bb); |
|
130 | - } |
|
116 | + for ($x = 0; isset($aa[$x]) && isset($bb[$x]); $x++) { |
|
117 | + $aChunk = $aa[$x]; |
|
118 | + $bChunk = $bb[$x]; |
|
119 | + if ($aChunk !== $bChunk) { |
|
120 | + // test first character (character comparison, not number comparison) |
|
121 | + if ($aChunk[0] >= '0' && $aChunk[0] <= '9' && $bChunk[0] >= '0' && $bChunk[0] <= '9') { |
|
122 | + $aNum = (int)$aChunk; |
|
123 | + $bNum = (int)$bChunk; |
|
124 | + return $aNum - $bNum; |
|
125 | + } |
|
126 | + return self::getCollator()->compare($aChunk, $bChunk); |
|
127 | + } |
|
128 | + } |
|
129 | + return count($aa) - count($bb); |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * Returns a singleton |
|
134 | - * @return \OC\NaturalSort instance |
|
135 | - */ |
|
136 | - public static function getInstance() { |
|
137 | - if (!isset(self::$instance)) { |
|
138 | - self::$instance = new \OC\NaturalSort(); |
|
139 | - } |
|
140 | - return self::$instance; |
|
141 | - } |
|
132 | + /** |
|
133 | + * Returns a singleton |
|
134 | + * @return \OC\NaturalSort instance |
|
135 | + */ |
|
136 | + public static function getInstance() { |
|
137 | + if (!isset(self::$instance)) { |
|
138 | + self::$instance = new \OC\NaturalSort(); |
|
139 | + } |
|
140 | + return self::$instance; |
|
141 | + } |
|
142 | 142 | } |
@@ -20,4 +20,4 @@ |
||
20 | 20 | * |
21 | 21 | */ |
22 | 22 | |
23 | -require_once __DIR__ . '/v1.php'; |
|
23 | +require_once __DIR__.'/v1.php'; |
@@ -26,8 +26,8 @@ |
||
26 | 26 | $server = \OC::$server; |
27 | 27 | |
28 | 28 | $controller = new \OC\OCS\Provider( |
29 | - 'ocs_provider', |
|
30 | - $server->getRequest(), |
|
31 | - $server->getAppManager() |
|
29 | + 'ocs_provider', |
|
30 | + $server->getRequest(), |
|
31 | + $server->getAppManager() |
|
32 | 32 | ); |
33 | 33 | echo $controller->buildProviderList()->render(); |
@@ -19,7 +19,7 @@ |
||
19 | 19 | * |
20 | 20 | */ |
21 | 21 | |
22 | -require_once __DIR__ . '/../lib/base.php'; |
|
22 | +require_once __DIR__.'/../lib/base.php'; |
|
23 | 23 | |
24 | 24 | header('Content-Type: application/json'); |
25 | 25 |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | - /** @var array $_ */ |
|
3 | - /** @var \OCP\IL10N $l */ |
|
2 | + /** @var array $_ */ |
|
3 | + /** @var \OCP\IL10N $l */ |
|
4 | 4 | |
5 | 5 | style('core', ['styles', 'header']); |
6 | 6 | ?> |
@@ -34,28 +34,28 @@ |
||
34 | 34 | |
35 | 35 | class RemoveCertificate extends Base { |
36 | 36 | |
37 | - /** @var ICertificateManager */ |
|
38 | - protected $certificateManager; |
|
39 | - |
|
40 | - public function __construct(ICertificateManager $certificateManager) { |
|
41 | - $this->certificateManager = $certificateManager; |
|
42 | - parent::__construct(); |
|
43 | - } |
|
44 | - |
|
45 | - protected function configure() { |
|
46 | - $this |
|
47 | - ->setName('security:certificates:remove') |
|
48 | - ->setDescription('remove trusted certificate') |
|
49 | - ->addArgument( |
|
50 | - 'name', |
|
51 | - InputArgument::REQUIRED, |
|
52 | - 'the file name of the certificate to remove' |
|
53 | - ); |
|
54 | - } |
|
55 | - |
|
56 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
57 | - $name = $input->getArgument('name'); |
|
58 | - |
|
59 | - $this->certificateManager->removeCertificate($name); |
|
60 | - } |
|
37 | + /** @var ICertificateManager */ |
|
38 | + protected $certificateManager; |
|
39 | + |
|
40 | + public function __construct(ICertificateManager $certificateManager) { |
|
41 | + $this->certificateManager = $certificateManager; |
|
42 | + parent::__construct(); |
|
43 | + } |
|
44 | + |
|
45 | + protected function configure() { |
|
46 | + $this |
|
47 | + ->setName('security:certificates:remove') |
|
48 | + ->setDescription('remove trusted certificate') |
|
49 | + ->addArgument( |
|
50 | + 'name', |
|
51 | + InputArgument::REQUIRED, |
|
52 | + 'the file name of the certificate to remove' |
|
53 | + ); |
|
54 | + } |
|
55 | + |
|
56 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
57 | + $name = $input->getArgument('name'); |
|
58 | + |
|
59 | + $this->certificateManager->removeCertificate($name); |
|
60 | + } |
|
61 | 61 | } |
@@ -34,64 +34,64 @@ |
||
34 | 34 | |
35 | 35 | class ListCertificates extends Base { |
36 | 36 | |
37 | - /** @var ICertificateManager */ |
|
38 | - protected $certificateManager; |
|
39 | - /** @var IL10N */ |
|
40 | - protected $l; |
|
37 | + /** @var ICertificateManager */ |
|
38 | + protected $certificateManager; |
|
39 | + /** @var IL10N */ |
|
40 | + protected $l; |
|
41 | 41 | |
42 | - public function __construct(ICertificateManager $certificateManager, IL10N $l) { |
|
43 | - $this->certificateManager = $certificateManager; |
|
44 | - $this->l = $l; |
|
45 | - parent::__construct(); |
|
46 | - } |
|
42 | + public function __construct(ICertificateManager $certificateManager, IL10N $l) { |
|
43 | + $this->certificateManager = $certificateManager; |
|
44 | + $this->l = $l; |
|
45 | + parent::__construct(); |
|
46 | + } |
|
47 | 47 | |
48 | - protected function configure() { |
|
49 | - $this |
|
50 | - ->setName('security:certificates') |
|
51 | - ->setDescription('list trusted certificates'); |
|
52 | - parent::configure(); |
|
53 | - } |
|
48 | + protected function configure() { |
|
49 | + $this |
|
50 | + ->setName('security:certificates') |
|
51 | + ->setDescription('list trusted certificates'); |
|
52 | + parent::configure(); |
|
53 | + } |
|
54 | 54 | |
55 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
56 | - $outputType = $input->getOption('output'); |
|
57 | - if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) { |
|
58 | - $certificates = array_map(function (ICertificate $certificate) { |
|
59 | - return [ |
|
60 | - 'name' => $certificate->getName(), |
|
61 | - 'common_name' => $certificate->getCommonName(), |
|
62 | - 'organization' => $certificate->getOrganization(), |
|
63 | - 'expire' => $certificate->getExpireDate()->format(\DateTime::ATOM), |
|
64 | - 'issuer' => $certificate->getIssuerName(), |
|
65 | - 'issuer_organization' => $certificate->getIssuerOrganization(), |
|
66 | - 'issue_date' => $certificate->getIssueDate()->format(\DateTime::ATOM) |
|
67 | - ]; |
|
68 | - }, $this->certificateManager->listCertificates()); |
|
69 | - if ($outputType === self::OUTPUT_FORMAT_JSON) { |
|
70 | - $output->writeln(json_encode(array_values($certificates))); |
|
71 | - } else { |
|
72 | - $output->writeln(json_encode(array_values($certificates), JSON_PRETTY_PRINT)); |
|
73 | - } |
|
74 | - } else { |
|
75 | - $table = new Table($output); |
|
76 | - $table->setHeaders([ |
|
77 | - 'File Name', |
|
78 | - 'Common Name', |
|
79 | - 'Organization', |
|
80 | - 'Valid Until', |
|
81 | - 'Issued By' |
|
82 | - ]); |
|
55 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
56 | + $outputType = $input->getOption('output'); |
|
57 | + if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) { |
|
58 | + $certificates = array_map(function (ICertificate $certificate) { |
|
59 | + return [ |
|
60 | + 'name' => $certificate->getName(), |
|
61 | + 'common_name' => $certificate->getCommonName(), |
|
62 | + 'organization' => $certificate->getOrganization(), |
|
63 | + 'expire' => $certificate->getExpireDate()->format(\DateTime::ATOM), |
|
64 | + 'issuer' => $certificate->getIssuerName(), |
|
65 | + 'issuer_organization' => $certificate->getIssuerOrganization(), |
|
66 | + 'issue_date' => $certificate->getIssueDate()->format(\DateTime::ATOM) |
|
67 | + ]; |
|
68 | + }, $this->certificateManager->listCertificates()); |
|
69 | + if ($outputType === self::OUTPUT_FORMAT_JSON) { |
|
70 | + $output->writeln(json_encode(array_values($certificates))); |
|
71 | + } else { |
|
72 | + $output->writeln(json_encode(array_values($certificates), JSON_PRETTY_PRINT)); |
|
73 | + } |
|
74 | + } else { |
|
75 | + $table = new Table($output); |
|
76 | + $table->setHeaders([ |
|
77 | + 'File Name', |
|
78 | + 'Common Name', |
|
79 | + 'Organization', |
|
80 | + 'Valid Until', |
|
81 | + 'Issued By' |
|
82 | + ]); |
|
83 | 83 | |
84 | - $rows = array_map(function (ICertificate $certificate) { |
|
85 | - return [ |
|
86 | - $certificate->getName(), |
|
87 | - $certificate->getCommonName(), |
|
88 | - $certificate->getOrganization(), |
|
89 | - $this->l->l('date', $certificate->getExpireDate()), |
|
90 | - $certificate->getIssuerName() |
|
91 | - ]; |
|
92 | - }, $this->certificateManager->listCertificates()); |
|
93 | - $table->setRows($rows); |
|
94 | - $table->render(); |
|
95 | - } |
|
96 | - } |
|
84 | + $rows = array_map(function (ICertificate $certificate) { |
|
85 | + return [ |
|
86 | + $certificate->getName(), |
|
87 | + $certificate->getCommonName(), |
|
88 | + $certificate->getOrganization(), |
|
89 | + $this->l->l('date', $certificate->getExpireDate()), |
|
90 | + $certificate->getIssuerName() |
|
91 | + ]; |
|
92 | + }, $this->certificateManager->listCertificates()); |
|
93 | + $table->setRows($rows); |
|
94 | + $table->render(); |
|
95 | + } |
|
96 | + } |
|
97 | 97 | } |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | protected function execute(InputInterface $input, OutputInterface $output) { |
56 | 56 | $outputType = $input->getOption('output'); |
57 | 57 | if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) { |
58 | - $certificates = array_map(function (ICertificate $certificate) { |
|
58 | + $certificates = array_map(function(ICertificate $certificate) { |
|
59 | 59 | return [ |
60 | 60 | 'name' => $certificate->getName(), |
61 | 61 | 'common_name' => $certificate->getCommonName(), |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | 'Issued By' |
82 | 82 | ]); |
83 | 83 | |
84 | - $rows = array_map(function (ICertificate $certificate) { |
|
84 | + $rows = array_map(function(ICertificate $certificate) { |
|
85 | 85 | return [ |
86 | 86 | $certificate->getName(), |
87 | 87 | $certificate->getCommonName(), |
@@ -33,36 +33,36 @@ |
||
33 | 33 | |
34 | 34 | class ImportCertificate extends Base { |
35 | 35 | |
36 | - /** @var ICertificateManager */ |
|
37 | - protected $certificateManager; |
|
36 | + /** @var ICertificateManager */ |
|
37 | + protected $certificateManager; |
|
38 | 38 | |
39 | - public function __construct(ICertificateManager $certificateManager) { |
|
40 | - $this->certificateManager = $certificateManager; |
|
41 | - parent::__construct(); |
|
42 | - } |
|
39 | + public function __construct(ICertificateManager $certificateManager) { |
|
40 | + $this->certificateManager = $certificateManager; |
|
41 | + parent::__construct(); |
|
42 | + } |
|
43 | 43 | |
44 | - protected function configure() { |
|
45 | - $this |
|
46 | - ->setName('security:certificates:import') |
|
47 | - ->setDescription('import trusted certificate') |
|
48 | - ->addArgument( |
|
49 | - 'path', |
|
50 | - InputArgument::REQUIRED, |
|
51 | - 'path to the certificate to import' |
|
52 | - ); |
|
53 | - } |
|
44 | + protected function configure() { |
|
45 | + $this |
|
46 | + ->setName('security:certificates:import') |
|
47 | + ->setDescription('import trusted certificate') |
|
48 | + ->addArgument( |
|
49 | + 'path', |
|
50 | + InputArgument::REQUIRED, |
|
51 | + 'path to the certificate to import' |
|
52 | + ); |
|
53 | + } |
|
54 | 54 | |
55 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
56 | - $path = $input->getArgument('path'); |
|
55 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
56 | + $path = $input->getArgument('path'); |
|
57 | 57 | |
58 | - if (!file_exists($path)) { |
|
59 | - $output->writeln('<error>certificate not found</error>'); |
|
60 | - return; |
|
61 | - } |
|
58 | + if (!file_exists($path)) { |
|
59 | + $output->writeln('<error>certificate not found</error>'); |
|
60 | + return; |
|
61 | + } |
|
62 | 62 | |
63 | - $certData = file_get_contents($path); |
|
64 | - $name = basename($path); |
|
63 | + $certData = file_get_contents($path); |
|
64 | + $name = basename($path); |
|
65 | 65 | |
66 | - $this->certificateManager->addCertificate($certData, $name); |
|
67 | - } |
|
66 | + $this->certificateManager->addCertificate($certData, $name); |
|
67 | + } |
|
68 | 68 | } |
@@ -117,12 +117,12 @@ |
||
117 | 117 | try { |
118 | 118 | $success = $user->setPassword($password); |
119 | 119 | } catch (\Exception $e) { |
120 | - $output->writeln('<error>' . $e->getMessage() . '</error>'); |
|
120 | + $output->writeln('<error>'.$e->getMessage().'</error>'); |
|
121 | 121 | return 1; |
122 | 122 | } |
123 | 123 | |
124 | 124 | if ($success) { |
125 | - $output->writeln("<info>Successfully reset password for " . $username . "</info>"); |
|
125 | + $output->writeln("<info>Successfully reset password for ".$username."</info>"); |
|
126 | 126 | } else { |
127 | 127 | $output->writeln("<error>Error while resetting password!</error>"); |
128 | 128 | return 1; |
@@ -39,98 +39,98 @@ |
||
39 | 39 | |
40 | 40 | class ResetPassword extends Command { |
41 | 41 | |
42 | - /** @var IUserManager */ |
|
43 | - protected $userManager; |
|
44 | - |
|
45 | - public function __construct(IUserManager $userManager) { |
|
46 | - $this->userManager = $userManager; |
|
47 | - parent::__construct(); |
|
48 | - } |
|
49 | - |
|
50 | - protected function configure() { |
|
51 | - $this |
|
52 | - ->setName('user:resetpassword') |
|
53 | - ->setDescription('Resets the password of the named user') |
|
54 | - ->addArgument( |
|
55 | - 'user', |
|
56 | - InputArgument::REQUIRED, |
|
57 | - 'Username to reset password' |
|
58 | - ) |
|
59 | - ->addOption( |
|
60 | - 'password-from-env', |
|
61 | - null, |
|
62 | - InputOption::VALUE_NONE, |
|
63 | - 'read password from environment variable OC_PASS' |
|
64 | - ) |
|
65 | - ; |
|
66 | - } |
|
67 | - |
|
68 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
69 | - $username = $input->getArgument('user'); |
|
70 | - |
|
71 | - /** @var $user \OCP\IUser */ |
|
72 | - $user = $this->userManager->get($username); |
|
73 | - if (is_null($user)) { |
|
74 | - $output->writeln('<error>User does not exist</error>'); |
|
75 | - return 1; |
|
76 | - } |
|
77 | - |
|
78 | - if ($input->getOption('password-from-env')) { |
|
79 | - $password = getenv('OC_PASS'); |
|
80 | - if (!$password) { |
|
81 | - $output->writeln('<error>--password-from-env given, but OC_PASS is empty!</error>'); |
|
82 | - return 1; |
|
83 | - } |
|
84 | - } elseif ($input->isInteractive()) { |
|
85 | - /** @var QuestionHelper $helper */ |
|
86 | - $helper = $this->getHelper('question'); |
|
87 | - |
|
88 | - if (\OCP\App::isEnabled('encryption')) { |
|
89 | - $output->writeln( |
|
90 | - '<error>Warning: Resetting the password when using encryption will result in data loss!</error>' |
|
91 | - ); |
|
92 | - |
|
93 | - $question = new ConfirmationQuestion('Do you want to continue?'); |
|
94 | - if (!$helper->ask($input, $output, $question)) { |
|
95 | - return 1; |
|
96 | - } |
|
97 | - } |
|
98 | - |
|
99 | - $question = new Question('Enter a new password: '); |
|
100 | - $question->setHidden(true); |
|
101 | - $password = $helper->ask($input, $output, $question); |
|
102 | - |
|
103 | - if ($password === null) { |
|
104 | - $output->writeln("<error>Password cannot be empty!</error>"); |
|
105 | - return 1; |
|
106 | - } |
|
107 | - |
|
108 | - $question = new Question('Confirm the new password: '); |
|
109 | - $question->setHidden(true); |
|
110 | - $confirm = $helper->ask($input, $output, $question); |
|
111 | - |
|
112 | - if ($password !== $confirm) { |
|
113 | - $output->writeln("<error>Passwords did not match!</error>"); |
|
114 | - return 1; |
|
115 | - } |
|
116 | - } else { |
|
117 | - $output->writeln("<error>Interactive input or --password-from-env is needed for entering a new password!</error>"); |
|
118 | - return 1; |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - try { |
|
123 | - $success = $user->setPassword($password); |
|
124 | - } catch (\Exception $e) { |
|
125 | - $output->writeln('<error>' . $e->getMessage() . '</error>'); |
|
126 | - return 1; |
|
127 | - } |
|
128 | - |
|
129 | - if ($success) { |
|
130 | - $output->writeln("<info>Successfully reset password for " . $username . "</info>"); |
|
131 | - } else { |
|
132 | - $output->writeln("<error>Error while resetting password!</error>"); |
|
133 | - return 1; |
|
134 | - } |
|
135 | - } |
|
42 | + /** @var IUserManager */ |
|
43 | + protected $userManager; |
|
44 | + |
|
45 | + public function __construct(IUserManager $userManager) { |
|
46 | + $this->userManager = $userManager; |
|
47 | + parent::__construct(); |
|
48 | + } |
|
49 | + |
|
50 | + protected function configure() { |
|
51 | + $this |
|
52 | + ->setName('user:resetpassword') |
|
53 | + ->setDescription('Resets the password of the named user') |
|
54 | + ->addArgument( |
|
55 | + 'user', |
|
56 | + InputArgument::REQUIRED, |
|
57 | + 'Username to reset password' |
|
58 | + ) |
|
59 | + ->addOption( |
|
60 | + 'password-from-env', |
|
61 | + null, |
|
62 | + InputOption::VALUE_NONE, |
|
63 | + 'read password from environment variable OC_PASS' |
|
64 | + ) |
|
65 | + ; |
|
66 | + } |
|
67 | + |
|
68 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
69 | + $username = $input->getArgument('user'); |
|
70 | + |
|
71 | + /** @var $user \OCP\IUser */ |
|
72 | + $user = $this->userManager->get($username); |
|
73 | + if (is_null($user)) { |
|
74 | + $output->writeln('<error>User does not exist</error>'); |
|
75 | + return 1; |
|
76 | + } |
|
77 | + |
|
78 | + if ($input->getOption('password-from-env')) { |
|
79 | + $password = getenv('OC_PASS'); |
|
80 | + if (!$password) { |
|
81 | + $output->writeln('<error>--password-from-env given, but OC_PASS is empty!</error>'); |
|
82 | + return 1; |
|
83 | + } |
|
84 | + } elseif ($input->isInteractive()) { |
|
85 | + /** @var QuestionHelper $helper */ |
|
86 | + $helper = $this->getHelper('question'); |
|
87 | + |
|
88 | + if (\OCP\App::isEnabled('encryption')) { |
|
89 | + $output->writeln( |
|
90 | + '<error>Warning: Resetting the password when using encryption will result in data loss!</error>' |
|
91 | + ); |
|
92 | + |
|
93 | + $question = new ConfirmationQuestion('Do you want to continue?'); |
|
94 | + if (!$helper->ask($input, $output, $question)) { |
|
95 | + return 1; |
|
96 | + } |
|
97 | + } |
|
98 | + |
|
99 | + $question = new Question('Enter a new password: '); |
|
100 | + $question->setHidden(true); |
|
101 | + $password = $helper->ask($input, $output, $question); |
|
102 | + |
|
103 | + if ($password === null) { |
|
104 | + $output->writeln("<error>Password cannot be empty!</error>"); |
|
105 | + return 1; |
|
106 | + } |
|
107 | + |
|
108 | + $question = new Question('Confirm the new password: '); |
|
109 | + $question->setHidden(true); |
|
110 | + $confirm = $helper->ask($input, $output, $question); |
|
111 | + |
|
112 | + if ($password !== $confirm) { |
|
113 | + $output->writeln("<error>Passwords did not match!</error>"); |
|
114 | + return 1; |
|
115 | + } |
|
116 | + } else { |
|
117 | + $output->writeln("<error>Interactive input or --password-from-env is needed for entering a new password!</error>"); |
|
118 | + return 1; |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + try { |
|
123 | + $success = $user->setPassword($password); |
|
124 | + } catch (\Exception $e) { |
|
125 | + $output->writeln('<error>' . $e->getMessage() . '</error>'); |
|
126 | + return 1; |
|
127 | + } |
|
128 | + |
|
129 | + if ($success) { |
|
130 | + $output->writeln("<info>Successfully reset password for " . $username . "</info>"); |
|
131 | + } else { |
|
132 | + $output->writeln("<error>Error while resetting password!</error>"); |
|
133 | + return 1; |
|
134 | + } |
|
135 | + } |
|
136 | 136 | } |
@@ -32,127 +32,127 @@ |
||
32 | 32 | use Symfony\Component\Console\Output\OutputInterface; |
33 | 33 | |
34 | 34 | class ListConfigs extends Base { |
35 | - protected $defaultOutputFormat = self::OUTPUT_FORMAT_JSON_PRETTY; |
|
36 | - |
|
37 | - /** * @var SystemConfig */ |
|
38 | - protected $systemConfig; |
|
39 | - |
|
40 | - /** @var IAppConfig */ |
|
41 | - protected $appConfig; |
|
42 | - |
|
43 | - /** |
|
44 | - * @param SystemConfig $systemConfig |
|
45 | - * @param IAppConfig $appConfig |
|
46 | - */ |
|
47 | - public function __construct(SystemConfig $systemConfig, IAppConfig $appConfig) { |
|
48 | - parent::__construct(); |
|
49 | - $this->systemConfig = $systemConfig; |
|
50 | - $this->appConfig = $appConfig; |
|
51 | - } |
|
52 | - |
|
53 | - protected function configure() { |
|
54 | - parent::configure(); |
|
55 | - |
|
56 | - $this |
|
57 | - ->setName('config:list') |
|
58 | - ->setDescription('List all configs') |
|
59 | - ->addArgument( |
|
60 | - 'app', |
|
61 | - InputArgument::OPTIONAL, |
|
62 | - 'Name of the app ("system" to get the config.php values, "all" for all apps and system)', |
|
63 | - 'all' |
|
64 | - ) |
|
65 | - ->addOption( |
|
66 | - 'private', |
|
67 | - null, |
|
68 | - InputOption::VALUE_NONE, |
|
69 | - 'Use this option when you want to include sensitive configs like passwords, salts, ...' |
|
70 | - ) |
|
71 | - ; |
|
72 | - } |
|
73 | - |
|
74 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
75 | - $app = $input->getArgument('app'); |
|
76 | - $noSensitiveValues = !$input->getOption('private'); |
|
77 | - |
|
78 | - switch ($app) { |
|
79 | - case 'system': |
|
80 | - $configs = [ |
|
81 | - 'system' => $this->getSystemConfigs($noSensitiveValues), |
|
82 | - ]; |
|
83 | - break; |
|
84 | - |
|
85 | - case 'all': |
|
86 | - $apps = $this->appConfig->getApps(); |
|
87 | - $configs = [ |
|
88 | - 'system' => $this->getSystemConfigs($noSensitiveValues), |
|
89 | - 'apps' => [], |
|
90 | - ]; |
|
91 | - foreach ($apps as $appName) { |
|
92 | - $configs['apps'][$appName] = $this->getAppConfigs($appName, $noSensitiveValues); |
|
93 | - } |
|
94 | - break; |
|
95 | - |
|
96 | - default: |
|
97 | - $configs = [ |
|
98 | - 'apps' => [ |
|
99 | - $app => $this->getAppConfigs($app, $noSensitiveValues), |
|
100 | - ], |
|
101 | - ]; |
|
102 | - } |
|
103 | - |
|
104 | - $this->writeArrayInOutputFormat($input, $output, $configs); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Get the system configs |
|
109 | - * |
|
110 | - * @param bool $noSensitiveValues |
|
111 | - * @return array |
|
112 | - */ |
|
113 | - protected function getSystemConfigs($noSensitiveValues) { |
|
114 | - $keys = $this->systemConfig->getKeys(); |
|
115 | - |
|
116 | - $configs = []; |
|
117 | - foreach ($keys as $key) { |
|
118 | - if ($noSensitiveValues) { |
|
119 | - $value = $this->systemConfig->getFilteredValue($key, serialize(null)); |
|
120 | - } else { |
|
121 | - $value = $this->systemConfig->getValue($key, serialize(null)); |
|
122 | - } |
|
123 | - |
|
124 | - if ($value !== 'N;') { |
|
125 | - $configs[$key] = $value; |
|
126 | - } |
|
127 | - } |
|
128 | - |
|
129 | - return $configs; |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Get the app configs |
|
134 | - * |
|
135 | - * @param string $app |
|
136 | - * @param bool $noSensitiveValues |
|
137 | - * @return array |
|
138 | - */ |
|
139 | - protected function getAppConfigs($app, $noSensitiveValues) { |
|
140 | - if ($noSensitiveValues) { |
|
141 | - return $this->appConfig->getFilteredValues($app, false); |
|
142 | - } else { |
|
143 | - return $this->appConfig->getValues($app, false); |
|
144 | - } |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * @param string $argumentName |
|
149 | - * @param CompletionContext $context |
|
150 | - * @return string[] |
|
151 | - */ |
|
152 | - public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
153 | - if ($argumentName === 'app') { |
|
154 | - return array_merge(['all', 'system'], \OC_App::getAllApps()); |
|
155 | - } |
|
156 | - return []; |
|
157 | - } |
|
35 | + protected $defaultOutputFormat = self::OUTPUT_FORMAT_JSON_PRETTY; |
|
36 | + |
|
37 | + /** * @var SystemConfig */ |
|
38 | + protected $systemConfig; |
|
39 | + |
|
40 | + /** @var IAppConfig */ |
|
41 | + protected $appConfig; |
|
42 | + |
|
43 | + /** |
|
44 | + * @param SystemConfig $systemConfig |
|
45 | + * @param IAppConfig $appConfig |
|
46 | + */ |
|
47 | + public function __construct(SystemConfig $systemConfig, IAppConfig $appConfig) { |
|
48 | + parent::__construct(); |
|
49 | + $this->systemConfig = $systemConfig; |
|
50 | + $this->appConfig = $appConfig; |
|
51 | + } |
|
52 | + |
|
53 | + protected function configure() { |
|
54 | + parent::configure(); |
|
55 | + |
|
56 | + $this |
|
57 | + ->setName('config:list') |
|
58 | + ->setDescription('List all configs') |
|
59 | + ->addArgument( |
|
60 | + 'app', |
|
61 | + InputArgument::OPTIONAL, |
|
62 | + 'Name of the app ("system" to get the config.php values, "all" for all apps and system)', |
|
63 | + 'all' |
|
64 | + ) |
|
65 | + ->addOption( |
|
66 | + 'private', |
|
67 | + null, |
|
68 | + InputOption::VALUE_NONE, |
|
69 | + 'Use this option when you want to include sensitive configs like passwords, salts, ...' |
|
70 | + ) |
|
71 | + ; |
|
72 | + } |
|
73 | + |
|
74 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
75 | + $app = $input->getArgument('app'); |
|
76 | + $noSensitiveValues = !$input->getOption('private'); |
|
77 | + |
|
78 | + switch ($app) { |
|
79 | + case 'system': |
|
80 | + $configs = [ |
|
81 | + 'system' => $this->getSystemConfigs($noSensitiveValues), |
|
82 | + ]; |
|
83 | + break; |
|
84 | + |
|
85 | + case 'all': |
|
86 | + $apps = $this->appConfig->getApps(); |
|
87 | + $configs = [ |
|
88 | + 'system' => $this->getSystemConfigs($noSensitiveValues), |
|
89 | + 'apps' => [], |
|
90 | + ]; |
|
91 | + foreach ($apps as $appName) { |
|
92 | + $configs['apps'][$appName] = $this->getAppConfigs($appName, $noSensitiveValues); |
|
93 | + } |
|
94 | + break; |
|
95 | + |
|
96 | + default: |
|
97 | + $configs = [ |
|
98 | + 'apps' => [ |
|
99 | + $app => $this->getAppConfigs($app, $noSensitiveValues), |
|
100 | + ], |
|
101 | + ]; |
|
102 | + } |
|
103 | + |
|
104 | + $this->writeArrayInOutputFormat($input, $output, $configs); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Get the system configs |
|
109 | + * |
|
110 | + * @param bool $noSensitiveValues |
|
111 | + * @return array |
|
112 | + */ |
|
113 | + protected function getSystemConfigs($noSensitiveValues) { |
|
114 | + $keys = $this->systemConfig->getKeys(); |
|
115 | + |
|
116 | + $configs = []; |
|
117 | + foreach ($keys as $key) { |
|
118 | + if ($noSensitiveValues) { |
|
119 | + $value = $this->systemConfig->getFilteredValue($key, serialize(null)); |
|
120 | + } else { |
|
121 | + $value = $this->systemConfig->getValue($key, serialize(null)); |
|
122 | + } |
|
123 | + |
|
124 | + if ($value !== 'N;') { |
|
125 | + $configs[$key] = $value; |
|
126 | + } |
|
127 | + } |
|
128 | + |
|
129 | + return $configs; |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Get the app configs |
|
134 | + * |
|
135 | + * @param string $app |
|
136 | + * @param bool $noSensitiveValues |
|
137 | + * @return array |
|
138 | + */ |
|
139 | + protected function getAppConfigs($app, $noSensitiveValues) { |
|
140 | + if ($noSensitiveValues) { |
|
141 | + return $this->appConfig->getFilteredValues($app, false); |
|
142 | + } else { |
|
143 | + return $this->appConfig->getValues($app, false); |
|
144 | + } |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * @param string $argumentName |
|
149 | + * @param CompletionContext $context |
|
150 | + * @return string[] |
|
151 | + */ |
|
152 | + public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
153 | + if ($argumentName === 'app') { |
|
154 | + return array_merge(['all', 'system'], \OC_App::getAllApps()); |
|
155 | + } |
|
156 | + return []; |
|
157 | + } |
|
158 | 158 | } |