123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- <?php
- define("BUILD_PATH", dirname(dirname(__DIR__)) . "/build/");
- define("AIRTIME_CONF_TEMP_PATH", "/tmp/airtime.conf.temp");
- abstract class Setup {
- abstract function __construct($settings);
- abstract function runSetup();
-
- protected function writeToTemp($section, $properties) {
- if (!file_exists(AIRTIME_CONF_TEMP_PATH)) {
- copy(BUILD_PATH . "airtime.example.conf", AIRTIME_CONF_TEMP_PATH);
- }
-
- $file = file(AIRTIME_CONF_TEMP_PATH);
- $fileOutput = "";
-
- $inSection = false;
-
- foreach ($file as $line) {
- if (strpos($line, $section) !== false) {
- $inSection = true;
- } else if (strpos($line, "[") !== false) {
- $inSection = false;
- }
-
- if (substr(trim($line), 0, 1) == "#") {
-
- } else if ($inSection) {
- $key = trim(@substr($line, 0, strpos($line, "=")));
- $fileOutput .= $key && isset($properties[$key]) ? $key . " = " . $properties[$key] . "\n" : $line;
- } else {
- $fileOutput .= $line;
- }
- }
-
- file_put_contents(AIRTIME_CONF_TEMP_PATH, $fileOutput);
- }
-
- protected function generateRandomString($p_len = 20, $p_chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') {
- $string = '';
- for($i = 0; $i < $p_len; $i++) {
- $pos = mt_rand(0, strlen($p_chars) - 1);
- $string .= $p_chars{$pos};
- }
- return $string;
- }
- }
- class AirtimeDatabaseException extends Exception {
-
- protected $message = "Unknown Airtime database exception";
- protected $errors = array();
- public function __construct($message = null, $errors = array(), $code = 0, Exception $previous = null) {
- parent::__construct($message, $code, $previous);
- $this->errors = $errors;
- }
- public function getErrorFields() {
- return $this->errors;
- }
- }
- require_once ('database-setup.php');
- require_once ('rabbitmq-setup.php');
- require_once ('general-setup.php');
- require_once ('media-setup.php');
- if (!file_exists("/etc/airtime/airtime.conf")) {
- if (isset($_GET["obj"]) && $objType = $_GET["obj"]) {
- $obj = new $objType($_POST);
- if ($obj instanceof Setup) {
- try {
- $response = $obj->runSetup();
- } catch (AirtimeDatabaseException $e) {
- $response = array(
- "message" => $e->getMessage(),
- "errors" => $e->getErrorFields()
- );
- }
-
- echo json_encode($response);
- }
- }
- }
|