ajaxcontroller.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * @author Morris Jobke <hey@morrisjobke.de>
  4. * @author Robin McCorkell <robin@mccorkell.me.uk>
  5. * @author Ross Nicoll <jrn@jrn.me.uk>
  6. *
  7. * @copyright Copyright (c) 2016, ownCloud, Inc.
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OCA\Files_External\Controller;
  24. use OCA\Files_External\Lib\Auth\Password\GlobalAuth;
  25. use OCP\AppFramework\Controller;
  26. use OCP\IRequest;
  27. use OCP\AppFramework\Http\JSONResponse;
  28. use OCA\Files_External\Lib\Auth\PublicKey\RSA;
  29. class AjaxController extends Controller {
  30. /** @var RSA */
  31. private $rsaMechanism;
  32. /** @var GlobalAuth */
  33. private $globalAuth;
  34. public function __construct($appName, IRequest $request, RSA $rsaMechanism, GlobalAuth $globalAuth) {
  35. parent::__construct($appName, $request);
  36. $this->rsaMechanism = $rsaMechanism;
  37. $this->globalAuth = $globalAuth;
  38. }
  39. private function generateSshKeys() {
  40. $key = $this->rsaMechanism->createKey();
  41. // Replace the placeholder label with a more meaningful one
  42. $key['publicKey'] = str_replace('phpseclib-generated-key', gethostname(), $key['publickey']);
  43. return $key;
  44. }
  45. /**
  46. * Generates an SSH public/private key pair.
  47. *
  48. * @NoAdminRequired
  49. */
  50. public function getSshKeys() {
  51. $key = $this->generateSshKeys();
  52. return new JSONResponse(
  53. array('data' => array(
  54. 'private_key' => $key['privatekey'],
  55. 'public_key' => $key['publickey']
  56. ),
  57. 'status' => 'success'
  58. ));
  59. }
  60. public function saveGlobalCredentials($uid, $user, $password) {
  61. $this->globalAuth->saveAuth($uid, $user, $password);
  62. return true;
  63. }
  64. }