Auto Login for the Chive MySQL management tool.

Written by Kevin on November 23, 2011

Chive is Awesome


At work, I primarily use Chive to manage my MySQL databases. I find Chive to be a very effective tool. The only problem I had with it was, there was no way to have an automatic login via stored credentials. I decided to modify the entry script of Chive to auto-login to the database I need it to. Below are the changes I needed to make to have the Chive installation auto-login. In index.php, under the ROOT directory, change the following:

if(!$app->user->isGuest)
{
  $app->db->connectionString = 'mysql:host=' . $app->user->host . ';dbname=information_schema';
  $app->db->username= $app->user->name;
    $app->db->password= $app->user->password;
    $app->db->autoConnect = true;
    $app->db->setActive(true);
}
elseif(!preg_match('/^(' . implode('|', $validPaths) . ')/i', Yii::app()->urlManager->parseUrl($app->request)))
{
  if($app->request->isAjaxRequest)
  {
    $response = new AjaxResponse();
    $response->redirectUrl = Yii::app()->createUrl('site/login');
    $response->send();
  }
  else
  {
    $app->request->redirect(Yii::app()->createUrl('site/login'));
  }
}

Into:

if($app->user->isGuest)
{
  $ident = new UserIdentity('USERNAME','PASSWORD','HOST');
  $ident->authenticate();
  Yii::app()->user->login($ident);
}
$app->db->connectionString = 'mysql:host=' . $app->user->host . ';dbname=information_schema';
$app->db->username= $app->user->name;
$app->db->password= $app->user->password;
$app->db->autoConnect = true;
$app->db->setActive(true);

Change USERNAME, PASSWORD, and HOST to the appropriate values and your credentials will now be saved. For security sake. I would only apply this patch to an installation of Chive that is NOT on a public network. I have it on my local machine. If you decide to use a root or privileged account as the auto-login, you expose all your data to anyone who can access this installation. I hope that if you are reading this, you already know these things, but one can never be to careful.