Skip to content

Commit

Permalink
Add icons to credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
brantje committed Oct 29, 2017
1 parent d1103e6 commit c2c4d61
Show file tree
Hide file tree
Showing 501 changed files with 20,099 additions and 54 deletions.
9 changes: 4 additions & 5 deletions appinfo/database.xml
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,6 @@
<type>clob</type>
<notnull>false</notnull>
</field>
<field>
<name>favicon</name>
<type>clob</type>
<notnull>false</notnull>
</field>
<field>
<name>renew_interval</name>
<type>bigint</type>
Expand Down Expand Up @@ -238,6 +233,10 @@
<name>shared_key</name>
<type>clob</type>
</field>
<field>
<name>icon</name>
<type>clob</type>
</field>
<index>
<name>passman_credential_id_index</name>
<field>
Expand Down
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Features:
- Import from various password managers (KeePass, LastPass, DashLane, ZOHO, Clipperz.is )
For an demo of this app visit [https://demo.passman.cc](https://demo.passman.cc)
]]></description>
<version>2.1.4</version>
<version>2.1.5</version>
<licence>agpl</licence>
<author homepage="https://github.com/brantje">Sander Brand</author>
<author homepage="https://github.com/animalillo">Marcos Zuriaga</author>
Expand Down
7 changes: 6 additions & 1 deletion appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,14 @@
//Translations
['name' => 'translation#getLanguageStrings', 'url' => '/api/v2/language', 'verb' => 'GET'],


#Icons
['name' => 'icon#getIcon', 'url' => '/api/v2/icon/{base64Url}', 'verb' => 'GET'],
['name' => 'icon#getIcon', 'url' => '/api/v2/icon/{base64Url}/{credentialId}', 'verb' => 'GET'],
['name' => 'icon#getLocalIconList', 'url' => '/api/v2/icon/list', 'verb' => 'GET'],

//
['name' => 'vault#preflighted_cors', 'url' => '/api/v2/{path}', 'verb' => 'OPTIONS', 'requirements' => array('path' => '.+')],

//Internal API
['name' => 'internal#remind', 'url' => '/api/internal/notifications/remind/{credential_id}', 'verb' => 'POST'],
['name' => 'internal#read', 'url' => '/api/internal/notifications/read/{credential_id}', 'verb' => 'DELETE'],
Expand Down
10 changes: 10 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "nextcloud/passman",
"authors": [
{
"name": "brantje",
"email": "[email protected]"
}
],
"require": {}
}
4 changes: 2 additions & 2 deletions controller/credentialcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function getCredential($credential_guid) {
*/
public function updateCredential($changed, $created,
$credential_id, $custom_fields, $delete_time, $credential_guid,
$description, $email, $expire_time, $favicon, $files, $guid,
$description, $email, $expire_time, $icon, $files, $guid,
$hidden, $label, $otp, $password, $renew_interval,
$tags, $url, $username, $vault_id, $revision_created, $shared_key, $acl, $unshare_action, $set_share_key, $skip_revision) {

Expand All @@ -142,7 +142,7 @@ public function updateCredential($changed, $created,
'username' => $username,
'password' => $password,
'url' => $url,
'favicon' => $favicon,
'icon' => json_encode($icon),
'renew_interval' => $renew_interval,
'expire_time' => $expire_time,
'files' => $files,
Expand Down
140 changes: 140 additions & 0 deletions controller/iconcontroller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<?php
/**
* Nextcloud - passman
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Sander Brand <[email protected]>
* @copyright Sander Brand 2016
*/

namespace OCA\Passman\Controller;

use Doctrine\DBAL\Exception\DriverException;
use OC\App\AppManager;
use OCA\Passman\Service\IconService;
use OCA\Passman\Utility\Utils;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Http\DataDownloadResponse;
use OCP\AppFramework\Http\Response;
use OCP\IConfig;
use OCP\IRequest;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\ApiController;
use OCA\Passman\Service\CredentialService;
use \OCP\App;
use OCP\IURLGenerator;

class IconController extends ApiController {
private $userId;
private $credentialService;
private $am;
private $urlGenerator;

public function __construct($AppName,
IRequest $request,
$UserId,
CredentialService $credentialService,
AppManager $am,
IURLGenerator $urlGenerator
) {
parent::__construct(
$AppName,
$request,
'GET, POST, DELETE, PUT, PATCH, OPTIONS',
'Authorization, Content-Type, Accept',
86400);
$this->userId = $UserId;
$this->credentialService = $credentialService;
$this->am = $am;
$this->urlGenerator = $urlGenerator;

}

/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function getIcon($base64Url, $credentialId) {
$url = base64_decode(str_replace('_','/', $base64Url));

if($credentialId) {
try {
$credential = $this->credentialService->getCredentialById($credentialId, $this->userId);
$credential = $credential->jsonSerialize();
} catch (DoesNotExistException $e){
// Credential is not found, continue
$credential = false;
}
}

if (!preg_match("~^(?:f|ht)tps?://~i", $url)) {
$url = "http://" . $url;
}

$icon = new IconService($url);

$data = base64_decode("iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAABHVBMVEUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADF3oJhAAAAXnRSTlMAAQIDBAUGBwgJCwwOEBITFBUWFxgaHB4hJCUnKissMDI0ODs9PkFCQ0RNUVJWV1lbXF1hY2Zna2xtcXh7f4KDhYmUm52lq62vsLW3ucHFyszO0dPV197i7/H3+fv9358zuQAAAWdJREFUWMPtldlWwjAURdPWogyKOKM4z0NRQRRHnAdE0QoI1eb/P8OnmzYlSZs+unIes+/ZbdOuFCFuBmc2Dk+qpe18EsVIptTGJJ3jrGR99B4H8jQlUTfOMSM3ZtT+SAsz8z0ZrZ//wZy4S1H6C1iQtfD+tCsS4EJYP9kV9rGTCRE0fMOfxZypITO7++5b/NCE/S3fx7PsLc9/eeuWqK/3vA9ngAJ3BPwmBIIdMnYbvNNLgo4Egg4MvelBpD0D6/F3YYJcJd0PEw7AWa6gCCNnLLoPtMoVPMJIikVNoE2uAN6BzcZ1MPA2wRA+AUIHwHkn1BAM7LH5OvBhjiAFA6tsXgCe4wjSMLDC5nPAx5Xg3wrGylfk1GlcM/MC/KFW6fvRVbBkLuj+omwf401KUJcXtCiBIy+gT4UYfawrgRIogRIogRLwBG4MAfVnsuX7XX8fWfKCU0qgvcr2mwaiDZYtsw/tMtnCP4F4Y01BhTeiAAAAAElFTkSuQmCC");
$type = 'png';

if ($icon->icoExists) {
$data = $icon->icoData;
$type = $icon->icoType;
}

if (isset($credential) && $credential['user_id'] == $this->userId) {
$iconData = [
'type' => $type,
'content' => base64_encode($data)
];
$credential['icon'] = json_encode($iconData);
try {
$this->credentialService->updateCredential($credential);
} catch (DriverException $exception) {
/**
* @FIXME Syntax error or access violation: 1118 Row size too large
* This happens when favicons are quite big.
* Githubs one is 33kb and triggers the try catch
*/
}
}


$offset = 3600 * 24 * 30;
$contentType = 'image/png';
$response = new DataDownloadResponse($data, 'icon', $contentType);

$response->addHeader('Content-Type', $contentType);
$response->addHeader('Content-Length:', mb_strlen($data));
$response->addHeader('Expires: ', gmdate("D, d M Y H:i:s", time() + $offset) . " GMT");
$response->setETag($base64Url);
$response->cacheFor($offset);
//echo $data;
return $response;
}

/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function getLocalIconList() {
$dir = $this->am->getAppPath('passman');
$result = Utils::getDirContents($dir . '/img/icons');

$icons = [];
foreach ($result as $icon) {
$iconPath = $icon;
$path = explode('passman/', $iconPath);
$mime = mime_content_type($iconPath);
//print_r($path);
if($mime !== 'directory') {
$icon = [];
$icon['mimetype'] = mime_content_type($iconPath);
$icon['url'] = $this->urlGenerator->linkTo('passman', $path[1]);
$icons[] = $icon;
}
}
return new JSONResponse($icons);
}
}
3 changes: 3 additions & 0 deletions controller/translationcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ public function getLanguageStrings() {
'username' => $this->trans->t('Username'),
'password.r' => $this->trans->t('Repeat password'),
'add.tag' => $this->trans->t('Add tag'),
'pick.icon' => $this->trans->t('Pick an icon'),
'use.icon' => $this->trans->t('Use this icon'),
'selected.icon' => $this->trans->t('Selected icon'),

// templates/views/partials/edit_credential/custom_fields.html
'field.label' => $this->trans->t('Field label'),
Expand Down
65 changes: 65 additions & 0 deletions css/app.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c2c4d61

Please sign in to comment.