You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ajaxcontroller.php 1.8KB

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