urlSegment2) throw new Wire404Exception(); // urlSegment2 existiert nicht 404!
if($input->urlSegment1){
switch($input->urlSegment1){
case 'list':
$services = $pages->find('template=service, sort=-subtitle');
$table = '';
foreach($services as $service){
$status = ($service->online == 1 ? "alert success" : "alert danger");
$table .="
$service->subtitle |
$service->static_ip |
httpUrl}{$service->operator->name}'>{$service->operator->name} |
";
}
$page->table = $table;
$content = renderPage();
break;
case 'ips':
$useMain = false;
$services = $pages->find("template=service");
$service_serial = array();
foreach($services as $service){
if(!validateMac($service->title)) continue;
$service_serial[] = array('mac' => strtolower(str_replace(":", "", $service->title)),
'staticip' => strtoupper($service->static_ip));
}
echo serialize($service_serial);
break;
case 'add':
if($input->post->mac) $mac = normalizeMac($sanitizer->text($input->post->mac));
if($input->post->title) $inputTitle = $sanitizer->name($input->post->title);
if(!wire('user')->isLoggedin()){
$content = "Gesicherte Seite
Bitte Anmelden oder Registrieren.";
$session->redirectUrl = $page->path."add/";
} elseif(!$input->post->submit) {
$content = renderPage('ip_registration');
} else {
// Register Service
$user = wire('user')->name;
$parent = $pages->get($page->id);
$operator = wire('user')->id;
if($pages->get("template=services, title=$mac") instanceof Nullpage){
// Creat IP
do {
$ip = long2ip(rand(ip2long("{$pages->get('template=site-setting')->start_ip}"), ip2long("{$pages->get('template=site-setting')->end_ip}")));
} while(!$pages->get("template=services, static_ip=$ip") instanceof NullPage);
// Add new if not exist
$mac = strtoupper($mac);
$s = createPage('service', $parent, $mac);
$s->subtitle = $inputTitle;
$s->operator = $operator;
$s->static_ip = $ip;
$s->save();
} else {
// Update if exit
$operator = wire('user')->id;
$s = $pages->get("title={$input->post->mac}");
$s->operator = $operator;
$s->key = $input->post->key;
$s->of(false);
$s->save();
$s->of(true);
}
$content = "Node HinzugefĆ¼gt:
Titel: {$s->subtitle}
MAC : {$s->title}
IP : {$s->static_ip}
Betreiber: {$users->get($s->operator)->name}
";
$session->remove('key');
$session->remove('mac');
}
break;
default:
throw new Wire404Exception(); // alle anderen Segmente existieren nicht = 404!
}
} else {
$userid = wire('user')->id;
$services = $pages->find("operator=$userid, template=service, sort=-subtitle");
$table = '';
foreach($services as $service){
$status = ($service->online == 1 ? "alert success" : "alert danger");
$online = ($service->online == 1 ? "online" : "offline");
$table .="
$service->subtitle |
$service->static_ip |
{$service->operator->name} |
";
}
$page->table = $table;
$content = renderPage();
}