Exemplo n.º 1
0
function radiorelay_plugin_action()
{
    global $_, $conf, $myUser;
    //Action de réponse à la commande vocale "Yana, commande de test"
    switch ($_['action']) {
        case 'radioRelay_save_radioRelay':
            Action::write(function ($_, &$response) {
                $radioRelayManager = new RadioRelay();
                if (empty($_['nameRadioRelay'])) {
                    throw new Exception("Le nom est obligatoire");
                }
                if (!is_numeric($_['radioCodeRadioRelay'])) {
                    throw new Exception("Le code radio est obligatoire et doit être numerique");
                }
                $radioRelay = !empty($_['id']) ? $radioRelayManager->getById($_['id']) : new RadioRelay();
                $radioRelay->name = $_['nameRadioRelay'];
                $radioRelay->description = $_['descriptionRadioRelay'];
                $radioRelay->room = $_['roomRadioRelay'];
                $radioRelay->pulse = $_['pulseRadioRelay'];
                $radioRelay->onCommand = $_['onRadioRelay'];
                $radioRelay->offCommand = $_['offRadioRelay'];
                $radioRelay->icon = $_['iconRadioRelay'];
                $radioRelay->radiocode = $_['radioCodeRadioRelay'];
                $radioRelay->save();
                $response['message'] = 'Relais enregistré avec succès';
            }, array('plugin_radiorelay' => 'c'));
            break;
        case 'radioRelay_delete_radioRelay':
            Action::write(function ($_, $response) {
                $radioRelayManager = new RadioRelay();
                $radioRelayManager->delete(array('id' => $_['id']));
            }, array('plugin_radiorelay' => 'd'));
            break;
        case 'radioRelay_plugin_setting':
            Action::write(function ($_, &$response) {
                global $conf;
                $conf->put('plugin_radioRelay_emitter_pin', $_['emiterPin']);
                $conf->put('plugin_radioRelay_emitter_code', $_['emiterCode']);
                $response['message'] = 'Configuration enregistrée';
            }, array('plugin_radiorelay' => 'c'));
            break;
        case 'radioRelay_manual_change_state':
            Action::write(function ($_, &$response) {
                radiorelay_plugin_change_state($_['engine'], $_['state']);
            }, array('plugin_radiorelay' => 'c'));
            break;
        case 'radioRelay_vocal_change_state':
            global $_, $myUser;
            try {
                $response['responses'][0]['type'] = 'talk';
                if (!$myUser->can('plugin_radiorelay', 'u')) {
                    throw new Exception('Je ne vous connais pas, ou alors vous n\'avez pas le droit, je refuse de faire ça!');
                }
                radiorelay_plugin_change_state($_['engine'], $_['state']);
                $response['responses'][0]['sentence'] = Personality::response('ORDER_CONFIRMATION');
            } catch (Exception $e) {
                $response['responses'][0]['sentence'] = Personality::response('WORRY_EMOTION') . '! ' . $e->getMessage();
            }
            $json = json_encode($response);
            echo $json == '[]' ? '{}' : $json;
            break;
        case 'radioRelay_plugin_setting':
            Action::write(function ($_, &$response) {
                global $conf;
                $conf->put('plugin_radioRelay_emitter_pin', $_['emiterPin']);
                $conf->put('plugin_radioRelay_emitter_code', $_['emiterCode']);
                $response['message'] = 'Configuration modifiée avec succès';
            }, array('plugin_radiorelay' => 'u'));
            break;
        case 'radioRelay_load_widget':
            require_once dirname(__FILE__) . '/../dashboard/Widget.class.php';
            Action::write(function ($_, &$response) {
                $widget = new Widget();
                $widget = $widget->getById($_['id']);
                $data = $widget->data();
                $content = '';
                if (empty($data['relay'])) {
                    $content = 'Choisissez un relais en cliquant sur l \'icone <i class="fa fa-wrench"></i> de la barre du widget';
                } else {
                    if (fileperms(Plugin::path() . 'radioEmission') != '36333') {
                        $content .= '<div style="margin:0px;" class="flatBloc pink-color">Attention, les droits vers le fichier <br/> radioEmission sont mal réglés.<br/> Référez vous à <span style="cursor:pointer;text-decoration:underline;" onclick="window.location.href=\'https://github.com/ldleman/yana-server#installation\';">la doc</span> pour les régler</div>';
                    }
                    $relay = new RadioRelay();
                    $relay = $relay->getById($data['relay']);
                    $response['title'] = $relay->name;
                    $content .= '
						<!-- CSS -->
						<style>
							
							.radiorelay_relay_pane {
							    background: none repeat scroll 0 0 #50597b;
							    list-style-type: none;
							    margin: 0;
							    cursor:default;
							    width: 100%;
							}
							.radiorelay_relay_pane li {
							    background: none repeat scroll 0 0 #50597b;
							    display: inline-block;
							    margin: 0 1px 0 0;
							    padding: 10px;
							    cursor:default;
							    vertical-align: top;
							}
							.radiorelay_relay_pane li h2 {
							    color: #ffffff;
							    font-size: 16px;
							    margin: 0 0 5px;
							    padding: 0;
							    cursor:default;
							}
							.radiorelay_relay_pane li h1 {
							    color: #B6BED9;
							    font-size: 14px;
							    margin: 0 0 10px;
							    padding: 0;
							    cursor:default;
							}

							.radiorelay_relay_pane li.radiorelay-case{
								background-color:  #373f59;
								width: 55px;
								cursor:pointer;
							}
							.radiorelay-case i{
								color:#8b95b8;
								font-size:50px;
								transition: all 0.2s ease-in-out;
							}
							.radiorelay-case.active i{
								color:#ffffff;
								text-shadow: 0 0 10px #ffffff;
							}

							.radiorelay-case.active i.fa-lightbulb-o{
								color:#FFED00;
								text-shadow: 0 0 10px #ffdc00;
							}
							.radiorelay-case.active i.fa-power-off{
								color:#BDFF00;
								text-shadow: 0 0 10px #4fff00;
							}

							.radiorelay-case.active i.fa-flash{
								color:#FFFFFF;
								text-shadow: 0 0 10px #00FFD9;
							}

							.radiorelay-case.active i.fa-gears{
								color:#FFFFFF;
								text-shadow: 0 0 10px #FF00E4;
							}

						</style>
						
						<!-- CSS -->
						<ul class="radiorelay_relay_pane">
								<li class="radiorelay-case ' . ($relay->state ? 'active' : '') . '" onclick="plugin_radiorelay_change(this,' . $relay->id . ');" style="text-align:center;">
									<i title="On/Off" class="' . $relay->icon . '"></i>
								</li>
								<li>
									<h2>' . $relay->description . '</h2>
									<h1>CODE ' . $relay->radiocode . ($relay->pulse != 0 ? ' - Pulse ' . $relay->pulse . 'µs' : '') . '</h1>
								</li>
							</ul>

						<!-- JS -->
						<script type="text/javascript">
							function plugin_radiorelay_change(element,id){
								var state = $(element).hasClass(\'active\') ? 0 : 1 ;

								$.action(
									{
										action : \'radioRelay_manual_change_state\', 
										engine: id,
										state: state
									},
									function(response){
										$(element).toggleClass("active");
									}
								);

							}
						</script>
						';
                }
                $response['content'] = $content;
            });
            break;
        case 'radioRelay_edit_widget':
            require_once dirname(__FILE__) . '/../dashboard/Widget.class.php';
            $widget = new Widget();
            $widget = $widget->getById($_['id']);
            $data = $widget->data();
            $relayManager = new RadioRelay();
            $relays = $relayManager->populate();
            $content = '<h3>Relais ciblé</h3>';
            if (count($relays) == 0) {
                $content = 'Aucun relais existant dans yana, <a href="setting.php?section=radioRelay">Créer un relais ?</a>';
            } else {
                $content .= '<select id="relay">';
                $content .= '<option value="">-</option>';
                foreach ($relays as $relay) {
                    $content .= '<option value="' . $relay->id . '">' . $relay->name . '</option>';
                }
                $content .= '</select>';
            }
            echo $content;
            break;
        case 'radioRelay_save_widget':
            require_once dirname(__FILE__) . '/../dashboard/Widget.class.php';
            $widget = new Widget();
            $widget = $widget->getById($_['id']);
            $data = $widget->data();
            $data['relay'] = $_['relay'];
            $widget->data($data);
            $widget->save();
            echo $content;
            break;
    }
}
Exemplo n.º 2
0
function story_plugin_action()
{
    global $_, $myUser;
    switch ($_['action']) {
        case 'plugin_story_get_type_template':
            Action::write(function ($_, &$response) {
                $templates = array_merge(Cause::types(), Effect::types());
                $template = $templates[$_['type']];
                preg_match_all("/(\\{)(.*?)(\\})/", $template['template'], $matches, PREG_SET_ORDER);
                foreach ($matches as $match) {
                    $template['template'] = str_replace($match[0], $_['data'][$match[2]], $template['template']);
                }
                /*
                $matches = preg_split("/\[(.*?)\]/", $template['template'],-1,PREG_SPLIT_DELIM_CAPTURE);
                
                $tpl = '';
                
                for($i=0;$i<count($matches);$i+=2){
                	$start = $matches[$i];
                	$var = $matches[$i+1];
                	list($name,$value) = explode(':',$var);
                	
                	
                	if($_['data'][$name] == $value) {
                		
                		$tpl.= 'selected="selected"';
                	}
                	$tpl.= $start;
                }
                $template['template'] = $tpl;
                */
                $response['html'] = '<li class="line" data-type="' . $_['type'] . '">
						<i class="fa ' . $template['icon'] . '"></i> <strong>' . $template['label'] . '</strong> ' . $template['template'] . ' <div class="delete"><i onclick="deleteLine(this);" class="fa fa-times"></i></div>
					</li>';
            }, array());
            break;
        case 'plugin_story_get_causes_effects':
            Action::write(function ($_, &$response) {
                $cause = new Cause();
                $effect = new Effect();
                $effects = $effect->loadAll(array('story' => $_['id']), 'sort');
                $causes = $cause->loadAll(array('story' => $_['id']), 'sort');
                foreach ($causes as $caus) {
                    $data = $caus->getValues();
                    $response['results'][] = array('type' => $caus->type, 'panel' => "CAUSE", 'data' => array('value' => $data->value, 'target' => $data->target, 'operator' => $data->operator, 'union' => $data->union));
                }
                foreach ($effects as $eff) {
                    $data = $eff->getValues();
                    $response['results'][] = array('type' => $eff->type, 'panel' => "EFFECT", 'data' => array('value' => $data->value, 'target' => $data->target, 'operator' => $data->operator, 'union' => $data->union));
                }
            }, array());
            break;
        case 'plugin_story_get_captors_plugins':
            Action::write(function ($_, &$response) {
                $deviceManager = new Device();
                $devices = $deviceManager->loadAll(array('state' => 1, 'type' => Device::CAPTOR));
                $response['plugins'] = array();
                foreach ($devices as $device) {
                    if (!isset($response['plugins'][$device->plugin])) {
                        $response['plugins'][] = $device->plugin;
                    }
                }
            }, array());
            break;
        case 'plugin_story_get_captors':
            Action::write(function ($_, &$response) {
                $deviceManager = new Device();
                $devices = $deviceManager->loadAll(array('state' => 1, 'plugin' => $_['plugin'], 'type' => Device::CAPTOR));
                foreach ($devices as $device) {
                    $response['devices'][] = array('plugin' => $device->plugin, 'label' => $device->label, 'id' => $device->id);
                }
            }, array());
            break;
        case 'plugin_story_get_captor_values':
            Action::write(function ($_, &$response) {
                $deviceManager = new Device();
                $device = $deviceManager->getById($_['id']);
                $response['values'] = $device->getValues();
            }, array());
            break;
        case 'plugin_story_delete_story':
            Action::write(function ($_, &$response) {
                $storyManager = new Story();
                $causeManager = new Cause();
                $effectManager = new Effect();
                $storyManager->delete(array('id' => $_['id']));
                $causeManager->delete(array('story' => $_['id']));
                $effectManager->delete(array('story' => $_['id']));
            }, array());
            break;
        case 'plugin_story_check':
            require_once dirname(__FILE__) . '/Cause.class.php';
            $vocal = new Cause();
            $vocal = $vocal->getById($_['event']);
            Story::check($vocal);
            break;
        case 'plugin_story_save_story':
            Action::write(function ($_, &$response) {
                $causeManager = new Cause();
                $effectManager = new Effect();
                $story = new Story();
                if (isset($_['story']['id']) && $_['story']['id'] != '0') {
                    $story = $story->getById($_['story']['id']);
                    $causeManager->delete(array('story' => $story->id));
                    $effectManager->delete(array('story' => $story->id));
                }
                $story->label = $_['story']['label'];
                $story->date = time();
                $story->state = 1;
                $story->save();
                $i = 0;
                foreach ($_['story']['causes'] as $cause) {
                    $current = new Cause();
                    $current->type = $cause['type'];
                    $current->operator = @$cause['operator'];
                    $current->setValues($cause);
                    $current->sort = $i;
                    $current->union = $cause['union'];
                    $current->story = $story->id;
                    $current->save();
                    $i++;
                }
                $i = 0;
                foreach ($_['story']['effects'] as $effect) {
                    $current = new Effect();
                    $current->type = $effect['type'];
                    $current->setValues($effect);
                    $current->sort = $i;
                    $current->union = $cause['union'];
                    $current->story = $story->id;
                    $current->save();
                    $i++;
                }
            }, array());
            break;
    }
}
Exemplo n.º 3
0
function wirerelay_plugin_action()
{
    global $_, $conf, $myUser;
    //Action de réponse à la commande vocale "Yana, commande de test"
    switch ($_['action']) {
        case 'wireRelay_save_wireRelay':
            Action::write(function ($_, &$response) {
                $wireRelayManager = new WireRelay();
                if (empty($_['nameWireRelay'])) {
                    throw new Exception("Le nom est obligatoire");
                }
                if (!is_numeric($_['pinWireRelay'])) {
                    throw new Exception("Le PIN GPIO est obligatoire et doit être numerique");
                }
                $wireRelay = !empty($_['id']) ? $wireRelayManager->getById($_['id']) : new WireRelay();
                $wireRelay->name = $_['nameWireRelay'];
                $wireRelay->description = $_['descriptionWireRelay'];
                $wireRelay->pin = $_['pinWireRelay'];
                $wireRelay->room = $_['roomWireRelay'];
                $wireRelay->pulse = $_['pulseWireRelay'];
                $wireRelay->oncommand = $_['onWireRelay'];
                $wireRelay->offcommand = $_['offWireRelay'];
                $wireRelay->icon = $_['iconWireRelay'];
                $wireRelay->save();
                //Reference device for other plugins
                $device = new Device();
                $device->label = $wireRelay->name;
                $device->plugin = 'wireRelay';
                $device->type = Device::ACTUATOR;
                $device->location = $wireRelay->room;
                $device->icon = $wireRelay->icon;
                $device->setValue('value', 0);
                $device->state = 1;
                $device->uid = $wireRelay->id;
                $device->save();
                $response['message'] = 'Relais enregistré avec succès';
            }, array('plugin_wirerelay' => 'c'));
            break;
        case 'wireRelay_delete_wireRelay':
            Action::write(function ($_, $response) {
                $wireRelayManager = new WireRelay();
                $wireRelayManager->delete(array('id' => $_['id']));
            }, array('plugin_wirerelay' => 'd'));
            break;
        case 'wireRelay_plugin_setting':
            Action::write(function ($_, $response) {
                $conf->put('plugin_wireRelay_emitter_pin', $_['emiterPin']);
                $conf->put('plugin_wireRelay_emitter_code', $_['emiterCode']);
            }, array('plugin_wirerelay' => 'c'));
            break;
        case 'wireRelay_manual_change_state':
            Action::write(function ($_, &$response) {
                wirerelay_plugin_change_state($_['engine'], $_['state']);
            }, array('plugin_wirerelay' => 'c'));
            break;
        case 'wireRelay_vocal_change_state':
            global $_, $myUser;
            try {
                $response['responses'][0]['type'] = 'talk';
                if (!$myUser->can('plugin_wirerelay', 'u')) {
                    throw new Exception('Je ne vous connais pas, ou alors vous n\'avez pas le droit, je refuse de faire ça!');
                }
                wirerelay_plugin_change_state($_['engine'], $_['state']);
                $response['responses'][0]['sentence'] = Personality::response('ORDER_CONFIRMATION');
            } catch (Exception $e) {
                $response['responses'][0]['sentence'] = Personality::response('WORRY_EMOTION') . '! ' . $e->getMessage();
            }
            $json = json_encode($response);
            echo $json == '[]' ? '{}' : $json;
            break;
        case 'wireRelay_load_widget':
            require_once dirname(__FILE__) . '/../dashboard/Widget.class.php';
            Action::write(function ($_, &$response) {
                $widget = new Widget();
                $widget = $widget->getById($_['id']);
                $data = $widget->data();
                if (empty($data['relay'])) {
                    $content = 'Choisissez un relais en cliquant sur l \'icone <i class="fa fa-wrench"></i> de la barre du widget';
                } else {
                    $relay = new WireRelay();
                    $relay = $relay->getById($data['relay']);
                    $response['title'] = $relay->name;
                    $content = '
						<!-- CSS -->
						<style>
							
							.relay_pane {
							    background: none repeat scroll 0 0 #50597b;
							    list-style-type: none;
							    margin: 0;
							    cursor:default;
							    width: 100%;
							}
							.relay_pane li {
							    background: none repeat scroll 0 0 #50597b;
							    display: inline-block;
							    margin: 0 1px 0 0;
							    padding: 10px;
							    cursor:default;
							    vertical-align: top;
							}
							.relay_pane li h2 {
							    color: #ffffff;
							    font-size: 16px;
							    margin: 0 0 5px;
							    padding: 0;
							    cursor:default;
							}
							.relay_pane li h1 {
							    color: #B6BED9;
							    font-size: 14px;
							    margin: 0 0 10px;
							    padding: 0;
							    cursor:default;
							}

							.relay_pane li.wirerelay-case{
								background-color:  #373f59;
								cursor:pointer;
								width: 55px;
							}
							.wirerelay-case i{
								color:#8b95b8;
								font-size:50px;
								transition: all 0.2s ease-in-out;
							}
							.wirerelay-case.active i{
								color:#ffffff;
								text-shadow: 0 0 10px #ffffff;
							}

							.wirerelay-case.active i.fa-lightbulb-o{
								color:#FFED00;
								text-shadow: 0 0 10px #ffdc00;
							}
							.wirerelay-case.active i.fa-power-off{
								color:#BDFF00;
								text-shadow: 0 0 10px #4fff00;
							}

							.wirerelay-case.active i.fa-flash{
								color:#FFFFFF;
								text-shadow: 0 0 10px #00FFD9;
							}

							.wirerelay-case.active i.fa-gears{
								color:#FFFFFF;
								text-shadow: 0 0 10px #FF00E4;
							}

						</style>
						
						<!-- CSS -->
						<ul class="relay_pane">
								<li class="wirerelay-case ' . (Gpio::read($relay->pin, true) ? 'active' : '') . '" onclick="plugin_wirerelay_change(this);" style="text-align:center;">
									<i title="On/Off" class="' . $relay->icon . '"></i>
								</li>
								<li>
									<h2>' . $relay->description . '</h2>
									<h1>PIN ' . $relay->pin . ($relay->pulse != 0 ? ' - Pulse ' . $relay->pulse . 'µs' : '') . '</h1>
								</li>
							</ul>

						<!-- JS -->
						<script type="text/javascript">
							function plugin_wirerelay_change(element){
								var state = $(element).hasClass(\'active\') ? 0 : 1 ;

								$.action(
									{
										action : \'wireRelay_manual_change_state\', 
										engine: ' . $relay->id . ',
										state: state
									},
									function(response){
										$(element).toggleClass("active");
									}
								);

							}
						</script>
						';
                }
                $response['content'] = $content;
            });
            break;
        case 'wireRelay_edit_widget':
            require_once dirname(__FILE__) . '/../dashboard/Widget.class.php';
            $widget = new Widget();
            $widget = $widget->getById($_['id']);
            $data = $widget->data();
            $relayManager = new WireRelay();
            $relays = $relayManager->populate();
            $content = '<h3>Relais ciblé</h3>';
            if (count($relays) == 0) {
                $content = 'Aucun relais existant dans yana, <a href="setting.php?section=wireRelay">Créer un relais ?</a>';
            } else {
                $content .= '<select id="relay">';
                $content .= '<option value="">-</option>';
                foreach ($relays as $relay) {
                    $content .= '<option value="' . $relay->id . '">' . $relay->name . '</option>';
                }
                $content .= '</select>';
            }
            echo $content;
            break;
        case 'wireRelay_save_widget':
            require_once dirname(__FILE__) . '/../dashboard/Widget.class.php';
            $widget = new Widget();
            $widget = $widget->getById($_['id']);
            $data = $widget->data();
            $data['relay'] = $_['relay'];
            $widget->data($data);
            $widget->save();
            echo $content;
            break;
    }
}
Exemplo n.º 4
0
function ipcam_action()
{
    global $_, $conf;
    switch ($_['action']) {
        case 'ipcam_save_camera':
            Action::write(function ($_, &$response) {
                require_once 'Camera.class.php';
                $camera = new Camera();
                if (empty($_['labelCamera'])) {
                    throw new Exception("Le nom est obligatoire");
                }
                if (empty($_['ipCamera'])) {
                    throw new Exception("L'IP est obligatoire");
                }
                $camera = !empty($_['id']) ? $camera->getById($_['id']) : new Camera();
                $camera->label = $_['labelCamera'];
                $camera->location = $_['locationCamera'];
                $camera->ip = $_['ipCamera'];
                $camera->login = $_['loginCamera'];
                $camera->password = $_['passwordCamera'];
                $camera->save();
                $response['message'] = 'Caméra enregistrée avec succès';
            }, array('ipcam' => 'c'));
            break;
        case 'ipcam_delete_camera':
            Action::write(function ($_, $response) {
                require_once 'Camera.class.php';
                $camera = new Camera();
                $camera->delete(array('id' => $_['id']));
            }, array('ipcam' => 'd'));
            break;
        case 'ipcam_load_widget':
            require_once dirname(__FILE__) . '/../dashboard/Widget.class.php';
            Action::write(function ($_, &$response) {
                $widget = new Widget();
                $widget = $widget->getById($_['id']);
                $parameters = $widget->data();
                if (empty($parameters['camera'])) {
                    $content = 'Choisissez une camera en cliquant sur l \'icone <i class="fa fa-wrench"></i> de la barre du widget';
                } else {
                    global $conf;
                    require_once 'Camera.class.php';
                    $camera = new Camera();
                    $camera = $camera->getById($parameters['camera']);
                    $room = new Room();
                    $room = $room->getById($camera->location);
                    $response['title'] = 'Sonde ' . $camera->label . ' (' . $room->getName() . ')';
                    $content = '
						<!-- CSS -->
						<style>
						</style>
						
						<!-- HTML -->
						';
                    $content .= '<div class="ipcam_widget"><img name="main" id="main" border="0" src="http://' . $camera->login . ':' . $camera->password . '@' . $camera->ip . '/videostream.cgi">';
                    $content .= '</div>';
                    $content .= '
						<!-- JS -->
						<script type="text/javascript">
						</script>
						';
                }
                $response['content'] = $content;
            });
            break;
        case 'ipcam_edit_widget':
            require_once dirname(__FILE__) . '/../dashboard/Widget.class.php';
            require_once dirname(__FILE__) . '/Camera.class.php';
            $widget = new Widget();
            $widget = $widget->getById($_['id']);
            $data = $widget->data();
            $camera = new Camera();
            $cameras = $camera->populate();
            $content = '<h3>Choix de la camera</h3>';
            if (count($cameras) == 0) {
                $content = 'Aucune camera enregistrée,<a href="setting.php?section=ipcam">enregistrer une camera<a>';
            } else {
                $content .= '<select id="camera">';
                foreach ($cameras as $camera) {
                    $content .= '<option ' . ($camera->id == $data['camera'] ? 'selected="selected"' : '') . ' value="' . $camera->id . '">' . $camera->label . ' (' . $camera->uid . ')</option>';
                }
                $content .= '</select>';
            }
            echo $content;
            break;
        case 'ipcam_save_widget':
            require_once dirname(__FILE__) . '/../dashboard/Widget.class.php';
            $widget = new Widget();
            $widget = $widget->getById($_['id']);
            $data = $widget->data();
            $data['camera'] = $_['camera'];
            $widget->data($data);
            $widget->save();
            echo $content;
            break;
    }
}
Exemplo n.º 5
0
        } else {
            Gpio::write($_["pin"], $_["state"], true);
        }
        break;
        // Gestion des interfaces de seconde génération
    // Gestion des interfaces de seconde génération
    case 'SUBSCRIBE_TO_CLIENT':
        Action::write(function ($_, &$response) {
            global $myUser, $conf;
            if (!isset($_['ip'])) {
                throw new Exception("IP invalide");
            }
            if (!isset($_['port']) || !is_numeric($_['port'])) {
                throw new Exception("Port invalide");
            }
            $url = Functions::getBaseUrl('action.php') . '/action.php';
            $client = new CLient($_['ip'], $_['port']);
            Plugin::callHook("vocal_command", array(&$vocal, $url));
            $conf = array('VOCAL_ENTITY_NAME' => $conf->put('VOCAL_ENTITY_NAME', 'YANA'), 'SPEECH_COMMAND' => $vocal);
            if (!$client->suscribe($url, $myUser->getToken())) {
                throw new Exception("Appairage impossible");
            }
            if (!$client->configure($conf)) {
                throw new Exception("Configuration impossible");
            }
        }, array('user' => 'u'));
        break;
    default:
        Plugin::callHook("action_post_case", array());
        break;
}
Exemplo n.º 6
0
            } else {
                Functions::rmFullDir($tempZipFolder);
                echo '<br/>Impossible de renommer le plugin <span class="label label-error">Erreur</span>';
            }
            unlink($tempZipName);
        } catch (Exception $e) {
            echo '<br/>' . $e->getMessage() . ' <span class="label label-error">Erreur</span>';
        }
        break;
    case 'CHANGE_GPIO_STATE':
        if ($myUser == false) {
            exit('Vous devez vous connecter pour cette action.');
        } else {
            Gpio::write($_["pin"], $_["state"], true);
        }
        break;
        // Gestion des interfaces de seconde génération
    // Gestion des interfaces de seconde génération
    case 'ADD_CLIENT':
        Action::write(function ($_, &$response) {
            global $myUser, $conf, $client;
            if (!isset($_SERVER['argv'][2])) {
                throw new Exception("Type client invalide");
            }
            file_put_contents('filename', $_SERVER['argv'][2]);
        });
        break;
    default:
        Plugin::callHook("action_post_case", array());
        break;
}
Exemplo n.º 7
0
function propise_action()
{
    global $_, $conf;
    switch ($_['action']) {
        case 'propise_save_sensor':
            Action::write(function ($_, &$response) {
                require_once 'Sensor.class.php';
                $sensor = new Sensor();
                if (empty($_['labelSensor'])) {
                    throw new Exception("Le nom est obligatoire");
                }
                if (empty($_['uidSensor'])) {
                    throw new Exception("L'UID est obligatoire");
                }
                $sensor = !empty($_['id']) ? $sensor->getById($_['id']) : new Sensor();
                $sensor->label = $_['labelSensor'];
                $sensor->location = $_['locationSensor'];
                $sensor->uid = $_['uidSensor'];
                $sensor->save();
                //Reference device for other plugins
                $device = new Device();
                $device->label = $sensor->label;
                $device->plugin = 'propise';
                $device->type = Device::CAPTOR;
                $device->location = $sensor->location;
                $device->icon = 'fa-heartbeat';
                $device->setValue('humidity', 0);
                $device->setValue('temperature', 0);
                $device->setValue('light', 0);
                $device->setValue('mouvment', 0);
                $device->setValue('sound', 0);
                $device->state = 1;
                $device->uid = $sensor->id;
                $device->save();
                $response['message'] = 'Sonde enregistrée avec succès';
            }, array('propise' => 'c'));
            break;
        case 'propise_delete_sensor':
            Action::write(function ($_, $response) {
                require_once 'Sensor.class.php';
                $sensor = new Sensor();
                $sensor->delete(array('id' => $_['id']));
            }, array('propise' => 'd'));
            break;
        case 'propise_add_data':
            /*for($i=0;$i<60;$i++){
            		$_ = array(
            		'uid'=>'sensor-2',
            		'humidity'=>rand(0,100),
            		'temperature'=>rand(0,100),
            		'light'=>rand(0,100),
            		'mouvment'=>rand(0,1),
            		'sound'=>rand(0,1)
            		);*/
            require_once 'Sensor.class.php';
            require_once 'Data.class.php';
            $sensor = new Sensor();
            $data = new Data();
            $sensor = $sensor->load(array('uid' => $_['uid']));
            if ($sensor == null || $sensor->id == 0) {
                return;
            }
            $data->time = time();
            //$data->time = strtotime(date('Ymd H:').$i.':00');
            $data->humidity = $_['humidity'];
            $data->temperature = $_['temperature'];
            $data->light = $_['light'];
            $data->mouvment = $_['mouvment'];
            $data->sound = $_['sound'];
            $data->sensor = $sensor->id;
            $data->save();
            //}
            break;
        case 'propise_load_widget':
            require_once dirname(__FILE__) . '/../dashboard/Widget.class.php';
            Action::write(function ($_, &$response) {
                $widget = new Widget();
                $widget = $widget->getById($_['id']);
                $parameters = $widget->data();
                if (empty($parameters['sensor'])) {
                    $content = 'Choisissez une localisation en cliquant sur l \'icone <i class="fa fa-wrench"></i> de la barre du widget';
                } else {
                    global $conf;
                    require_once 'Data.class.php';
                    require_once 'Sensor.class.php';
                    $sensor = new Sensor();
                    $data = new Data();
                    $sensor = $sensor->getById($parameters['sensor']);
                    $datas = $data->loadAll(array('sensor' => $sensor->id), 'time DESC', 1);
                    $response['title'] = 'Sonde ' . $sensor->label . ' (' . $sensor->uid . ')';
                    $content = '
						<!-- CSS -->
						<style>
							.propise_view{
								background:#36B3E1;
								color:#ffffff;
								margin:0px;
								padding:10px;
								width:100%;
								list-style-type:none;
								transition:all 0.2s ease-in-out;
								box-sizing: border-box;
							}
							.propise_menu{
								margin:0;
							}
							.propise_menu li{
								cursor: pointer;
								display: inline-block;
								font-size: 20px;
								height: 25px;
								margin-top: 3px;
								padding: 5px;
								text-align: center;
								transition: all 0.2s ease-in-out 0s;
								width: 30px;
								border-top:4px solid #cecece;
							}
							
							color: #cecece;
    
							
							.propise_menu li:hover{
								background:#222222;
								color:#ffffff;
							}
							
							.propise_view li{
								display:none;
								font-family: "Open Sans Light",sans-serif;
								text-align:center;
								padding:15px 0;
								font-weight:300;
								font-size:60px;
							}
							
							.propise_view li.propise_temperature{
								display:block;
							}
							
							.propise_menu li.propise_temperature{
								border-color:#36B3E1;
							}
							.propise_menu li.propise_humidity{
								border-color:#50597B;
							}
							.propise_menu li.propise_light{
								border-color:#EF4D66;
							}
							.propise_menu li.propise_mouvment{
								border-color:#FFBF4C;
							}
							.propise_menu li.propise_sound{
								border-color:#84C400;
							}
							.propise_menu li.propise_stats{
								border-color:#C1004F;
							}
						</style>
						
						<!-- HTML -->
						';
                    $content .= '<div class="propise_widget"><ul class="propise_view">';
                    $content .= '<li class="propise_temperature"><i class="fa fa-fire"></i> ' . round($datas[0]->temperature, 1) . '°</li>';
                    $content .= '<li class="propise_humidity"><i class="fa fa-tint"></i> ' . round($datas[0]->humidity, 1) . '%</li>';
                    $content .= '<li class="propise_light"><i class="fa fa-sun-o"></i> ' . round($datas[0]->light, 1) . '%</li>';
                    $content .= '<li class="propise_mouvment"><i class="fa fa-eye' . ($datas[0]->mouvment == 1 ? '' : '-slash') . '"></i></li>';
                    $content .= '<li class="propise_sound"><i class="fa fa-bell' . ($datas[0]->sound == 1 ? '' : '-slash') . '"></i></li>';
                    $content .= '</ul><ul class="propise_menu">';
                    $content .= '<li class="propise_temperature" onclick="propise_menu(this)" data-view="temperature"><i class="fa fa-fire"></i></li>';
                    $content .= '<li class="propise_humidity" onclick="propise_menu(this)" data-view="humidity"><i class="fa fa-tint"></i></li>';
                    $content .= '<li class="propise_light" onclick="propise_menu(this)" data-view="light"><i class="fa fa-sun-o"></i></li>';
                    $content .= '<li class="propise_mouvment" onclick="propise_menu(this)" data-view="mouvment"><i class="fa fa-eye"></i></li>';
                    $content .= '<li class="propise_sound" onclick="propise_menu(this)" data-view="sound"><i class="fa fa-bell"></i></li>';
                    $content .= '<li class="propise_stats" onclick="window.open(\'index.php?module=propise\')"><i class="fa fa-line-chart"></i></li>';
                    $content .= '</ul>';
                    $content .= '</div>';
                    $content .= '
						<!-- JS -->
						<script type="text/javascript">
							function propise_menu(element){
								var container = $(element).closest(".propise_widget");
								$(".propise_view li",container).hide();
								$(".propise_view").css("background-color",$(element).css("border-top-color"));
								$(".propise_view li.propise_"+$(element).data("view"),container).fadeIn();
							};
							
						</script>
						';
                }
                $response['content'] = $content;
            });
            break;
        case 'propise_edit_widget':
            require_once dirname(__FILE__) . '/../dashboard/Widget.class.php';
            require_once dirname(__FILE__) . '/Sensor.class.php';
            $widget = new Widget();
            $widget = $widget->getById($_['id']);
            $data = $widget->data();
            $sensor = new Sensor();
            $sensors = $sensor->populate();
            $content = '<h3>Choix de la sonde</h3>';
            if (count($sensors) == 0) {
                $content = 'Aucune sonde enregistrée,<a href="setting.php?section=propise">enregistrer une sonde<a>';
            } else {
                $content .= '<select id="sensor">';
                foreach ($sensors as $sensor) {
                    $content .= '<option ' . ($sensor->id == $data['sensor'] ? 'selected="selected"' : '') . ' value="' . $sensor->id . '">' . $sensor->label . ' (' . $sensor->uid . ')</option>';
                }
                $content .= '</select>';
            }
            echo $content;
            break;
        case 'propise_save_widget':
            require_once dirname(__FILE__) . '/../dashboard/Widget.class.php';
            $widget = new Widget();
            $widget = $widget->getById($_['id']);
            $data = $widget->data();
            $data['sensor'] = $_['sensor'];
            $widget->data($data);
            $widget->save();
            echo $content;
            break;
    }
}
Exemplo n.º 8
0
 public function write($output)
 {
     $xfer = 0;
     $xfer += $output->writeStructBegin('ActionService_get_action_result');
     if ($this->success !== null) {
         if (!is_object($this->success)) {
             throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
         }
         $xfer += $output->writeFieldBegin('success', TType::STRUCT, 0);
         $xfer += $this->success->write($output);
         $xfer += $output->writeFieldEnd();
     }
     $xfer += $output->writeFieldStop();
     $xfer += $output->writeStructEnd();
     return $xfer;
 }
