aboutsummaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorDavid Siegfried <david.siegfried@uni-vechta.de>2022-08-23 14:04:34 +0000
committerDavid Siegfried <david.siegfried@uni-vechta.de>2022-08-23 14:04:34 +0000
commit5f171dd74b373121a7132125016e56f2f45be44c (patch)
treed47dd86c7488db774c8495910193e11fcd7d604f /cli
parentb79328e273c94d724ed8fd577d38688cd4bc45a4 (diff)
migrate cli-script twillo-generate-private-keys to symfony-commands, closes #1477
Closes #1477 Merge request studip/studip!922
Diffstat (limited to 'cli')
-rw-r--r--cli/Commands/Twillo/PrivateKeys.php62
-rwxr-xr-xcli/studip1
-rw-r--r--cli/twillo_generate_keys.php36
3 files changed, 63 insertions, 36 deletions
diff --git a/cli/Commands/Twillo/PrivateKeys.php b/cli/Commands/Twillo/PrivateKeys.php
new file mode 100644
index 0000000..830df9f
--- /dev/null
+++ b/cli/Commands/Twillo/PrivateKeys.php
@@ -0,0 +1,62 @@
+<?php
+namespace Studip\Cli\Commands\Twillo;
+
+use Config;
+use EduSharingHelper;
+use Studip\Cli\Commands\AbstractCommand;
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Console\Style\SymfonyStyle;
+
+final class PrivateKeys extends AbstractCommand
+{
+ protected static $defaultName = 'twillo:generate-private-keys';
+
+
+ protected function configure(): void
+ {
+ $this->setDescription('Generate private keys for twillo');
+ $this->setHelp('This command will generate the private keys for the twillo-integration');
+ }
+
+ public function execute(InputInterface $input, OutputInterface $output)
+ {
+ $io = new SymfonyStyle($input, $output);
+ $appId = str_replace(' ', '-', Config::get()->UNI_NAME_CLEAN);
+ $privateKey = $GLOBALS['ABSOLUTE_PATH_STUDIP'] . '/config/twillo-private.key';
+ $properties = $GLOBALS['ABSOLUTE_PATH_STUDIP'] . '/config/twillo.properties.xml';
+
+ if (!file_exists($privateKey)) {
+ $key = EduSharingHelper::generateKeyPair();
+ $success = file_put_contents(
+ $properties,
+ EduSharingHelper::generateEduAppXMLData($appId, $key['publickey'])
+ );
+
+ if ($success !== false) {
+ file_put_contents(
+ $privateKey,
+ $key['privatekey']
+ );
+ Config::get()->store('OERCAMPUS_TWILLO_APPID', $appId);
+
+ $io->success('"Wrote config/twillo.properties.xml file. Next steps');
+ $io->note([
+ 'Send the file config/twillo.properties.xml to the twillo.de administrators support.twillo@tib.eu . If they ask you to change the app-ID, you can do this in the system at Admin -> System -> Configuration by editing the config value OERCAMPUS_TWILLO_APPID.',
+ 'Leave the config/twillo-private.key file as it is in the config folder. This file is important for the API to work',
+ 'You need to either have or create a datafield for users which contains the DFN-AAI-ID of a person. Without this ID in the datafield a user cannot upload to twillo.de due to technical restrictions',
+ 'Copy the datafield_id of this datafield (you find this in the DB-table datafields). In Stud.IP go to Admin -> System -> Configuration and edit the config value OERCAMPUS_TWILLO_DFNAAIID_DATAFIELD. What you inserted, should look like 6a9ee3ca3685d2551698a3dc6f0f0eff',
+ 'Once the twillo.de adminstrators received your file and registered your Stud.IP, you can enable the connection to twillo: Go to Admin -> System -> Configuration and edit the config value OERCAMPUS_ENABLE_TWILLO and switch it on.',
+ 'There you go. From now on all your users with a given DFN-AAI-ID should be able to upload their OERs to twillo.de.'
+ ]);
+ } else {
+ $io->error('No permission to write into folder config. Cannot save private and public keys');
+ }
+ } else {
+ $io->error('Private key already exists. Remove it or be happy that it is there.');
+ }
+ return Command::SUCCESS;
+ }
+}
diff --git a/cli/studip b/cli/studip
index 2b24238..36fe5f5 100755
--- a/cli/studip
+++ b/cli/studip
@@ -54,6 +54,7 @@ $commands = [
Commands\Plugins\I18N\I18NCompile::class,
Commands\Resources\UpdateBookingIntervals::class,
Commands\SORM\DescribeModels::class,
+ Commands\Twillo\PrivateKeys::class,
Commands\Users\UserDelete::class,
Commands\Users\UserDelete::class,
];
diff --git a/cli/twillo_generate_keys.php b/cli/twillo_generate_keys.php
deleted file mode 100644
index 0d1f5d1..0000000
--- a/cli/twillo_generate_keys.php
+++ /dev/null
@@ -1,36 +0,0 @@
-#!/usr/bin/env php
-<?php
-require_once 'studip_cli_env.inc.php';
-
-$app_id = str_replace(" ", "-", Config::get()->UNI_NAME_CLEAN);
-
-$privatekey = @file_get_contents('../config/twillo-private.key');
-
-if (!$privatekey) {
- $key = EduSharingHelper::generateKeyPair();
- $success = file_put_contents(
- '../config/twillo.properties.xml',
- EduSharingHelper::generateEduAppXMLData($app_id, $key['publickey'])
- );
- if ($success !== false) {
- file_put_contents(
- '../config/twillo-private.key',
- $key['privatekey']
- );
- Config::get()->store('OERCAMPUS_TWILLO_APPID', $app_id);
- echo "Wrote config/twillo.properties.xml file. Next steps:
-
-- Send the file config/twillo.properties.xml to the twillo.de administrators support.twillo@tib.eu . If they ask you to change the app-ID, you can do this in the system at Admin -> System -> Configuration by editing the config value OERCAMPUS_TWILLO_APPID.
-- Leave the config/twillo-private.key file as it is in the config folder. This file is important for the API to work.
-- You need to either have or create a datafield for users which contains the DFN-AAI-ID of a person. Without this ID in the datafield a user cannot upload to twillo.de due to technical restrictions.
-- Copy the datafield_id of this datafield (you find this in the DB-table datafields). In Stud.IP go to Admin -> System -> Configuration and edit the config value OERCAMPUS_TWILLO_DFNAAIID_DATAFIELD. What you inserted, should look like 6a9ee3ca3685d2551698a3dc6f0f0eff.
-- Once the twillo.de adminstrators received your file and registered your Stud.IP, you can enable the connection to twillo: Go to Admin -> System -> Configuration and edit the config value OERCAMPUS_ENABLE_TWILLO and switch it on.
-
-There you go. From now on all your users with a given DFN-AAI-ID should be able to upload their OERs to twillo.de.
-";
- } else {
- echo "No permission to write into folder config. Cannot save private and public keys.\n";
- }
-} else {
- echo "Private key already exists. Remove it or be happy that it is there.\n";
-}