Esempio n. 1
0
 /**
  * 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 = PasswordController::encrypt($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);
         }
     }
 }
Esempio n. 2
0
 /**
  * This command removes all auth assignments for a given
  * auth id, which can be part of an account credential.
  *
  * @param id $id The auth item id.
  * @return null
  */
 public function actionRemoveAuthAssignmentsForId($id)
 {
     PasswordController::removeAllAuthAssignments($id);
 }
Esempio n. 3
0
<?php

use yii\helpers\Html;
use yii\widgets\DetailView;
use app\modules\yiipass\controllers\PasswordController;
/* @var $this yii\web\View */
/* @var $model app\models\Password */
$this->title = $model->title;
$this->params['breadcrumbs'][] = ['label' => 'Passwords', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
// Make password visible.
$model->password = PasswordController::decrypt($model->password);
$debug = true;
?>
<div class="password-view">

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>

    <p>
        <?php 
echo Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']);
?>
        <?php 
echo Html::a('Delete', ['delete', 'id' => $model->id], ['class' => 'btn btn-danger', 'data' => ['confirm' => 'Are you sure you want to delete this item?', 'method' => 'post']]);
?>
    </p>

    <?php 
Esempio n. 4
0
?>
</li>
                    </ul>
                </div>
            </nav>
        </div>
    </div>

    <?php 
$arr_widget = ['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\DataColumn', 'attribute' => 'title', 'format' => 'html', 'value' => function (\app\modules\yiipass\models\Password $password) {
    return Html::a($password->title, ['view?id=' . $password->id]);
}], 'group', ['class' => 'yii\\grid\\ActionColumn', 'template' => '{copy}', 'buttons' => ['copy' => function ($url, $model, $key) {
    return '<button type="button" class="copy_username copy_button"
                                            data-toggle="modal" data-target="#mobileCopyModal"
                                            data-username="******"
                                            data-password="******"
                                            data-title="' . $model->title . '"
                                            title="Copy details">Copy</button>';
}]], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update}', 'buttons' => ['open_url' => function ($url, $model, $key) {
    if ($model->url !== '') {
        return '<a href="' . $model->url . '" title="Open URL in new window" target="_blank">Open URL</a>';
    }
}]]]];
/**
 * If checkboxes will be needed, comment the following line in.
 * Increase then the array key of columns.
 */
// array_unshift($arr_widget['columns'], ['class' => 'yii\grid\CheckboxColumn']);
$arr_widget['columns'][] = ['class' => 'yii\\grid\\ActionColumn', 'template' => '{delete}', 'buttons' => ['open_url' => function ($url, $model, $key) {
    if ($model->url !== '') {
        return '<a href="' . $model->url . '" title="Open URL in new window" target="_blank">Open URL</a>';
Esempio n. 5
0
 /**
  * Deletes an existing Password model. If deletion is successful, the
  * browser will be redirected to the 'index' page.
  *
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     if (Yii::$app->params['single_user_mode'] === FALSE) {
         if (Yii::$app->user->isGuest === TRUE) {
             return $this->redirect(['/site/login']);
         }
         PasswordController::teamSecretCheck();
     }
     if (Yii::$app->params['single_user_mode'] === TRUE or Yii::$app->user->getIdentity()->is_admin == 1) {
         $this->findModel($id)->delete();
         // Remove roles and permissions.
         self::removeAllAuthAssignments($id);
         \Yii::$app->getSession()->setFlash('success', 'Account credential successfully deleted.');
     }
     return $this->redirect(['index']);
 }
Esempio n. 6
0
 public function actionLogout()
 {
     Yii::$app->user->logout();
     PasswordController::removeTeamSecret();
     return $this->goHome();
 }
Esempio n. 7
0
    </div>

    <?php 
$arr_widget = ['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\DataColumn', 'attribute' => 'title', 'format' => 'html', 'value' => function (\app\modules\yiipass\models\Password $password) {
    return Html::a($password->title, ['view?id=' . $password->id]);
}], 'group', ['class' => 'yii\\grid\\ActionColumn', 'template' => '{open_url} {copy_username} {copy_password} {update}', 'buttons' => ['open_url' => function ($url, $model, $key) {
    if ($model->url !== '') {
        return '<a href="' . $model->url . '" title="Open URL in new window" target="_blank">Open URL</a>';
    }
}, 'copy_username' => function ($url, $model, $key) {
    if ($model->username !== '') {
        return '<button type="button" class="copy_username copy_button" data-clipboard-text="' . $model->username . '" title="Click to copy me.">Copy Username</button>';
    }
}, 'copy_password' => function ($url, $model, $key) {
    if ($model->password !== '') {
        return '<button type="button" class="copy_password copy_button" data-clipboard-text="' . PasswordController::decrypt($model->password) . '" title="Click to copy me.">Copy Password</button>';
    }
}]]]];
// If user is admin, set checkbox column at the beginning of the columns.
if (Yii::$app->user->identity->is_admin) {
    /**
     * If checkboxes will be needed, comment the following line in.
     * Increase then the array key of columns.
     */
    // array_unshift($arr_widget['columns'], ['class' => 'yii\grid\CheckboxColumn']);
    $arr_widget['columns']['2']['template'] .= '{delete} ';
}
?>

    <?php 
echo CustomGridViewService::widget($arr_widget);
Esempio n. 8
-1
 /**
  * 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;
 }