Exemplo n.º 9
0
function story_plugin_action()
{
    global $_, $myUser;
    switch ($_['action']) {
        case 'plugin_story_get_type_template':
            Action::write(function ($_, &$response) {
                $templates = array_merge(Cause::types(), Effect::types());
                $template = $templates[$_['type']];
                $response['html'] = '<li class="line" data-type="' . $_['type'] . '">
						<i class="fa ' . $template['icon'] . '"></i> <strong>' . $template['label'] . '</strong> ' . $template['template'] . ' <div class="delete"><i onclick="deleteLine(this);" class="fa fa-times"></i></div>
					</li>';
            }, array());
            break;
        case 'plugin_story_get_captors_plugins':
            Action::write(function ($_, &$response) {
                $deviceManager = new Device();
                $devices = $deviceManager->loadAll(array('state' => 1, 'type' => Device::CAPTOR));
                $response['plugins'] = array();
                foreach ($devices as $device) {
                    if (!isset($response['plugins'][$device->plugin])) {
                        $response['plugins'][] = $device->plugin;
                    }
                }
            }, array());
            break;
        case 'plugin_story_get_captors':
            Action::write(function ($_, &$response) {
                $deviceManager = new Device();
                $devices = $deviceManager->loadAll(array('state' => 1, 'plugin' => $_['plugin'], 'type' => Device::CAPTOR));
                foreach ($devices as $device) {
                    $response['devices'][] = array('plugin' => $device->plugin, 'label' => $device->label, 'id' => $device->id);
                }
            }, array());
            break;
        case 'plugin_story_get_captor_values':
            Action::write(function ($_, &$response) {
                $deviceManager = new Device();
                $device = $deviceManager->getById($_['id']);
                $response['values'] = $device->getValues();
            }, array());
            break;
        case 'plugin_story_delete_story':
            Action::write(function ($_, &$response) {
                $storyManager = new Story();
                $causeManager = new Cause();
                $effectManager = new Effect();
                $storyManager->delete(array('id' => $_['id']));
                $causeManager->delete(array('story' => $_['id']));
                $effectManager->delete(array('story' => $_['id']));
            }, array());
            break;
        case 'plugin_story_check':
            require_once dirname(__FILE__) . '/Cause.class.php';
            $vocal = new Cause();
            $vocal = $vocal->getById($_['event']);
            Story::check($vocal);
            break;
        case 'plugin_story_save_story':
            Action::write(function ($_, &$response) {
                $causeManager = new Cause();
                $effectManager = new Effect();
                $story = new Story();
                if (isset($_['story']['id']) && $_['story']['id'] != '0') {
                    $story = $story->getById($_['story']['id']);
                    $causeManager->delete(array('story' => $story->id));
                    $effectManager->delete(array('story' => $story->id));
                }
                $story->label = $_['story']['label'];
                $story->date = time();
                $story->state = 1;
                $story->save();
                $i = 0;
                foreach ($_['story']['causes'] as $cause) {
                    $current = new Cause();
                    $current->type = $cause['type'];
                    $current->operator = @$cause['operator'];
                    $current->setValues($cause);
                    $current->sort = $i;
                    $current->union = $cause['union'];
                    $current->story = $story->id;
                    $current->save();
                    $i++;
                }
                $i = 0;
                foreach ($_['story']['effects'] as $effect) {
                    $current = new Effect();
                    $current->type = $effect['type'];
                    $current->setValues($effect);
                    $current->sort = $i;
                    $current->union = $cause['union'];
                    $current->story = $story->id;
                    $current->save();
                    $i++;
                }
            }, array());
            break;
    }
}