diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/appconfig.php | 89 | ||||
-rw-r--r-- | lib/crypt.php | 51 | ||||
-rw-r--r-- | lib/documentservice.php | 12 |
3 files changed, 93 insertions, 59 deletions
diff --git a/lib/appconfig.php b/lib/appconfig.php index c585ec8..d0a719a 100644 --- a/lib/appconfig.php +++ b/lib/appconfig.php @@ -96,6 +96,13 @@ class AppConfig { private $_defFormats = "defFormats"; /** + * The config key for the editable formats + * + * @var string + */ + private $_editFormats = "editFormats"; + + /** * The config key for the setting same tab * * @var string @@ -178,12 +185,16 @@ class AppConfig { /** * Get value from the system configuration - * + * * @param string $key - key configuration + * @param string $system - get from root or from app section * * @return string */ - public function GetSystemValue($key) { + public function GetSystemValue($key, $system = false) { + if ($system) { + return $this->config->getSystemValue($key); + } if (!empty($this->config->getSystemValue($this->appName)) && array_key_exists($key, $this->config->getSystemValue($this->appName))) { return $this->config->getSystemValue($this->appName)[$key]; @@ -346,7 +357,7 @@ class AppConfig { } /** - * Save the formats array with default action + * Save an array of formats with default action * * @param array $formats - formats with status */ @@ -358,11 +369,11 @@ class AppConfig { } /** - * Get the formats array with default action + * Get an array of formats with default action * * @return array */ - public function GetDefaultFormats() { + private function GetDefaultFormats() { $value = $this->config->getAppValue($this->appName, $this->_defFormats, ""); if (empty($value)) { return array(); @@ -371,6 +382,31 @@ class AppConfig { } /** + * Save an array of formats that is opened for editing + * + * @param array $formats - formats with status + */ + public function SetEditableFormats($formats) { + $value = json_encode($formats); + $this->logger->info("Set editing formats: " . $value, array("app" => $this->appName)); + + $this->config->setAppValue($this->appName, $this->_editFormats, $value); + } + + /** + * Get an array of formats opening for editing + * + * @return array + */ + private function GetEditableFormats() { + $value = $this->config->getAppValue($this->appName, $this->_editFormats, ""); + if (empty($value)) { + return array(); + } + return json_decode($value, true); + } + + /** * Save the opening setting in a same tab * * @param boolean $value - same tab @@ -397,7 +433,7 @@ class AppConfig { */ public function TurnOffVerification() { $turnOff = $this->getSystemValue($this->_verification); - return $turnOff === TRUE; + return $turnOff === true; } /** @@ -431,14 +467,41 @@ class AppConfig { return empty($this->config->getAppValue($this->appName, $this->_settingsError, "")); } + /** + * Get supported formats + * + * @return array + * + * @NoAdminRequired + */ + public function FormatsSetting() { + $result = $this->formats; + + $defFormats = $this->GetDefaultFormats(); + foreach ($defFormats as $format => $setting) { + if (array_key_exists($format, $result)) { + $result[$format]["def"] = ($setting === true || $setting === "true"); + } + } + + $editFormats = $this->GetEditableFormats(); + foreach ($editFormats as $format => $setting) { + if (array_key_exists($format, $result)) { + $result[$format]["edit"] = ($setting === true || $setting === "true"); + } + } + + return $result; + } + /** * Additional data about formats * * @var array */ - public $formats = [ - "csv" => [ "mime" => "text/csv", "type" => "spreadsheet", "edit" => true ], + private $formats = [ + "csv" => [ "mime" => "text/csv", "type" => "spreadsheet", "edit" => true, "editable" => true ], "doc" => [ "mime" => "application/msword", "type" => "text", "conv" => true ], "docm" => [ "mime" => "application/vnd.ms-word.document.macroEnabled.12", "type" => "text", "conv" => true ], "docx" => [ "mime" => "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "type" => "text", "edit" => true, "def" => true ], @@ -447,9 +510,9 @@ class AppConfig { "epub" => [ "mime" => "application/epub+zip", "type" => "text", "conv" => true ], "htm" => [ "type" => "text", "conv" => true ], "html" => [ "mime" => "text/html", "type" => "text", "conv" => true ], - "odp" => [ "mime" => "application/vnd.oasis.opendocument.presentation", "type" => "presentation", "conv" => true ], - "ods" => [ "mime" => "application/vnd.oasis.opendocument.spreadsheet", "type" => "spreadsheet", "conv" => true ], - "odt" => [ "mime" => "application/vnd.oasis.opendocument.text", "type" => "text", "conv" => true ], + "odp" => [ "mime" => "application/vnd.oasis.opendocument.presentation", "type" => "presentation", "conv" => true, "editable" => true ], + "ods" => [ "mime" => "application/vnd.oasis.opendocument.spreadsheet", "type" => "spreadsheet", "conv" => true, "editable" => true ], + "odt" => [ "mime" => "application/vnd.oasis.opendocument.text", "type" => "text", "conv" => true, "editable" => true ], "pdf" => [ "mime" => "application/pdf", "type" => "text" ], "pot" => [ "type" => "presentation", "conv" => true ], "potm" => [ "mime" => "application/vnd.ms-powerpoint.template.macroEnabled.12", "type" => "presentation", "conv" => true ], @@ -460,8 +523,8 @@ class AppConfig { "ppt" => [ "mime" => "application/vnd.ms-powerpoint", "type" => "presentation", "conv" => true ], "pptm" => [ "mime" => "application/vnd.ms-powerpoint.presentation.macroEnabled.12", "type" => "presentation", "conv" => true ], "pptx" => [ "mime" => "application/vnd.openxmlformats-officedocument.presentationml.presentation", "type" => "presentation", "edit" => true, "def" => true ], - "rtf" => [ "mime" => "text/rtf", "type" => "text", "conv" => true ], - "txt" => [ "mime" => "text/plain", "type" => "text", "edit" => true ], + "rtf" => [ "mime" => "text/rtf", "type" => "text", "conv" => true, "editable" => true ], + "txt" => [ "mime" => "text/plain", "type" => "text", "edit" => true, "editable" => true ], "xls" => [ "mime" => "application/vnd.ms-excel", "type" => "spreadsheet", "conv" => true ], "xlsm" => [ "mime" => "application/vnd.ms-excel.sheet.macroEnabled.12", "type" => "spreadsheet", "conv" => true ], "xlsx" => [ "mime" => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "type" => "spreadsheet", "edit" => true, "def" => true ], diff --git a/lib/crypt.php b/lib/crypt.php index b7790ff..4605df0 100644 --- a/lib/crypt.php +++ b/lib/crypt.php @@ -32,7 +32,7 @@ namespace OCA\Onlyoffice; use OCA\Onlyoffice\AppConfig; /** - * Hash generator + * Token generator * * @package OCA\Onlyoffice */ @@ -53,63 +53,34 @@ class Crypt { } /** - * Generate base64 hash for the object + * Generate token for the object * - * @param array $object - object to signature hash + * @param array $object - object to signature * * @return string */ public function GetHash($object) { - $primaryKey = json_encode($object); - $hash = $this->SignatureCreate($primaryKey); - return $hash; + return \Firebase\JWT\JWT::encode($object, $this->skey); } /** - * Create an object from the base64 hash + * Create an object from the token * - * @param string $hash - base64 hash + * @param string $token - token * * @return array */ - public function ReadHash($hash) { + public function ReadHash($token) { $result = NULL; $error = NULL; - if ($hash === NULL) { - return [$result, "hash is empty"]; + if ($token === NULL) { + return [$result, "token is empty"]; } try { - $payload = base64_decode($hash); - $payloadParts = explode("?", $payload, 2); - - if (count($payloadParts) === 2) { - $encode = base64_encode( hash( "sha256", ($payloadParts[1] . $this->skey), true ) ); - - if ($payloadParts[0] === $encode) { - $result = json_decode($payloadParts[1]); - } else { - $error = "hash not equal"; - } - } else { - $error = "incorrect hash"; - } - } catch (\Exception $e) { + $result = \Firebase\JWT\JWT::decode($token, $this->skey, array("HS256")); + } catch (\UnexpectedValueException $e) { $error = $e->getMessage(); } return [$result, $error]; } - - /** - * Generate base64 hash for the object - * - * @param string $primary_key - string to the signature hash - * - * @return string - */ - private function SignatureCreate($primary_key) { - $payload = base64_encode( hash( "sha256", ($primary_key . $this->skey), true ) ) . "?" . $primary_key; - $base64Str = base64_encode($payload); - - return $base64Str; - } } diff --git a/lib/documentservice.php b/lib/documentservice.php index 621b02c..558bd79 100644 --- a/lib/documentservice.php +++ b/lib/documentservice.php @@ -90,7 +90,7 @@ class DocumentService { * @return string */ function GetConvertedUri($document_uri, $from_extension, $to_extension, $document_revision_id) { - $responceFromConvertService = $this->SendRequestToConvertService($document_uri, $from_extension, $to_extension, $document_revision_id, FALSE); + $responceFromConvertService = $this->SendRequestToConvertService($document_uri, $from_extension, $to_extension, $document_revision_id, false); $errorElement = $responceFromConvertService->Error; if ($errorElement->count() > 0) { @@ -268,7 +268,7 @@ class DocumentService { ) ); - if (($response = $this->Request($urlHealthcheck, $opts)) === FALSE) { + if (($response = $this->Request($urlHealthcheck, $opts)) === false) { throw new \Exception ($this->trans->t("Bad Request or timeout error")); } @@ -314,7 +314,7 @@ class DocumentService { $opts["http"]["header"] = $opts["http"]["header"] . $this->config->JwtHeader() . ": Bearer " . $token . "\r\n"; } - if (($response = $this->Request($urlCommand, $opts)) === FALSE) { + if (($response = $this->Request($urlCommand, $opts)) === false) { throw new \Exception ($this->trans->t("Bad Request or timeout error")); } @@ -371,13 +371,13 @@ class DocumentService { if (substr($url, 0, strlen("https")) === "https" && $this->config->TurnOffVerification()) { $opts["ssl"] = array( - "verify_peer" => FALSE, - "verify_peer_name" => FALSE + "verify_peer" => false, + "verify_peer_name" => false ); } $context = stream_context_create($opts); - return file_get_contents($url, FALSE, $context); + return file_get_contents($url, false, $context); } } |