Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
{
"version": "1.0.5",
"version": "1.0.6",
"name": "jsonms/php",
"description": "A JSON.ms requests handler to install on your own server.",
"type": "library",
"license": "MIT",
"scripts": {
"setup-hooks": "cp .pre-commit .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit"
"setup-hooks": "cp .pre-commit .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit",
"post-install-cmd": [
"php install.php"
]
},
"autoload": {
"psr-4": {
Expand Down
56 changes: 56 additions & 0 deletions install.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

// Define ANSI color codes
define('COLOR_GREEN', "\033[32m");
define('COLOR_WHITE', "\033[0m");

// Function to prompt a question and get user input
function prompt($question, $default = null) {
echo COLOR_GREEN . $question . COLOR_WHITE . ": ";
$handle = fopen("php://stdin", "r");
$response = trim(fgets($handle));
fclose($handle);
return empty($response) ? $default : $response;
}

$createFile = prompt('Would you like to automatically create an index.php that instantiate JSON.ms? (Y) ', 'Y');
if (strtoupper($createFile) == 'Y') {
$privatePath = preg_replace('/(\/|\\\)+/', DIRECTORY_SEPARATOR , getcwd() . '/private/');
$privatePath = prompt('Where in your file system do you want to save your data? (default: ' . $privatePath . ') ', $privatePath);
$privatePath = str_replace('\\', '\\\\', $privatePath);

$publicUrl = 'http://localhost:8080';
$publicUrl = prompt('What will be your public endpoint URL? (default: ' . $publicUrl . ') ', $publicUrl);

$acao = 'https://json.ms';
$acao = prompt('Define the Access-Control-Allow-Origin (default: ' . $acao . '): ', $acao);

$secretKey = prompt('Your webhook secret key? ');
$cypherKey = prompt('Your webhook cypher key? ');

$fileContent = <<<EOD
<?php

use JSONms\JSONms;

require 'vendor/autoload.php';

// Load JSONms configurations
\$jsonms = new JSONms(
'$privatePath', // Where to read/save your data in your file system?
'$publicUrl', // Public path of your server (webhook)
'$acao', // Set to "https://json.ms" if you do not need your own instance of JSON.ms. You can add multiple URLs by seperating them by a comma.
'$secretKey', // Obtain from your Webhook Endpoint in Settings panel in Advanced mode.
'$cypherKey', // Obtain from your Webhook Endpoint in Settings panel in Advanced mode.
);

// Handle errors (if required) and requests
\$jsonms->handleErrors(); // Optional. Remove if you prefer to handle errors yourself.
\$jsonms->handleRequests(); // You can pass an URI param. (ex: /data/get/YOUR_HASH)`);

EOD;

file_put_contents(dirname(__FILE__) . '/index.php', $fileContent);

echo COLOR_GREEN . 'A new index.php file has been created!' . COLOR_WHITE;
}