|
| 1 | +<?php |
| 2 | + |
| 3 | +// Define ANSI color codes |
| 4 | +define('COLOR_GREEN', "\033[32m"); |
| 5 | +define('COLOR_WHITE', "\033[0m"); |
| 6 | + |
| 7 | +// Function to prompt a question and get user input |
| 8 | +function prompt($question, $default = null) { |
| 9 | + echo COLOR_GREEN . $question . COLOR_WHITE . ": "; |
| 10 | + $handle = fopen("php://stdin", "r"); |
| 11 | + $response = trim(fgets($handle)); |
| 12 | + fclose($handle); |
| 13 | + return empty($response) ? $default : $response; |
| 14 | +} |
| 15 | + |
| 16 | +$createFile = prompt('Would you like to automatically create an index.php that instantiate JSON.ms? (Y) ', 'Y'); |
| 17 | +if (strtoupper($createFile) == 'Y') { |
| 18 | + $privatePath = preg_replace('/(\/|\\\)+/', DIRECTORY_SEPARATOR , getcwd() . '/private/'); |
| 19 | + $privatePath = prompt('Where in your file system do you want to save your data? (default: ' . $privatePath . ') ', $privatePath); |
| 20 | + $privatePath = str_replace('\\', '\\\\', $privatePath); |
| 21 | + |
| 22 | + $publicUrl = 'http://localhost:8080'; |
| 23 | + $publicUrl = prompt('What will be your public endpoint URL? (default: ' . $publicUrl . ') ', $publicUrl); |
| 24 | + |
| 25 | + $acao = 'https://json.ms'; |
| 26 | + $acao = prompt('Define the Access-Control-Allow-Origin (default: ' . $acao . '): ', $acao); |
| 27 | + |
| 28 | + $secretKey = prompt('Your webhook secret key? '); |
| 29 | + $cypherKey = prompt('Your webhook cypher key? '); |
| 30 | + |
| 31 | + $fileContent = <<<EOD |
| 32 | +<?php |
| 33 | +
|
| 34 | +use JSONms\JSONms; |
| 35 | +
|
| 36 | +require 'vendor/autoload.php'; |
| 37 | +
|
| 38 | +// Load JSONms configurations |
| 39 | +\$jsonms = new JSONms( |
| 40 | + '$privatePath', // Where to read/save your data in your file system? |
| 41 | + '$publicUrl', // Public path of your server (webhook) |
| 42 | + '$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. |
| 43 | + '$secretKey', // Obtain from your Webhook Endpoint in Settings panel in Advanced mode. |
| 44 | + '$cypherKey', // Obtain from your Webhook Endpoint in Settings panel in Advanced mode. |
| 45 | +); |
| 46 | +
|
| 47 | +// Handle errors (if required) and requests |
| 48 | +\$jsonms->handleErrors(); // Optional. Remove if you prefer to handle errors yourself. |
| 49 | +\$jsonms->handleRequests(); // You can pass an URI param. (ex: /data/get/YOUR_HASH)`); |
| 50 | +
|
| 51 | +EOD; |
| 52 | + |
| 53 | + file_put_contents(dirname(__FILE__) . '/index.php', $fileContent); |
| 54 | + |
| 55 | + echo COLOR_GREEN . 'A new index.php file has been created!' . COLOR_WHITE; |
| 56 | +} |
0 commit comments