/** * Iterates over all password groups and their passwords and saves them * to the database. */ public function get($file_path) { /* @var $xml \app\modules\yiipass\services\SimpleKeePassXmlService */ $xml = \Yii::$app->getModule('yiipass')->get('SimpleKeePassXmlService'); $arr_password_groups = $xml->formXmlFileToArray($file_path); foreach ($arr_password_groups as $group) { foreach ($group as $password_from_group) { /* @var $password_from_group \app\models\Password */ /* @var $password \app\models\Password */ $password = new Password(); $password->title = $password_from_group->title->__toString(); $password->username = $password_from_group->username->__toString(); $password->password = $password_from_group->password->__toString(); $password->url = $password_from_group->url->__toString(); $password->comment = $password_from_group->comment->__toString(); $password->creation = $password_from_group->creation->__toString(); $password->lastaccess = $password_from_group->lastaccess->__toString(); $password->lastmod = $password_from_group->lastmod->__toString(); $password->group = $password_from_group->group->__toString(); $password->lastaccess = $password_from_group->lastaccess->__toString(); $password->save(); $password->save(); UserController::addPermissionToUser(Yii::$app->user->id, 'password-id-' . $password->id); } } }
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; }
/** * Finds the Password model based on its primary key value. If the model * is not found, a 404 HTTP exception will be thrown. * * @param integer $id * @return Password the loaded model * @throws NotFoundHttpException if the model cannot be found * return null */ protected function findModel($id) { if (($model = Password::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getPassword() { return $this->hasOne(Password::className(), ['id' => 'password_id']); }
/** * 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; }