* [ADD] sysPass XML import

This commit is contained in:
nuxsmin
2015-07-14 19:05:53 +02:00
committed by nuxsmin
parent ea3b32f401
commit 7da5da2ea6
5 changed files with 402 additions and 18 deletions

View File

@@ -33,8 +33,17 @@ defined('APP_ROOT') || die(_('No es posible acceder directamente a este archivo'
*/
class Import
{
/**
* @var array Resultado de las operaciones
*/
private static $_result = array();
/**
* @var string Contenido del archivo importado
*/
private static $_fileContent;
/**
* @var string Nombre del archivo temporal
*/
private static $_tmpFile;
/**
@@ -257,14 +266,17 @@ class Import
$xml = self::readXMLFile();
if ($xml->Meta->Generator == 'KeePass') {
KeepassImport::addKeepassAccounts($xml);
KeepassImport::addAccounts($xml);
} else if($xml->Meta->Generator == 'sysPass') {
$import = new SyspassImport();
$import->addAccounts($xml);
} else if ($xmlApp = self::parseFileHeader()) {
switch ($xmlApp) {
case 'keepassx_database':
KeepassXImport::addKeepassXAccounts($xml);
KeepassXImport::addAccounts($xml);
break;
case 'revelationdata':
error_log('REVELATION');
error_log('REVELATION XML');
break;
default:
break;
@@ -282,7 +294,7 @@ class Import
* Leer el archivo de KeePass a un objeto XML.
*
* @throws SPException
* @return object Con los datos del archivo XML
* @return \SimpleXMLElement Con los datos del archivo XML
*/
private static function readXMLFile()
{

View File

@@ -1,5 +1,4 @@
<?php
/**
* sysPass
*
@@ -36,9 +35,9 @@ class KeepassImport
/**
* Iniciar la importación desde KeePass
*
* @param object $xml
* @param \SimpleXMLElement $xml
*/
public static function addKeepassAccounts($xml)
public static function addAccounts(\SimpleXMLElement $xml)
{
self::getGroups($xml->Root->Group);
}
@@ -46,10 +45,10 @@ class KeepassImport
/**
* Obtener los datos de las entradas de KeePass.
*
* @param object $entries con el objeto XML con las entradas
* @param \SimpleXMLElement $entries El objeto XML con las entradas
* @param string $groupName con nombre del grupo a procesar
*/
private static function getEntryData($entries, $groupName)
protected static function getEntryData(\SimpleXMLElement $entries, $groupName)
{
foreach ($entries as $entry) {
foreach ($entry->String as $account) {
@@ -81,9 +80,9 @@ class KeepassImport
/**
* Obtener los grupos y procesar lan entradas de KeePass.
*
* @param object $xml con objeto XML del archivo de KeePass
* @param \SimpleXMLElement $xml El objeto XML del archivo de KeePass
*/
private static function getGroups($xml)
protected static function getGroups(\SimpleXMLElement $xml)
{
foreach ($xml as $node) {
if ($node->Group) {

View File

@@ -1,5 +1,4 @@
<?php
/**
* sysPass
*
@@ -36,9 +35,9 @@ class KeepassXImport
/**
* Iniciar la importación desde KeePass.
*
* @param object $xml
* @param \SimpleXMLElement $xml
*/
public static function addKeepassXAccounts($xml)
public static function addAccounts(\SimpleXMLElement $xml)
{
self::getGroups($xml);
}
@@ -46,10 +45,10 @@ class KeepassXImport
/**
* Obtener los datos de las entradas de KeePass.
*
* @param object $entries con el objeto XML con las entradas
* @param \SimpleXMLElement $entries El objeto XML con las entradas
* @param string $groupName con nombre del grupo a procesar
*/
private static function getEntryData($entries, $groupName)
protected static function getEntryData(\SimpleXMLElement $entries, $groupName)
{
foreach ($entries as $entry) {
$notes = (isset($entry->comment)) ? (string)$entry->comment : '';
@@ -66,9 +65,9 @@ class KeepassXImport
/**
* Obtener los grupos y procesar lan entradas de KeePass.
*
* @param object $xml con objeto XML del archivo de KeePass
* @param \SimpleXMLElement $xml con objeto XML del archivo de KeePass
*/
private static function getGroups($xml)
protected static function getGroups(\SimpleXMLElement $xml)
{
foreach ($xml as $node) {
if ($node->group) {

108
inc/SyspassImport.class.php Normal file
View File

@@ -0,0 +1,108 @@
<?php
/**
* sysPass
*
* @author nuxsmin
* @link http://syspass.org
* @copyright 2012-2015 Rubén Domínguez nuxsmin@syspass.org
*
* This file is part of sysPass.
*
* sysPass is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* sysPass is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace SP;
defined('APP_ROOT') || die(_('No es posible acceder directamente a este archivo'));
/**
* Esta clase es la encargada de importar cuentas desde KeePass
*/
class SyspassImport extends XmlImportBase
{
/**
* Iniciar la importación desde KeePass
*
* @param \SimpleXMLElement $xml
* @throws SPException
* @return bool
*/
public function addAccounts(\SimpleXMLElement $xml)
{
try {
$this->getAccountData($xml->Accounts);
$this->getCategories($xml->Categories);
$this->getCustomers($xml->Customers);
} catch (SPException $e){
return false;
}
return true;
}
/**
* Obtener los datos de las entradas de KeePass.
*
* @param \SimpleXMLElement $entries El objeto XML del nodo de cuentas
*/
protected function getAccountData(\SimpleXMLElement $entries)
{
foreach ($entries as $entry) {
$account = $entry->Account;
$this->setAccountName($account->name);
$this->setAccountLogin($account->login);
$this->setCategoryId($account->categoryId);
$this->setCustomerId($account->customerId);
$this->setAccountUrl($account->url);
$this->setAccountLogin($account->login);
$this->setAccountPass($account->pass);
$this->setAccountPassIV($account->passiv);
$this->setAccountNotes($account->notes);
error_log($this->getAccountName());
// Import::addAccountData($accountData);
}
}
/**
* Obtener las categorías.
*
* @param \SimpleXMLElement $entries El objeto XML del nodo categorias
*/
protected function getCategories(\SimpleXMLElement $entries)
{
foreach ($entries->Category as $category) {
$this->setCategoryId($category['id']);
$this->setCategoryName($category->name);
Category::addCategory();
}
}
/**
* Obtener los clientes.
*
* @param \SimpleXMLElement $entries El objeto XML del nodo clientes
*/
protected function getCustomers(\SimpleXMLElement $entries)
{
foreach ($entries->Customer as $customer) {
$this->setCustomerId($customer['id']);
$this->setCustomerName($customer->name);
}
}
}

266
inc/XmlImportBase.class.php Normal file
View File

@@ -0,0 +1,266 @@
<?php
/**
* sysPass
*
* @author nuxsmin
* @link http://syspass.org
* @copyright 2012-2015 Rubén Domínguez nuxsmin@syspass.org
*
* This file is part of sysPass.
*
* sysPass is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* sysPass is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace SP;
defined('APP_ROOT') || die(_('No es posible acceder directamente a este archivo'));
abstract class XmlImportBase
{
/**
* Nombre de la cuenta.
*
* @var string
*/
protected $_accountName = '';
/**
* Id del cliente.
*
* @var int
*/
protected $_customerId = 0;
/**
* Id de categoria.
*
* @var int
*/
protected $_categoryId = 0;
/**
* Login de la cuenta.
*
* @var string
*/
protected $_accountLogin = '';
/**
* Url de la cuenta.
*
* @var string
*/
protected $_accountUrl = '';
/**
* Notas de la cuenta.
*
* @var string
*/
protected $_accountNotes = '';
/**
* Clave de la cuenta.
*
* @var string
*/
protected $_accountPass = '';
/**
* IV de la clave de la cuenta.
*
* @var string
*/
protected $_accountPassIV = '';
/**
* Nombre de la categoría
*
* @var string
*/
protected $_categoryName = '';
/**
* Nombre del cliente.
*
* @var string
*/
protected $_customerName = '';
/**
* @return string
*/
public function getCategoryName()
{
return $this->_categoryName;
}
/**
* @param string $_categoryName
*/
public function setCategoryName($_categoryName)
{
$this->_categoryName = $_categoryName;
}
/**
* @return string
*/
public function getCustomerName()
{
return $this->_customerName;
}
/**
* @param string $_customerName
*/
public function setCustomerName($_customerName)
{
$this->_customerName = $_customerName;
}
/**
* @return string
*/
public function getAccountName()
{
return $this->_accountName;
}
/**
* @param string $_accountName
*/
public function setAccountName($_accountName)
{
$this->_accountName = $_accountName;
}
/**
* @return int
*/
public function getCustomerId()
{
return $this->_customerId;
}
/**
* @param int $_customerId
*/
public function setCustomerId($_customerId)
{
$this->_customerId = $_customerId;
}
/**
* @return int
*/
public function getCategoryId()
{
return $this->_categoryId;
}
/**
* @param int $_categoryId
*/
public function setCategoryId($_categoryId)
{
$this->_categoryId = $_categoryId;
}
/**
* @return string
*/
public function getAccountLogin()
{
return $this->_accountLogin;
}
/**
* @param string $_accountLogin
*/
public function setAccountLogin($_accountLogin)
{
$this->_accountLogin = $_accountLogin;
}
/**
* @return string
*/
public function getAccountUrl()
{
return $this->_accountUrl;
}
/**
* @param string $_accountUrl
*/
public function setAccountUrl($_accountUrl)
{
$this->_accountUrl = $_accountUrl;
}
/**
* @return string
*/
public function getAccountNotes()
{
return $this->_accountNotes;
}
/**
* @param string $_accountNotes
*/
public function setAccountNotes($_accountNotes)
{
$this->_accountNotes = $_accountNotes;
}
/**
* @return string
*/
public function getAccountPass()
{
return $this->_accountPass;
}
/**
* @param string $_accountPass
*/
public function setAccountPass($_accountPass)
{
$this->_accountPass = $_accountPass;
}
/**
* @return string
*/
public function getAccountPassIV()
{
return $this->_accountPassIV;
}
/**
* @param string $_accountPassIV
*/
public function setAccountPassIV($_accountPassIV)
{
$this->_accountPassIV = $_accountPassIV;
}
/**
* Iniciar la importación de cuentas
*
* @param \SimpleXMLElement $xml
*/
public abstract function addAccounts(\SimpleXMLElement $xml);
/**
* Obtener los datos de las entradas.
*
* @param \SimpleXMLElement $entries El objeto XML con las entradas
*/
protected abstract function getAccountData(\SimpleXMLElement $entries);
}