public function testImport() { /* @var $xml \app\modules\yiipass\services\SimpleKeePassXmlService */ $xml = Yii::$app->getModule('yiipass')->get('xml'); $arr__passwords = Password::find()->asArray()->orderBy('group')->each(); $xml_result = $xml->createKeePassValidXml($arr__passwords); $debug = 'foo'; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params, $account_credential_ids = null) { $query = Password::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate() || empty($account_credential_ids) && $this->isUserAllowedToSeeAllPasswords() === FALSE) { // uncomment the following line if you do not want to return any records when validation fails $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'creation' => $this->creation, 'lastaccess' => $this->lastaccess, 'lastmod' => $this->lastmod, 'expire' => $this->expire]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'group', $this->group])->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'password', $this->password])->andFilterWhere(['like', 'comment', $this->comment])->andFilterWhere(['like', 'url', $this->url]); if (!empty($account_credential_ids)) { $query->andFilterWhere(['in', 'id', $account_credential_ids]); } return $dataProvider; }
/** * Allows download as passwords for KeePass programs as XML file. * * @throws \yii\base\InvalidConfigException * @throws \yii\web\HttpException * return null */ public function actionDownloadPasswordsAsKeePassXml() { if (Yii::$app->user->isGuest === true) { return $this->redirect(['/site/login']); } $all_passwords = Password::find()->asArray()->all(); $allowed_passwords = array(); foreach ($all_passwords as $password) { $user_id = Yii::$app->user->identity->id; $is_admin = Yii::$app->user->identity->is_admin; if (Yii::$app->authManager->checkAccess($user_id, 'password-id-' . $password['id']) === true || $is_admin == 1) { $allowed_passwords[] = $password; } } /* @var $xml_service \app\modules\yiipass\services\SimpleKeePassXmlService */ $xml_service = \Yii::$app->getModule('yiipass')->get('SimpleKeePassXmlService'); $xml = $xml_service->createKeePassValidXml($allowed_passwords); // Download the passwords XML file. \Yii::$app->getResponse()->sendContentAsFile($xml, 'passwords.xml'); }
/** * Checks the team secret. If not set, the user will be redirected to the * team secret form. * * @return \yii\web\Response|bool */ public static function teamSecretCheck() { $password = Password::find()->andWhere(['not', ['password' => null]])->one(); if (self::getTeamSecret() !== null && isset($password->password) && self::decrypt($password->password) === false) { \Yii::$app->session->setFlash('error', 'Inserted team secret is wrong.'); self::removeTeamSecret(); } if (!self::getTeamSecret() && isset($password->password) && self::decrypt($password->password) === false) { \Yii::$app->session->setFlash('info', 'Please insert the team secret.'); self::removeTeamSecret(); } if (!isset($password->password)) { \Yii::$app->session->setFlash('info', 'Please set initially the team secret for your team. ' . 'Mind that the team secret cannot be changed, after any account credential is being saved.'); } // Initial login. No passwords saved, don't redirect back to the form. if (self::getTeamSecret() !== null && !isset($password->password)) { return true; } if (self::getTeamSecret() == null or self::decrypt($password->password) === false) { return (new PasswordController('teamSecretCheck', Yii::$app->module))->redirect('/yiipass/password/team-secret-form'); } }
/** * Modifies the group input to let the user choose all existing groups. * * @param $cells * @return array */ private function modifyGroupInput($cells) { foreach ($cells as $cell) { if (is_numeric(strpos($cell, '[group]'))) { $searchModel = new PasswordSearch(); $acc_groups = Password::find()->select(['id', 'group'])->where(['is not', 'group', null])->asArray()->all(); // Filter unique group items from all account credentials. $acc_groups = self::getUniqueArrItems($acc_groups, 'group'); // Groups for which the user has access. $allowed_acc_groups = array(); if (is_object(\Yii::$app->user->identity) && intval(\Yii::$app->user->identity->is_admin) !== 1) { foreach ($acc_groups as $a_group) { // Iterate all groups and check if user is allowed. if (PasswordController::checkAccessByAccId($a_group['id'])) { $allowed_acc_groups[] = $a_group; } } } else { // Admin can access everything. $allowed_acc_groups = $acc_groups; } $arr_dropdown = ArrayHelper::map($allowed_acc_groups, 'group', 'group'); $cell = Html::activeDropDownList($searchModel, 'group', $arr_dropdown, ['class' => 'form-control', 'prompt' => 'Select Group']); $cell = $this->render('@app/modules/yiipass/views/elements/dropdown', array('group_input' => $cell)); } // Remove "lastaccess" input. Working sorting is enough here. Input for date works not good. if (is_numeric(strpos($cell, '[lastaccess]'))) { $cell = ''; } $new_cells[] = $cell; } return $new_cells; }