예제 #1
0
 /**
  * Registers a service to be used with the service chain
  *
  * @return  Void
  *
  * @since   2015-12-17
  * @author  Deac Karns <*****@*****.**>
  */
 public function register($name = NULL)
 {
     $headers = \Rhonda\Headers::getallheaders();
     $config = \Rhonda\Config::get('system');
     if (empty($name) && !empty($config)) {
         // see if service is set in the config
         if (!empty($config->host)) {
             $service = $config->host;
         }
     } else {
         if (!empty($name)) {
             $service = $name;
         } else {
             $service = "Generic-Service";
         }
     }
     $chain = isset($headers['Service-Chain']) ? json_decode($headers['Service-Chain']) : array();
     if (count($chain) < 1) {
         // Add the referrer to the chain if it exists
         if (isset($_SERVER['HTTP_REFERER']) && !is_null($_SERVER['HTTP_REFERER'])) {
             $ref = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST);
         } else {
             if (!empty($_SERVER['HTTP_HOST'])) {
                 $ref = parse_url($_SERVER['HTTP_HOST'], PHP_URL_HOST);
             } else {
                 $ref = "External-Request";
             }
         }
         $chain[] = $ref;
     }
     $chain[] = $service;
     self::$chain = json_encode($chain);
     $_SERVER['HTTP_SERVICE_CHAIN'] = self::$chain;
 }
예제 #2
0
 /**
  * Read average temperature value of multiple sensors
  * <pre class="POST"> POST [url]/i2c/temperature/</pre>
  *
  * @example
  * [
  *     "sensor_id"
  *   , "sensor_id"
  * ]
  *
  * @return JSON - **Object** result info
  *
  * @since   2016-02-07
  * @author  Wesley Dekkers <*****@*****.**>
  * @todo    check if id exists
  **/
 public function temperature_multiple()
 {
     try {
         $config = \Rhonda\Config::get('config');
         // Load post body
         $body = \Rhonda\RequestBody::get();
         $celsius = 0;
         $fahrenheit = 0;
         $count = count($body);
         foreach ($body as $sensor_id) {
             $sensor = new \Models\I2c();
             $sensor->id = $sensor_id;
             $sensor->path = $config->BUS_PATH;
             $temp = $sensor->get_temperature();
             $celsius = $celsius + $temp->celsius;
             $fahrenheit = $fahrenheit + $temp->fahrenheit;
         }
         $average = new \stdClass();
         $average->celsius = $celsius / $count;
         $average->fahrenheit = $fahrenheit / $count;
         echo json_encode($average);
     } catch (\Exception $e) {
         echo \Rhonda\Error::handle($e);
     }
 }
예제 #3
0
 /**
  * Requires a database config file or object to be loaded and the mysqli extension for PHP to be installed</br>
  *
  * Escape a String
  * @example
  * <code>
  *   $string = "that's all folks";
  *   $string = \Rhonda\Mysql::real_escape($string);
  * </code>
  *
  * Escape an Object
  * @example
  * <code>
  *   $object = new \stdClass();
  *   $object->thing = "it's for real";
  *   $object = \Rhonda\Mysql::real_escape($object);
  * </code>
  *
  * Escape an Array
  * @example
  * <code>
  * $array = array(
  *    "ray"=>"it's escaping arrays"
  *  , "ray2"=>"escape's this one too"
  * );
  * $array = \Rhonda\Mysql::real_escape($ray);
  *
  * @return Type - Mysql escaped resource that was operated on
  *
  * @since   2015-11-20
  * @author  Deac Karns <*****@*****.**> 
  **/
 public static function real_escape($thing)
 {
     // check that a configuration object exists for DB
     try {
         $db = \Rhonda\Config::get('DB')->connections->local;
     } catch (\Exception $e) {
         echo \Rhonda\Error::handle($e);
     }
     $mysqli = new \mysqli($db->host, $db->user, $db->password, $db->database, $db->port);
     $mysqli->set_charset("utf8");
     if ($mysqli->connect_errno) {
         echo \Rhonda\Error::handle($mysqli->connect_error);
     }
     // test the thing that is coming in
     switch (gettype($thing)) {
         case 'string':
             $escaped = $mysqli->real_escape_string($thing);
             break;
         case 'object':
             $escaped = self::escape_collection($thing, $mysqli);
             break;
         case 'array':
             $escaped = self::escape_collection($thing, $mysqli);
             break;
         default:
             $escaped = $thing;
             break;
     }
     return $escaped;
 }
 /**
  * Write a pin value
  * <pre class="PUT"> PUT [url]/gpio/write/:pin/:value/</pre>
  *
  * @param String - pin number
  * @param String - value
  *
  * @example
  * No POST Body
  *
  * @return JSON - **Object** success message
  *
  * @since   2016-02-05
  * @author  Wesley Dekkers <*****@*****.**>
  * @todo    check if values are set correctly
  * @todo    check if pin exists
  **/
 public function send($id)
 {
     try {
         $config = \Rhonda\Config::get('config');
         $send = new \Models\RFID();
         $send->id = $id;
         $send->path = $config->RFID_PATH;
         $send->send();
         echo \Rhonda\Success::create();
     } catch (\Exception $e) {
         echo \Rhonda\Error::handle($e);
     }
 }
예제 #5
0
파일: Mysql.php 프로젝트: peledies/rhonda
<?php

echo "<h3>\\Rhonda\\Mysql</h3>";
// Mysql escape
$object = json_decode('{
  "connections": {
    "local": {
      "host": "192.168.99.100"
    , "database": "core_elguapo"
    , "port": "3306"
    , "user": "******"
    , "password": "******"
    }
  }
}');
\Rhonda\Config::load_object('DB', $object);
echo \Rhonda\Mysql::real_escape("that's all folks");
$object = new \stdClass();
$object->obj = "it's fo sho";
$object->obj2 = "escape's this one too";
$array = array("ray" => "it's escaping arrays", "ray2" => "escape's this one too");
echo "<pre>" . print_r(\Rhonda\Mysql::real_escape($object), true) . "</pre>";
echo "<pre>" . print_r(\Rhonda\Mysql::real_escape($array), true) . "</pre>";
echo "</br>Convert 'TRUE' to string: " . \Rhonda\Mysql::bool_to_string('TRUE');
echo "</br>Convert 'FALSE' to string: " . \Rhonda\Mysql::bool_to_string('FALSE');
echo "</br>Convert 'true' to string: " . \Rhonda\Mysql::bool_to_string('true');
echo "</br>Convert 'false' to string: " . \Rhonda\Mysql::bool_to_string('false');
echo "</br>Convert '0' to string: " . \Rhonda\Mysql::bool_to_string('0');
echo "</br>Convert '1' to string: " . \Rhonda\Mysql::bool_to_string('1');
echo "</br>Convert 'asdfghq' to string: " . \Rhonda\Mysql::bool_to_string('asdfhg');
echo "</br>Convert '' to string: " . \Rhonda\Mysql::bool_to_string('');
예제 #6
0
파일: Google.php 프로젝트: peledies/rhonda
 /**
  * Load address info based on basic address data
  *
  * @example
  * <code>
  * \Rhonda\Google:: geo_code(API_KEY, $params);
  * </code>
  *
  * @param String - Google API Key
  * @param Array  - of Parameters such as Address, city, zip
  *
  * @uses For error codes: https://developers.google.com/maps/documentation/geocoding/intro#StatusCodes
  * @uses For API Key: https://developers.google.com/maps/documentation/geocoding/get-api-key#get-an-api-key
  *
  * @example
  * Return body
  * <code>
  * {
  *   "results" : [
  *      {
  *         "address_components" : [
  *            {
  *               "long_name" : "1600",
  *               "short_name" : "1600",
  *               "types" : [ "street_number" ]
  *            },
  *            {
  *               "long_name" : "Amphitheatre Pkwy",
  *               "short_name" : "Amphitheatre Pkwy",
  *               "types" : [ "route" ]
  *            },
  *            {
  *               "long_name" : "Mountain View",
  *               "short_name" : "Mountain View",
  *               "types" : [ "locality", "political" ]
  *            },
  *            {
  *               "long_name" : "Santa Clara County",
  *               "short_name" : "Santa Clara County",
  *               "types" : [ "administrative_area_level_2", "political" ]
  *            },
  *            {
  *               "long_name" : "California",
  *               "short_name" : "CA",
  *               "types" : [ "administrative_area_level_1", "political" ]
  *            },
  *            {
  *               "long_name" : "United States",
  *               "short_name" : "US",
  *               "types" : [ "country", "political" ]
  *            },
  *            {
  *               "long_name" : "94043",
  *               "short_name" : "94043",
  *               "types" : [ "postal_code" ]
  *            }
  *         ],
  *         "formatted_address" : "1600 Amphitheatre Parkway, Mountain View, CA 94043, USA",
  *         "geometry" : {
  *            "location" : {
  *               "lat" : 37.4224764,
  *               "lng" : -122.0842499
  *            },
  *            "location_type" : "ROOFTOP",
  *            "viewport" : {
  *               "northeast" : {
  *                  "lat" : 37.42382538,
  *                  "lng" : -122.08290
  *               },
  *               "southwest" : {
  *                  "lat" : 37.4211274197085,
  *                  "lng" : -122.0855988802915
  *               }
  *            }
  *         },
  *         "place_id" : "ChIJ2eUgeAK6j4ARbn5u_wAGqWA",
  *         "types" : [ "street_address" ]
  *      }
  *   ],
  *   "status" : "OK"
  * }
  * </code>
  *
  * @return **Object** with specific address data
  *
  * @since   2016-07-18
  * @author  Wesley Dekkers <*****@*****.**> 
  **/
 public static function geo_code($key = NULL, $params = NULL)
 {
     // Make a valid query string so Google will accept this
     $query_string = self::prepare_query_string($params);
     // Check if key is set
     $key = $key ? $key : \Rhonda\Config::get('system')->google_api_key;
     // Load the basic url
     $request_url = 'https://maps.googleapis.com/maps/api/geocode/json';
     // Load the paramaters + key
     $request_options = '?address=' . $query_string . '&key=' . $key;
     $result = json_decode(file_get_contents($request_url . "" . $request_options));
     if ($result->status != "OK") {
         throw new \Exception("Google API Error: " . $result->status . ", " . $result->error_message);
     }
     return $result;
 }
예제 #7
0
<?php

echo "<h3>\\Rhonda\\Config</h3>";
// Load an object into memory for later retrieval
$object = new stdClass();
$object->thing_1 = 'something one';
$object->thing_2 = 'something two';
\Rhonda\Config::load_object('test_one', $object);
// Retrieve a configuration object from memory
echo "<pre>";
print_r(\Rhonda\Config::get('test_one'));
echo "</pre>";
$config = new \Rhonda\Config();
$config->load_object('test_two', $object);
echo "<pre>";
print_r($config->get('test_two'));
echo "</pre>";
예제 #8
-1
<?php

// CORS when your origin is not localhost you are going to need this or else it will not work.
// if you are using it outside of your home network please reconsider the * of allow origin
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: POST, PUT, DELETE, GET, OPTIONS");
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization, auth, user");
header("Access-Control-Max-Age: 1728000");
// Load the composer autoloader
require __DIR__ . '/../../vendor/autoload.php';
\Rhonda\Config::load_file("config", "../../etc/config.json");
// Create Router instance
$router = new \Bramus\Router\Router();
// Define controllers
include 'modules/gpio/controller.gpio.php';
include 'modules/rfid/controller.rfid.php';
include 'modules/switch/controller.switch.php';
include 'modules/i2c/controller.i2c.php';
include 'modules/onkyo/controller.onkyo.php';
// Define models
include 'modules/gpio/model.gpio.php';
include 'modules/rfid/model.rfid.php';
include 'modules/i2c/model.i2c.php';
include 'modules/onkyo/model.onkyo.php';
// Define routes
require 'routes.php';
header('Content-Type: application/json');
// Run it!
$router->run();