PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Colin McKinnon   PHP KeePassX Writer   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP KeePassX Writer
Create database of passwords for KeePass
Author: By
Last change:
Date: 3 years ago
Size: 1,599 bytes


Class file image Download


$kpx=new KeePassWriter(
getenv("HOME") . "/sample.kdbx", // database to create
"letmein", // passphrase for new database
20, // timeout for writing to keepassxc-cli (optional)
'/usr/bin/keepassxc-cli'); // path to binary (optional)

// groups are created automatically, but if we want to assign notes
// or specific icons then we use 'addgroup'
// addgroup($path, $notes, $icon=false)
$kpx->addgroup("/home", "Home folder", KPX_ICON_HOME);
$kpx->addgroup("/infrastructure/network", "Switches etc", KPX_ICON_NETWORK_BOXES);
$kpx->addgroup("/infrastructure/linux", "Linux hosts", KPX_ICON_TUX);
$kpx->addgroup("/infrastructure/external", "3rd Party services", KPX_ICON_CLOUD);
$kpx->addgroup("/infrastructure/Microsoft", "MS Windows hosts", KPX_ICON_MSWINDOWS);
$kpx->addgroup("/applications", "In-house apps", KPX_ICON_YELLOW_DOC);
$kpx->addgroup("/database", "Admin accounts", KPX_ICON_DB_BURGER_KEY);
$kpx->addgroup("/encryption", "Encryption keys", KPX_ICON_KEYRING);

// add some entries
// additem($path, $title, $username, $secret, $url, $notes)
$kpx->additem("/infrastructure/linux", ""
, "root", "sw0rd1sh", "ssh://"
, "Assunming the host is configured to allow root logins via ssh");
$kpx->additem("/infrastructure/network", "admin@"
, "admin", "pass123", "ssh://admin@"
, "Admin user on Cisco");

// we can display the generated XML....
// $kpx->writedata(STDOUT);