Skip to content

Instantly share code, notes, and snippets.

@supertassu
Created June 12, 2017 15:07
Show Gist options
  • Save supertassu/7bd02ab3ba4c1625340505f4ac9efb96 to your computer and use it in GitHub Desktop.
Save supertassu/7bd02ab3ba4c1625340505f4ac9efb96 to your computer and use it in GitHub Desktop.
licensing system
<?php
error_reporting(E_ALL);
if (!(isset($_GET["pl"]))) die("error");
if (!(isset($_GET["token"]))) die("error");
$handle = @fopen("someplugin.txt", "r");
if ($handle && $_GET["pl"] == "someplugin") {
while (($buffer = fgets($handle, 4096)) !== false) {
if (strcmp(trim($buffer), $_GET["token"]) == 0) {
echo "ok";
}
}
if (!feof($handle)) {
echo "error: unexpected fgets() fail\n";
}
fclose($handle);
} else {
echo "error";
}
String token = ...;
try {
boolean license = false;
URL oracle = new URL("http://your.server/api.php?pl=someplugin&token=" + token);
BufferedReader in = new BufferedReader(
new InputStreamReader(oracle.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
if (inputLine.contains("ok")) {
license = true;
getLogger().info("License ok");
}
}
in.close();
if (!license) {
getLogger().info("== [ == ] == [ == ] ==");
getLogger().info("UNKNOWN LICENSE KEY!");
getLogger().info("== [ == ] == [ == ] ==");
getPluginLoader().disablePlugin(this);
return;
}
}
catch (Exception ex) {
ex.printStackTrace();
getLogger().info("== [ == ] == [ == ] ==");
getLogger().info("COULD NOT CONTACT LICENSING SERVERS");
getLogger().info("== [ == ] == [ == ] ==");
getPluginLoader().disablePlugin(this);
return;
}
key1
key2
key3
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment