Ejemplo n.º 1
0
});
$klein->respond('POST', '/admin/node/view/[i:id]/add-ip', function ($request, $response, $service) use($core) {
    $lines = explode("\r\n", str_replace(" ", "", $request->param('ip_port')));
    $node = ORM::forTable('nodes')->findOne($request->param('id'));
    if (!$node) {
        $service->flash('<div class="alert alert-danger">The requested node does not exist in the system.</div>');
        $response->redirect('/admin/node')->send();
        return;
    }
    $IPA = json_decode($node->ips, true);
    $IPP = json_decode($node->ports, true);
    foreach ($lines as $id => $values) {
        list($ip, $ports) = explode('|', $values);
        $IPA = array_merge($IPA, array($ip => array()));
        $IPP = array_merge($IPP, array($ip => array()));
        $portList = Functions::processPorts($ports);
        $portCount = count($portList);
        for ($l = 0; $l < $portCount; $l++) {
            $IPP[$ip][$portList[$l]] = 1;
        }
        if (count($IPP[$ip]) > 0) {
            $IPA[$ip] = array_merge($IPA[$ip], array("ports_free" => count($IPP[$ip])));
        } else {
            $service->flash('<div class="alert alert-danger">You must enter ports to be used with the IP.</div>');
            $response->redirect('/admin/node/view/' . $request->param('id') . '?tab-allocation')->send();
            return;
        }
    }
    $node->ips = json_encode($IPA);
    $node->ports = json_encode($IPP);
    $node->save();