protected function doRun()
 {
     $cryptTool = CryptTool::getInstance();
     $sendersThreemaId = $this->getArgumentThreemaId(self::argThreemaId);
     $id = $this->getArgumentThreemaId(self::argFrom);
     $secret = $this->getArgument(self::argSecret);
     $privateKey = $this->getArgumentPrivateKey(self::argPrivateKey);
     $nonce = $cryptTool->hex2bin($this->getArgument(self::argNonce));
     $messageId = $this->getArgument(self::argMessageId);
     $outputFolder = $this->getArgument(self::argOutputFolder);
     $box = $cryptTool->hex2bin($this->readStdIn());
     Common::required($box, $id, $secret, $privateKey, $nonce);
     $settings = new ConnectionSettings($id, $secret);
     $connector = new Connection($settings, $this->publicKeyStore);
     $helper = new E2EHelper($privateKey, $connector);
     $message = $helper->receiveMessage($sendersThreemaId, $messageId, $box, $nonce, $outputFolder);
     if (null === $message) {
         Common::e('invalid message');
         return;
     }
     if ($message->isSuccess()) {
         Common::l($message->getMessageId() . ' - ' . $message->getThreemaMessage());
         foreach ($message->getFiles() as $fileName => $filePath) {
             Common::l('   received file ' . $fileName . ' in ' . $filePath);
         }
     } else {
         Common::e('Error: ' . implode("\n", $message->getErrors()));
     }
 }
 protected function doRun()
 {
     $id = $this->getArgumentThreemaId(self::argThreemaId);
     $from = $this->getArgumentThreemaId(self::argFrom);
     $secret = $this->getArgument(self::argSecret);
     Common::required($id, $from, $secret);
     //define connection settings
     $settings = new ConnectionSettings($from, $secret);
     //create a connection
     $connector = new Connection($settings, $this->publicKeyStore);
     $result = $connector->fetchPublicKey($id);
     if ($result->isSuccess()) {
         Common::l(Common::convertPublicKey($result->getPublicKey()));
     } else {
         Common::e($result->getErrorMessage());
     }
 }
Example #3
0
 protected function doRun()
 {
     $from = $this->getArgumentThreemaId(self::argFrom);
     $secret = $this->getArgument(self::argSecret);
     Common::required($from, $secret);
     //define connection settings
     $settings = new ConnectionSettings($from, $secret);
     //create a connection
     $connector = new Connection($settings, $this->publicKeyStore);
     $result = $connector->credits();
     Common::required($result);
     if ($result->isSuccess()) {
         Common::l("remaining credits: " . $result->getCredits());
     } else {
         Common::e($result->getErrorMessage());
     }
 }
 protected function doRun()
 {
     $phoneNo = $this->getArgument(self::argPhoneNo);
     $from = $this->getArgumentThreemaId(self::argFrom);
     $secret = $this->getArgument(self::argSecret);
     Common::required($phoneNo, $from, $secret);
     //define connection settings
     $settings = new ConnectionSettings($from, $secret);
     //create a connection
     $connector = new Connection($settings, $this->publicKeyStore);
     $result = $connector->keyLookupByPhoneNumber($phoneNo);
     Common::required($result);
     if ($result->isSuccess()) {
         Common::l($result->getId());
     } else {
         Common::e($result->getErrorMessage());
     }
 }
 protected function doRun()
 {
     $threemaId = $this->getArgument(self::argThreemaId);
     $from = $this->getArgument(self::argFrom);
     $secret = $this->getArgument(self::argSecret);
     $privateKey = $this->getArgumentPrivateKey(self::argPrivateKey);
     $path = $this->getArgumentFile(self::argImageFile);
     Common::required($threemaId, $from, $secret, $privateKey, $path);
     $settings = new ConnectionSettings($from, $secret);
     $connector = new Connection($settings, $this->publicKeyStore);
     $helper = new E2EHelper($privateKey, $connector);
     $result = $helper->sendImageMessage($threemaId, $path);
     if ($result->isSuccess()) {
         Common::l('Message ID: ' . $result->getMessageId());
     } else {
         Common::e('Error: ' . $result->getErrorMessage());
     }
 }
 protected function doRun()
 {
     $threemaId = $this->getArgumentThreemaId(self::argThreemaId);
     $from = $this->getArgument(self::argFrom);
     $secret = $this->getArgument(self::argSecret);
     $privateKey = $this->getArgumentPrivateKey(self::argPrivateKey);
     Common::required($threemaId, $from, $secret, $privateKey);
     $message = $this->readStdIn();
     if (strlen($message) === 0) {
         throw new \InvalidArgumentException('please define a message');
     }
     $settings = new ConnectionSettings($from, $secret);
     $connector = new Connection($settings, $this->publicKeyStore);
     $helper = new E2EHelper($privateKey, $connector);
     $result = $helper->sendTextMessage($threemaId, $message);
     if ($result->isSuccess()) {
         Common::l('Message ID: ' . $result->getMessageId());
     } else {
         Common::e('Error: ' . $result->getErrorMessage());
     }
 }
 protected function doRun()
 {
     $threemaId = $this->getArgumentThreemaId(self::argThreemaId);
     $from = $this->getArgumentThreemaId(self::argFrom);
     $secret = $this->getArgument(self::argSecret);
     Common::required($threemaId, $from, $secret);
     if (strlen($threemaId) != 8) {
         throw new Exception('invalid threema id');
     }
     //define connection settings
     $settings = new ConnectionSettings($from, $secret);
     //create a connection
     $connector = new Connection($settings, $this->publicKeyStore);
     $result = $connector->keyCapability($threemaId);
     Common::required($result);
     if ($result->isSuccess()) {
         Common::l(implode("\n", $result->getCapabilities()));
     } else {
         Common::e($result->getErrorMessage());
     }
 }
Example #8
0
 public function run()
 {
     $found = null;
     $argumentLength = 0;
     //find the correct command by arguments and arguments count
     foreach ($this->commands as $data) {
         if (is_scalar($data)) {
             continue;
         }
         list($keys, $command) = $data;
         if (array_slice($this->arguments, 0, count($keys)) == $keys) {
             $argCount = count($this->arguments) - count($keys);
             /** @noinspection PhpUndefinedMethodInspection */
             if ($argCount >= $command->getRequiredArgumentCount() && $argCount <= $command->getAllArgumentsCount()) {
                 $found = $command;
                 $argumentLength = count($keys);
                 break;
             }
         }
     }
     if ($argumentLength > 0) {
         array_splice($this->arguments, 0, $argumentLength);
     }
     if (null === $found) {
         $this->help();
     } else {
         try {
             $found->run($this->arguments);
         } catch (Exception $x) {
             Common::l();
             Common::e('ERROR: ' . $x->getMessage());
             Common::e(get_class($x));
             Common::l();
         }
     }
 }