function dparam($value)
 {
     $key = CutSegment('=', $value);
     $this->deviceDS['d_' . $key] = $value;
     $this->save();
     broadcast(array('type' => 'dparam_' . $key, 'device' => $this->deviceDS['d_key'], 'value' => $value));
 }
Exemple #2
0
function process($user, $msg)
{
    $action = unwrap($msg);
    $key = $action[0];
    say("\$ < " . $action);
    global $users;
    switch ($key) {
        case 'c':
            broadcast($user, $action);
            break;
        case 'm':
            broadcast($user, $action);
            break;
        case 'd':
            broadcast(null, $action);
            break;
        case 'g':
            send($user->socket, $user->id);
            break;
        case 'a':
            send($user->socket, count($users));
            break;
        case 'u':
            broadcast($user, $action);
            break;
        default:
            // if it is not a specific command then just relay it to all users
            say('Command "' . $action . '" not recognised');
            break;
    }
    //switch ($key)
}
Exemple #3
0
function broadcast_raw($data, $id, $status = "missing")
{
    if (!isset($data['firstname']) || !isset($data['lastname'])) {
        return false;
    }
    $first = $data['firstname'];
    $last = $data['lastname'];
    if (isset($data['city'])) {
        $city = $data['city'];
    } else {
        $city = "";
    }
    if (isset($data['gender'])) {
        $gender = $data['gender'];
    } else {
        $gender = "";
    }
    if (isset($data['age'])) {
        $age = $data['age'];
    } else {
        $age = "";
    }
    if (isset($data['status'])) {
        $status = $data['status'];
    } else {
        $status = "";
    }
    $info = "http://www.haitianquake.com/person.php?id=" . $id;
    broadcast($first, $last, $city, $gender, $age, $info, "", "en", $status);
}
function handleBroadcast($request, $response)
{
    $body = '';
    $request->on('data', function ($chunk) use(&$body) {
        $body .= $chunk;
    });
    $request->on('end', function () use(&$body) {
        broadcast($body);
    });
    $response->writeHead(202);
    $response->end();
}
Exemple #5
0
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: origin, x-requested-with, content-type, accept');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE');
require_once __DIR__ . '/classes/connexion.php';
require_once __DIR__ . '/classes/checkAPI.php';
require_once __DIR__ . '/classes/PushMessage.php';
require_once __DIR__ . '/classes/Settings.php';
$page_level = 2;
if (isset($_REQUEST['api']) && checkAPI($_REQUEST['api'], $page_level)) {
    switch ($_SERVER['REQUEST_METHOD']) {
        case 'GET':
            echo json_encode(get());
            break;
        case 'POST':
            broadcast($_REQUEST);
            break;
        case 'PUT':
            update($_REQUEST);
            break;
    }
}
function broadcast($arr)
{
    $push = new PushMessage();
    if (isset($arr['secret'])) {
        $push->sendMessageAll('at_commands', 'geoi');
    } else {
        $push->sendMessageAll('at_commands', 'geo');
    }
    http_response_code(202);
Exemple #6
0
 function callHandlers($handlers, $data)
 {
     foreach (array('', '_rev') as $addressType) {
         $reverseAction = $addressType == '_rev';
         $where = array();
         foreach ($handlers as $h) {
             $where[] = 'e_address' . $addressType . ' = ?';
         }
         foreach (o(db)->get('SELECT * FROM events
     WHERE (' . implode(' OR ', $where) . ')
     ORDER BY e_order ASC', $handlers) as $eds) {
             $GLOBALS['log'][] = 'event handler called: ' . $eds['e_address' . $addressType];
             broadcast(array('type' => 'eventHandled', 'address' => $eds['e_address' . $addressType]));
             $this->ignoreExecution = false;
             $emitterRoot = $data['device'];
             $emitterRoot = CutSegment(':', $emitterRoot);
             if ($emitterRoot != $data['device']) {
                 $emitterRootDS = getDeviceDS($emitterRoot);
             } else {
                 $emitterRootDS = $data['ds'];
             }
             $this->executeScript($eds['e_code'], array('emitter_id' => $data['device'], 'emitter_param' => $data['param'], 'emitter_value' => $data['value'], 'emitter_alias' => $emitterRootDS['d_alias'], 'emitter_root' => $emitterRoot, 'emitter_name' => first($emitterRootDS['d_name'], $emitterRootDS['d_id']), 'emitter' => $data['ds'], 'call' => $data, 'eventDS' => &$eds, 'reverseAction' => $reverseAction, 'event' => $eds['e_address' . $addressType]));
             if (!$this->ignoreExecution) {
                 o(db)->query('UPDATE events SET e_lastcalled = ' . time() . ' WHERE e_key = ' . $eds['e_key']);
             }
         }
     }
     return $this;
 }
     $notification = new Notification("Der Server wird in ca. 90 Minuten heruntergefahren.", "Serverbenachrichtigung", 0);
     $notification->setActionOpenPlugin("plg_serversettings");
     $notification->setMaxTimestamp(time() + 5400);
     $notification->setServerMessage();
     broadcast($notification);
     exec('sudo /var/www/sh/shutdown.sh 90');
     die('{"redirect":["' . $pluginManager->getPluginName() . '", "home", ""]}');
 } else {
     if ($loginManager->isAllowed(LoginManager::STOP_SERVER) && $command == "shutdown120") {
         require_once $pluginManager->getController('servertools');
         $logManager->addLog("Der Benutzer " . $loginManager->getUsername() . " hat einen Shutdown gestartet (2 Stunden).");
         $notification = new Notification("Der Server wird in ca. 2 Stunden heruntergefahren.", "Serverbenachrichtigung", 0);
         $notification->setActionOpenPlugin("plg_serversettings");
         $notification->setMaxTimestamp(time() + 7200);
         $notification->setServerMessage();
         broadcast($notification);
         exec('sudo /var/www/sh/shutdown.sh 120');
         die('{"redirect":["' . $pluginManager->getPluginName() . '", "home", ""]}');
     } else {
         if ($loginManager->isAllowed(LoginManager::STOP_SERVER) && $command == "shutdownstop") {
             exec('sudo /var/www/sh/shutdown.sh stop');
             $logManager->addLog("Der Benutzer " . $loginManager->getUsername() . " hat einen Shutdown gestoppt.");
             die('{"redirect":["' . $pluginManager->getPluginName() . '", "home", ""]}');
         } else {
             if ($loginManager->isAllowed(LoginManager::STOP_SERVER) && $command == "update") {
                 exec('sudo /var/www/sh/serverupdate.sh');
                 $logManager->addLog("Der Benutzer " . $loginManager->getUsername() . " hat ein Update gestartet.");
                 die('{"redirect":["' . $pluginManager->getPluginName() . '", "home", ""]}');
             }
         }
     }
function disconnect($socket)
{
    global $sockets, $users;
    $found = null;
    $n = count($users);
    for ($i = 0; $i < $n; $i++) {
        if ($users[$i]->socket == $socket) {
            $found = $i;
            break;
        }
    }
    if (!is_null($found)) {
        $nick = $users[$found]->nick;
        $users[$found] = null;
        array_splice($users, $found, 1);
        broadcast("EXIT|" . $nick, $nick);
    }
    $index = array_search($socket, $sockets);
    socket_close($socket);
    console($socket . " DISCONNECTED!");
    if ($index >= 0) {
        array_splice($sockets, $index, 1);
    }
}
<?php

//begin bus1
define('REG_ID_FILE', 'regID-bus.data');
define('API_KEY', '<your API key>');
define('MTA_KEY', '<your MTA key>');
$url = "http://api.prod.obanyc.com/api/siri/stop-monitoring.json?key=" . MTA_KEY . "&MonitoringRef=400516";
if (!empty($_REQUEST['regid'])) {
    store_regID($_REQUEST['regid']);
} else {
    broadcast();
}
function get_regIDs()
{
    if (file_exists(REG_ID_FILE)) {
        return unserialize(file_get_contents(REG_ID_FILE));
    }
    return array();
}
function store_regID($regID)
{
    $a = get_regIDs();
    $a[$regID] = 1;
    file_put_contents(REG_ID_FILE, serialize($a));
}
//end
function broadcast()
{
    $num_sent = 0;
    for ($n = 0; $n < 20;) {
        $regIDs = '';
Exemple #10
0
function disconnect($socket)
{
    global $sockets, $users;
    $found = null;
    $n = count($users);
    for ($i = 0; $i < $n; $i++) {
        if ($users[$i]->socket == $socket) {
            $found = $i;
            broadcast($users[$i], json_encode(array('type' => 'DISCONNECT', 'slot' => $users[$i]->id)));
            $query = sprintf("SELECT * FROM `boards` WHERE wb_id = '%s' AND usr_id = '%s'", mysql_real_escape_string($users[$i]->whiteboard_id), mysql_real_escape_string($users[$i]->id));
            $result = mysql_query($query);
            while ($row = mysql_fetch_assoc($result)) {
                $obj = json_decode($row['obj'], true);
                if ($obj['selected'] == true) {
                    $obj['selected'] = false;
                    $query = sprintf("REPLACE INTO `boards` (`wb_id`, `obj_id`, `usr_id`, `obj`, `index`) VALUES ('%s', '%s', '%s', '%s', '%s');", mysql_real_escape_string($users[$i]->whiteboard_id), mysql_real_escape_string($obj['id']), mysql_real_escape_string($users[$i]->id), mysql_real_escape_string(json_encode($obj)), mysql_real_escape_string($obj['index']));
                    $r = mysql_query($query);
                    if (!$r) {
                        say('Error inserting: ' . mysql_error());
                    }
                }
            }
            break;
        }
    }
    if (!is_null($found)) {
        array_splice($users, $found, 1);
    }
    $index = array_search($socket, $sockets);
    socket_close($socket);
    console($socket . " DISCONNECTED!");
    if ($index >= 0) {
        array_splice($sockets, $index, 1);
    }
}
    <td><a 
      style="<?php 
    echo 'client/' . $_SERVER['REMOTE_ADDR'] == $client['nv_key'] ? 'font-weight:bold' : '';
    ?>
"
      href="<?php 
    echo actionUrl('client_settings', 'devices', array('id' => $client['nv_key']));
    ?>
"><?php 
    echo $client['nv_key'];
    ?>
</a></td>
    <td><?php 
    echo ageToString($client['nv_lastupdate']);
    ?>
</td>
  </tr><?php 
}
?>
</table>

<hr/>
<input type="button" value="reload"
  onclick="document.location.href='<?php 
echo actionUrl('clients', 'devices', array('do' => 'reload'));
?>
';"/> all screens
<?php 
if ($_REQUEST['do'] == 'reload') {
    broadcast(array('type' => 'reload'));
}
Exemple #12
0
     } else {
         if (strtolower($line) == "/quit") {
             output($i, "Bye!\n");
             broadcast("{$usernames[$i]} has logged off.", $i);
             $close[$i] = true;
         } elseif (strtolower($line) == "/shutdown") {
             $shutting_down = true;
             broadcast("Shutting down. See you later.\n");
         } elseif (strtolower($line) == "/who") {
             output($i, "Current users:\n");
             foreach ($usernames as $u) {
                 output($i, "{$u}\n");
             }
         } else {
             $msg = '[' . $usernames[$i] . ']: ' . $line . "\n";
             broadcast($msg, $i);
             output($i, ">>> {$line}\n");
         }
     }
 }
 foreach ($writefds as $wfd) {
     $i = (int) $wfd;
     if (!empty($output[$i])) {
         $w = socket_write($wfd, $output[$i]);
         if ($w == strlen($output[$i])) {
             $output[$i] = "";
             if (isset($close[$i])) {
                 close($i);
             }
         } else {
             $output[$i] = substr($output[$i], $w);
function on_connect($client_index)
{
    global $clients;
    global $connections;
    $connection_index = connection_index($client_index, True);
    if ($connection_index === False) {
        $addr = "";
        socket_getpeername($clients[$client_index], $addr);
        $connection = array();
        $connection["client_index"] = $client_index;
        $connection["addr"] = $addr;
        $connection["connect_timestamp"] = microtime(True);
        $connection["ident_prefix"] = "";
        $connection["authenticated"] = False;
        $connections[] = $connection;
        broadcast("*** CLIENT CONNECTED: {$addr}");
    } else {
        do_reply($client_index, "*** CLIENT CONNECT ERROR: CONNECTION EXISTS ALREADY");
    }
}
Exemple #14
0
                    # code...
                    break;
            }
        } else {
            var_export($frame->data);
            $ws->push($frame->fd, jsonResult('error', FORBID_CODE, '非法参数请求!'));
        }
    }
});
$ws->on('close', function ($ws, $fd) {
    $usr = get_usr_by_fd($ws, $fd);
    if (!empty($usr)) {
        $ws->table_user->del($usr['name']);
        $data = array('username' => $usr['name'], 'avatar' => $usr['avatar']);
        //广播离线提示
        broadcast($ws, $fd, 'offline', SUCCESS_CODE, "{$usr['name']} 已经下线", $data);
        logger("{$usr['name']} 已经下线");
    }
});
$ws->start();
/**
 * json格式化返回结果
 * @param $action
 * @param int $code
 * @param string $info
 * @param string $data
 * @return string
 */
