valicek1 / keepasshttpclient
KeePassHTTP的PHP库
v1.0.1
2017-01-21 12:01 UTC
Requires
- guzzlehttp/guzzle: ~6.0
This package is auto-updated.
Last update: 2024-08-29 03:31:35 UTC
README
要求
- php >= 5.5
- guzzlehttp/guzzle >= 6
安装
最佳方式是使用composer进行安装
$ composer require valicek1/keepasshttpclient
示例代码
# load key and it's id $secret = loadKey(); // you need to implement this by yourself # create class # $secret[0] is 256-bit (32 characters) long key # $secret[1] contains key id $kpx = new KeePassHTTPClient($secret[1], $secret[0]); # is the key associated with DB? if (!$kpx->testAssociated()) { # if not, try to authorize $label = $kpx->authorizeKey(); # and save key + label for next use saveKey($label, $secret[1]); // you need to implement this yourself } if ($kpx->testAssociated()) { // you are welcome to do something in database $url = "https://skype.com"; // get logins $logins = $kpx->getLogins($url, $url); // first URL is page URL, second one is Submit url for "form" // or just their count $count = $kpx->getLoginsCount($url, $url) // or create new pairs in database $kpx->setLogin($url, $url, "username", "realPassword") }
技术流程
与KeePass配对
testAssociated
- 可选authorizeLey
,保存返回的关键ID - 用于未来的请求testAssociated
- 如果成功,可以通过发送请求继续
请求
服务器要求在每个新会话的开始或失败后执行testAssociated
。虽然写了必须这样做,但就我个人而言,我没有看到KeepassHTTP在没有testAssociated
时的行为有任何区别
testAssociated
- 在第一次请求之前getLoginsCount
,getLogins
或setLogin
- 处理数据
文档
构造函数
/** * KeePassHTTPClient constructor. * @param string $key Encryption key, 256 bits * @param string $label Label (product of association) * @param string $address KeepassHTTP listening address * @param int $port KeepassHTTP listening port */ public function __construct($key, $label = "", $address = "localhost", $port = 19455){}
获取器
public function getAddress(){} // address of server public function getPort(){} // port of server public function isAssociated(){} // state of last testAssociated public function getClient(){} // return guzzle client
与KeePass一起工作的函数
public function isServerListening(){} // check, if port is opened public function sendRequest($json){} // json encode $json and send it as request. Return json object of response public function testAssociated($empty = FALSE){} // test if key is associated or server responding (empty = TRUE) public function authorizeKey(){} // authorize key (from constructor) public function getLogins($url, $redirectUrl){} // find logins/passwords for entered criteria. public function getLoginsCount($url, $redirectUrl){} // count number of items for entered criteria public function setLogin($url, $redirectURL, $login, $password){} // save login to KeePass DB
它看起来不是那么美观,但对于使用来说足够了。你仍然可以查看源代码...