Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP viewer for sqlite3 clients.db #27

Closed
wants to merge 3 commits into from
Closed

PHP viewer for sqlite3 clients.db #27

wants to merge 3 commits into from

Conversation

arturolegovich
Copy link

PHP viewer for sqlite3 clients.db

PHP viewer for sqlite3 clients.db
@arturolegovich
Copy link
Author

Hello!
If you already have PHP on your router and cannot install flask for sqlite-web then you can use this.

@Matthew-Beckett
Copy link
Collaborator

Hi @arturolegovich

Can you help us understand the purpose of this? We already provide an SQLite-web interface as a modern flask app and package it inside a docker container so you do not have to install flask.

@arturolegovich
Copy link
Author

Hi @arturolegovich

Can you help us understand the purpose of this? We already provide an SQLite-web interface as a modern flask app and package it inside a docker container so you do not have to install flask.

Yes, I do not have to install flask on old OpenWRT-firmware.

@Matthew-Beckett
Copy link
Collaborator

OpenWRT supports Docker no? I don't want to devalue your enhancement, I'm just trying to understand how your change will see wider usage by the community.

Docker is definitely our most common runtime/platform.

With it being in PHP, and I myself not being a PHP developer, can't be sure how people are going to host it and with no PHP skill on the team and it's history of vulnerability I'm hesitant to accept the PR for fear of how users may host it without security and expose themselves.

I'm sure your code is secure and fine, but we don't have the skill on the team to maintain it, maybe @simonmicro has more to add.

Just noting, this is not a no, or rejection. Just a discussion about how we support this long term.

@simonmicro
Copy link

Hi @arturolegovich

thanks for your contribution. I'm myself a developer and I have gained a lot of experience with PHP over the recent 3 years (sometimes I hate "historical reasons" 😮‍💨 ). As I can see the code is not as clean as it could be. Please take a look into your exhaustive usage of echo, as it really impacts the readability of your work. And yes, the indentations are also... To be improved.
Also I can understand why flask/websqlite does not work for you - after all routers only have a low two-digit number of remaining MB, mostly too few to install Docker, yet any image, on them.
Still, I have to ask how this could improve our primary goal of providing an Python application to deliver this service. Additionally we have already chosen a good fitting solution for viewing the sqlite database file. Therefore I would like to propose to you to close this PR and create your own repository containing this index file. I'll be happy to update the py-kms wiki to your project! In case it gains some sort of popularity we will be happy to include it into our official py-kms-organization and further developing / supporting it!

Feel free to answer to this PR and changing my mind 😄

@simonmicro
Copy link

@Matthew-Beckett The code seems to be fine on a function-level, as it does not take any input the most dangerous and common pitfalls have been avoided. But still: There is no error handling and... Why am I reviewing a < 60 lines of code PHP file? Honestly: Everyone with the desperate need for an PHP implementation should be able to create it for themselfs.

@simonmicro simonmicro added the enhancement New feature or request label Oct 28, 2021
@arturolegovich
Copy link
Author

Hi.
I wrote the first start.sh and Dockerfile xD). Yes, I also use an existing Docker image. But there is no way to install python3 on my router and I am using python2 xD). And since I already have php, it's easier for me to write 60 lines of code in php than to mess with packages. Maybe someone will have the same situation.

@arturolegovich
Copy link
Author

I need web-viewer on python without flask, small and easy. Somethink like this https://stackoverflow.com/questions/52418357/creating-a-rest-api-without-flask-in-python

@Matthew-Beckett
Copy link
Collaborator

Therefore I would like to propose to you to close this PR and create your own repository containing this index file. I'll be happy to update the py-kms wiki to your project! In case it gains some sort of popularity we will be happy to include it into our official py-kms-organization and further developing / supporting it!

I have to agree with @simonmicro and I believe this is a good course of action. Anyone with a requirement such as yours which has come about as a result of deprecation doesn't really fall in the remit of this project to support.

Furthermore, I couldn't merge a PR with commit messages which do not contain any valid description of the commit content, "Files added via upload" is not adequate detail, this must be improved before a merge of any code can be considered.

Please don't let this deter you though, we welcome advancements of any kind, but generally not components which duplicate existing functionality that are supported in the vast majority of deployments.

@arturolegovich
Copy link
Author

arturolegovich commented Oct 28, 2021

I agree with you. I close the request. Compiled python3 from sources for the router, normal flight xD).

I'll leave the code just in case someone suddenly needs it.

<!DOCTYPE html>

<html lang=en>
<head>
<meta charset=utf-8>
<title>py-kms server</title>
<meta name=description content="py-kms server">
<meta name=keywords content=php py-kms>
<body>

<?php
# Change variables for youself!
$sqlite_dbpath = "/opt/var/sqlite/clients.db";
$dateformat = "d.m.Y H:i:s";
#######################
# ---- START SCRIPT----
#######################
if (!file_exists($sqlite_dbpath)) {
	echo "Error: file $sqlite_dbpath not found!";
	die();
}
$dbn = "sqlite:$sqlite_dbpath";
try {
	$dbh = new PDO($dbn);
}
catch (PDOException $e) {
	echo "Error: " . $e->getMessage(). "!";
	die();
}
$sql = "SELECT sum(requestCount) FROM clients";
foreach ($dbh->query($sql) as $row) {
	$requestCount = $row[0];
}
$sql = "SELECT clientMachineId, machineName, applicationId, skuId, licenseStatus, lastRequestTime, kmsEpid, requestCount FROM clients";
?>
<table border=1 cellspacing=0 cellpadding=2 width=95% align=center>
	<thead bgcolor=silver>
	<tr>
		<th>Machine name</th><th>App ID</th><th>App version</th><th>License status</th><th>Last request time</th><th>Request count</th>
	</tr>
	<thead>
<?php
foreach ($dbh->query($sql) as $row) {
	echo "	<tr>
		<td>" . $row['machineName'] . "</td>
		<td>" . $row['applicationId'] . "</td>
		<td>" . $row['skuId'] . "</td>
		<td>" . $row['licenseStatus'] . "</td>
		<td>" . date('d.m.Y H:i:s',$row['lastRequestTime']). "</td>
		<td>" . $row['requestCount'] . "</td>
	</tr>\n";
}
?>
	<tr bgcolor=silver>
		<td colspan=5><b>Total request count:</b></td>
<?php		
	echo "	<td>$requestCount</td>\n";
?>
	</tr>
</table>
<?php
$dbh = NULL;
?>

</body>
</html>

Demo: https://www.phpchain.ru/py-kms/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants