<commit_before><?php
    /*
     *      Copyright (C) 2014 <NAME> 
     *      http://jjj.fi/
     *      <EMAIL>
     *      https://github.com/jjuhala/HomeHub
     *
     *  This project is licensed under the terms of the MIT license.
     *
     */
    
class Brains {
	protected $vars = array();
	protected $arduinoReply = array();
	var $result = array(
			"status" => "error",
			"messages" => array ()
		);



	public function Run($get) {
		// Authorize request (get ['s'] must match api_secret from settings)
		$this->Authorize($get);

		// If q and msg are not set, die
		if (!isset($get['q'])) $this->kill("No cmd given");
		if (!isset($get['msg'])) $this->kill("No msg given");

		// connect database
		$this->pdo = $this->ConnectPdo();

		$wcmd = $get['q'];
		if ($wcmd == "run_action") {
			$this->RunAction($get['msg']);
		} elseif ($wcmd == "sensor_set") {
			$this->fromArduino = isset($get['f']);
			$this->SensorSet($get['msg']);
		} else {
			$this->kill('Unknown api call.');
		}
	}



	public function __construct() {
		$this->ResultPrinted = false;
		$this->fromArduino = false;
	}

	public function Authorize($get) {
		if (isset($get['s']) === false || $get['s'] !== $this->conf['api_secret']) {
			$this->kill("Invalid secret");
		}
	}


	public function SensorSet($msg) {
		// Die if msg doesn't contain :
		if (strpos($msg,':') === false) $this->kill('Message must have : as name:data delimiter');
		$name = explode(':', $msg)[0];<commit_msg>Added support for raw_cmd to api<commit_after><?php
    /*
     *      Copyright (C) 2014 <NAME> 
     *      http://jjj.fi/
     *      <EMAIL>
     *      https://github.com/jjuhala/HomeHub
     *
     *  This project is licensed under the terms of the MIT license.
     *
     */
    
class Brains {
	protected $vars = array();
	protected $arduinoReply = array();
	var $result = array(
			"status" => "error",
			"messages" => array ()
		);



	public function Run($get) {
		// Authorize request (get ['s'] must match api_secret from settings)
		$this->Authorize($get);

		// If q and msg are not set, die
		if (!isset($get['q'])) $this->kill("No cmd given");
		if (!isset($get['msg'])) $this->kill("No msg given");

		// connect database
		$this->pdo = $this->ConnectPdo();

		$wcmd = $get['q'];
		if ($wcmd == "run_action") {
			$this->RunAction($get['msg']);
		} elseif ($wcmd == "sensor_set") {
			$this->fromArduino = isset($get['f']);
			$this->SensorSet($get['msg']);
		} elseif ($wcmd == "raw_cmd") {
			$this->ExecuteCommand(urlencode($get['msg']),urlencode($get['msg']));
			$this->SetStatus('ok');
			$this->PrintResult();
		} else {
			$this->kill('Unknown api call.');
		}
	}



	public function __construct() {
		$this->ResultPrinted = false;
		$this->fromArduino = false;
	}

	public function Authorize($get) {
		if (isset($get['s']) === false || $get['s'] !== $this->conf['api_secret']) {
			$this->kill("Invalid secret");
		}
	}


	public function SensorSet($msg) {
		// Die if msg doesn't contain :
		if (strpos($msg,':') === false) $this->kill('Message must have : as name:data delimiter');
		$name = explode(':', $msg)[0];
{'fraction_non_alphanumeric': 0.2101542416452442, 'fraction_numerical': 0.003213367609254499, 'mean_word_length': 3.156208277703605, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 42, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '939680', 'n_tokens_mistral': 1175, 'n_tokens_neox': 1072, 'n_words': 254}