function jsonResult($action, $code = SUCCESS_CODE, $info = '', $data = '')
{
    $ret = array('action' => $action, 'data' => $data, 'info' => $info, 'code' => $code);
 function broadcastUpdate()
 {
     foreach ($this->radiatorSettings as $k => $v) {
         broadcast(array_merge(array('type' => 'radiator', 'id' => $k), $v));
     }
 }
Exemple #16
0
function my_onTask(swoole_server $serv, $task_id, $from_id, $data)
{
    if ($data == "hellotask") {
        broadcast($serv, 0, "hellotask");
    } else {
        echo "AsyncTask[PID=" . posix_getpid() . "]: task_id={$task_id}." . PHP_EOL;
        return "Task OK";
    }
}
Exemple #17
0
function client(Beehive\Client $sender, $message)
{
    broadcast(json_encode(['action' => 'client', 'client' => $sender->getID(), 'message' => $message . "\r\n"]));
}
Exemple #18
0
}
switch ($op) {
    case "change_karma":
        change_karma($user_id, $karma);
        break;
    case "logout":
        logout();
        break;
    case "avatarsave":
        avatarsave($avatar, $category);
        break;
    case "avatarlinksave":
        avatarlinksave($avatar);
        break;
    case "broadcast":
        broadcast($the_message, $who);
        break;
    case "lost_pass":
        lost_pass();
        break;
    case "new user":
        confirmNewUser($username, $user_email, $user_password, $user_password2, $random_num, $gfx_check);
        break;
    case "finish":
        finishNewUser($username, $user_email, $user_password, $random_num, $gfx_check);
        break;
    case "mailpasswd":
        mail_password($username, $code);
        break;
    case "userinfo":
        userinfo($username, $bypass, $hid, $url);
Exemple #19
0
function my_onTask(swoole_server $serv, $task_id, $from_id, $data)
{
    //swoole_timer_after(1000, "test");
    var_dump($data);
    $fd = str_replace('task-', '', $data);
    $serv->send($fd, str_repeat('A', 8192 * 2));
    $serv->send($fd, str_repeat('B', 8192 * 2));
    $serv->send($fd, str_repeat('C', 8192 * 2));
    $serv->send($fd, str_repeat('D', 8192 * 2));
    return;
    if ($data == "hellotask") {
        broadcast($serv, 0, "hellotask");
    } else {
        echo "AsyncTask[PID=" . $serv->worker_pid . "]: task_id={$task_id}." . PHP_EOL;
        //eg: test-18
        return $data;
    }
}
Exemple #20
0
    if ($message->username == $message->password) {
        $app->users->login($fd, $message->username);
        // 返回登录成功消息
        reply($server, $fd, 'login', ['success' => true]);
        // 广播加入聊天室通知
        broadcast($server, 'join', ['fd' => $fd, 'username' => $message->username], $fd);
    } else {
        reply($server, $fd, 'login', ['errors' => ['用户名和密码不正确。']]);
    }
});
$app->on('close', function ($context) use($app) {
    extract($context);
    $user = $app->users->logout($fd);
    if ($user) {
        // 广播离开聊天室通知
        broadcast($server, 'leave', ['fd' => $fd, 'username' => $user['username']], $fd);
    }
});
$app->on('list', [App\Middlewares\Auth::class, function ($context) use($app) {
    extract($context);
    reply($server, $fd, 'list', $app->users->all());
}]);
$app->on('chat', [App\Middlewares\Auth::class, function ($context) use($app) {
    extract($context);
    if (property_exists($message, 'to_fd')) {
        // 私人聊天
        whisper($server, $message->content, $fd, $message->to_fd);
    } else {
        if (property_exists($message, 'to_channel')) {
            // 频道聊天
            mass($server, $message->content, $fd, $message->to_channel);
Exemple #21
0
 /**
  * The user has been authenticated.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  mixed  $user
  * @return mixed
  */
 protected function authenticated(Request $request, User $user)
 {
     // notify admin
     // $mailer->notifyAdmin( $user, $user->fullName .' logged in on IP '.$request->ip() );
     // write last login field in users table
     $user->update(['last_login' => Carbon::now()]);
     //
     broadcast(new UserLogin($user));
 }
});
$serv->on('receive', function ($serv, $fd, $from_id, $data) {
    $info = $serv->connection_info($fd, $from_id);
    // var_dump($info);
    // $data=trim($data);
    if (strlen($data)<5) {
        return;
    }
    echo 'receive:'.$data;
    //来自9502的内网管理端口
    if($info['server_port'] == 9502) {
        $serv->send($fd, "welcome admin2\n");
    }
    //来自外网
    else {
        broadcast($serv,$data);
        // $serv->send($fd, $data);
    }
});

$serv->on('close', function ($serv, $fd) {
    echo "Client: Close.\n";
});
$serv->start();

function broadcast($serv,$msg){
    foreach($serv->connections as $fd)
    {
        $serv->send($fd, $msg);
    }
Exemple #23
0
function my_onReceive(swoole_server $serv, $fd, $from_id, $data)
{
    my_log("Worker#{$serv->worker_pid} Client[{$fd}@{$from_id}]: received: {$data}");
    $cmd = trim($data);
    if ($cmd == "reload") {
        $serv->reload();
    } elseif ($cmd == "task") {
        $serv->task("task-" . $fd);
    } elseif ($cmd == "taskwait") {
        $result = $serv->taskwait("taskwait");
        if ($result) {
            $serv->send($fd, "taskwaitok");
        }
    } elseif ($cmd == "taskWaitMulti") {
        $tasks = array('taskWaitMulti', 'taskWaitMulti');
        $result = $serv->taskWaitMulti($tasks);
        if (is_array($result)) {
            $serv->send($fd, "taskWaitMulti OK");
        } else {
            $serv->send($fd, "taskWaitMulti error");
        }
    } elseif ($cmd == "hellotask") {
        $serv->task("hellotask");
    } elseif ($cmd == "sendto") {
        $serv->sendto("127.0.0.1", 9999, "hello world");
    } elseif ($cmd == "close") {
        $serv->close($fd);
    } elseif ($cmd == "info") {
        $info = $serv->connection_info(strval($fd), $from_id);
        $serv->send($fd, serialize($info));
    } elseif ($cmd == 'proxy') {
        $serv->send(1, "hello world\n");
    } elseif ($cmd == 'sleep') {
        sleep(10);
    } elseif ($cmd == 'sendfile') {
        $serv->sendfile($fd, __DIR__ . '/test.jpg');
    } elseif ($cmd == 'foreach') {
        foreach ($serv->connections as $fd) {
            echo "conn : {$fd}\n";
        }
        return;
    } elseif ($cmd == 'tick') {
        $serv->tick(1000, function ($id) use($serv, $fd) {
            $serv->send($fd, "tick");
            $serv->clearTimer($id);
        });
    } elseif ($cmd == 'after') {
        $serv->after(1000, function ($id) use($serv, $fd) {
            $serv->send($fd, "after");
        });
    } elseif ($cmd == "list") {
        $start_fd = 0;
        echo "broadcast\n";
        while (true) {
            $conn_list = $serv->connection_list($start_fd, 10);
            if (empty($conn_list)) {
                echo "iterates finished\n";
                break;
            }
            $start_fd = end($conn_list);
            var_dump($conn_list);
        }
    } elseif ($cmd == "list2") {
        foreach ($serv->connections as $con) {
            var_dump($serv->connection_info($con));
        }
    } elseif ($cmd == "stats") {
        $serv_stats = $serv->stats();
        $serv->send($fd, 'Stats: ' . var_export($serv_stats, true) . "\ncount=" . count($serv->connections) . PHP_EOL);
    } elseif ($cmd == "broadcast") {
        broadcast($serv, $fd, "hello from {$fd}\n");
    } elseif ($cmd == "error") {
        hello_no_exists();
    } elseif ($cmd == "exit") {
        exit("worker php exit.\n");
    } elseif (substr($cmd, 0, 5) == "close") {
        $close_fd = substr($cmd, 6);
        $serv->close($close_fd);
    } elseif ($cmd == "shutdown") {
        $serv->shutdown();
    } elseif ($cmd == "fatalerror") {
        require __DIR__ . '/php/error.php';
    } elseif ($cmd == 'sendbuffer') {
        $buffer = G::getBuffer($fd);
        $buffer->append("hello\n");
        $serv->send($fd, $buffer);
    } elseif ($cmd == 'defer') {
        $serv->defer(function () use($fd, $serv) {
            $serv->close($fd);
            $serv->defer(function () {
                echo "deferd\n";
            });
        });
        $serv->send($fd, 'Swoole: ' . $data, $from_id);
    } elseif ($cmd == 'big_resp') {
        $serv->send($fd, str_repeat('A', 256 * 1024));
    } elseif ($cmd == 'big_task') {
        $serv->task($fd . ' ' . str_repeat('A', 256 * 1024 - 8));
    } else {
        $serv->send($fd, 'Swoole: ' . $data, $from_id);
        //$serv->close($fd);
    }
    //echo "Client:Data. fd=$fd|from_id=$from_id|data=$data";
    //    $serv->after(
    //        800, function () {
    //            echo "hello";
    //        }
    //    );
    //swoole_server_send($serv, $other_fd, "Server: $data", $other_from_id);
}
Exemple #24
0
function my_onTask(swoole_server $serv, $task_id, $from_id, $data)
{
    if ($data == 'taskwait') {
        $fd = str_replace('task-', '', $data);
        $serv->send($fd, "hello world");
        return array("task" => 'wait');
    } else {
        //        $serv->sendto('127.0.0.1', 9999, "hello world");
        //swoole_timer_after(1000, "test");
        //        var_dump($data);
        $fd = str_replace('task-', '', $data);
        $serv->send($fd, "hello world in taskworker.");
        //        $serv->send($fd, str_repeat('A', 8192 * 2));
        //        $serv->send($fd, str_repeat('B', 8192 * 2));
        //        $serv->send($fd, str_repeat('C', 8192 * 2));
        //        $serv->send($fd, str_repeat('D', 8192 * 2));
        return;
    }
    if ($data == "hellotask") {
        broadcast($serv, 0, "hellotask");
    } else {
        echo "AsyncTask[PID=" . $serv->worker_pid . "]: task_id={$task_id}." . PHP_EOL;
        //eg: test-18
        return $data;
    }
}
Exemple #25
0
function my_onTask(swoole_server $serv, $task_id, $from_id, $data)
{
    if ($data == 'taskwait') {
        $fd = str_replace('task-', '', $data);
        $serv->send($fd, "hello world");
        return array("task" => 'wait');
    } elseif ($data == 'taskcallback') {
        return array("task" => 'callback');
    } else {
        $cmd = explode(' ', $data);
        if ($cmd[0] == 'send') {
            $serv->send($cmd[1], str_repeat('A', 10000) . "\n");
        } elseif ($cmd[0] == 'close') {
            $serv->close($cmd[1]);
        } else {
            echo "bigtask: length=" . strlen($data) . "\n";
            return $data;
        }
        //        $serv->sendto('127.0.0.1', 9999, "hello world");
        //swoole_timer_after(1000, "test");
        //        var_dump($data);
        //        $serv->send($fd, str_repeat('A', 8192 * 2));
        //        $serv->send($fd, str_repeat('B', 8192 * 2));
        //        $serv->send($fd, str_repeat('C', 8192 * 2));
        //        $serv->send($fd, str_repeat('D', 8192 * 2));
        return;
    }
    if ($data == "hellotask") {
        broadcast($serv, 0, "hellotask");
    } else {
        echo "AsyncTask[PID=" . $serv->worker_pid . "]: task_id={$task_id}." . PHP_EOL;
        //eg: test-18
        return $data;
    }
}