Esempio n. 1
0
<?php

// ./Examples/Basic.php
require __DIR__ . '/../Phpwol/Init.php';
$f = new \Phpwol\Factory();
$magicPacket = $f->magicPacket();
$macAddress = '50:46:5C:53:94:25';
$broadcastIP = '192.168.1.255';
$result = $magicPacket->send($macAddress, $broadcastIP);
if ($result) {
    echo "Worked\n";
} else {
    echo "Failed\n";
}
    /**
     * Displays the "waiting for connection" page where the user is asked to 
     * wait until the backend has been woken using WOL
     */
    public function actionWaitForConnectivity()
    {
        $backend = $this->getCurrent();
        // Determine the IP address of the backend
        if (filter_var($backend->hostname, FILTER_VALIDATE_IP)) {
            $ipAddress = $backend->hostname;
        } else {
            $ipAddress = gethostbyname($backend->hostname);
        }
        // Send the WOL packet
        $wol = new \Phpwol\Factory();
        $magicPacket = $wol->magicPacket();
        if (!$ipAddress || !$magicPacket->send($backend->macAddress, $ipAddress, $backend->subnetMask)) {
            throw new CHttpException(500, Yii::t('Backend', 'Unable to send WOL packet'));
        }
        // Start the poller which redirects once the backend is reachable
        Yii::app()->clientScript->registerScript(__CLASS__ . '_startPolling', '
			startPolling();
		', CClientScript::POS_END);
        // Render the "waiting" page
        Yii::app()->user->setFlash('error', Yii::t('Backend', 'The current backend is not connectable at the moment'));
        $this->render('waitForConnectivity');
    }
 /**
  * Displays the "waiting for connection" page where the user is asked to 
  * wait until the backend has been woken using WOL
  */
 public function actionWaitForConnectivity()
 {
     $backend = $this->getCurrent();
     // Determine the IP address of the backend
     if (filter_var($backend->hostname, FILTER_VALIDATE_IP)) {
         $ipAddress = $backend->hostname;
     } else {
         $ipAddress = gethostbyname($backend->hostname);
     }
     // Send the WOL packet
     $wol = new \Phpwol\Factory();
     $magicPacket = $wol->magicPacket();
     if (!$ipAddress || !$magicPacket->send($backend->macAddress, $ipAddress, $backend->subnetMask)) {
         throw new CHttpException(500, Yii::t('Backend', 'Unable to send WOL packet'));
     }
     // Render the "waiting" page
     Yii::app()->user->setFlash('error', Yii::t('Backend', 'The current backend is not connectable at the moment'));
     $this->render('waitForConnectivity');
 }
Esempio n. 4
0
 public function execute($_options = array())
 {
     if ($this->getType() == 'info') {
         return;
     }
     $eqLogic = $this->getEqLogic();
     if ($this->getLogicalId() == 'wol') {
         $f = new \Phpwol\Factory();
         $magicPacket = $f->magicPacket();
         $result = $magicPacket->send($eqLogic->getConfiguration('mac'), $eqLogic->getConfiguration('broadcastIP'));
         if (!$result) {
             $error = '';
             switch ($magicPacket->getLastError()) {
                 case 1:
                     $error = __('IP invalide', __FILE__);
                     break;
                 case 2:
                     $error = __('MAC invalide', __FILE__);
                     break;
                 case 4:
                     $error = __('SUBNET invalide', __FILE__);
                     break;
                 default:
                     $error = $magicPacket->getLastError();
                     break;
             }
             throw new Exception(__('Echec de la commande : ', __FILE__) . $error);
         }
     }
     if ($this->getLogicalId() == 'refresh') {
         $eqLogic->ping();
     }
 }