{ $id = intval(params('id')); $cfg = $GLOBALS['cfg']; $db = $GLOBALS['db']; $arrPerson = $db->select("SELECT *\n FROM {$cfg['tblPerson']}\n WHERE id={$id}"); if ($arrPerson) { set('person', $arrPerson[0]); if (isAjaxRequest()) { return html('people/edit.js.php', null); } return html('people/edit.html.php'); } halt(NOT_FOUND); } # update existing person dispatch_put('/people', 'people_update'); function people_update() { $cfg = $GLOBALS['cfg']; $db = $GLOBALS['db']; $id = intval($_POST['id']); $vorname = $db->escape($_POST['vorname']); $nachname = $db->escape($_POST['nachname']); $result = $db->update("UPDATE {$cfg['tblPerson']}\n SET vorname='{$vorname}', nachname='{$nachname}'\n WHERE id={$id}\n LIMIT 1"); if ($result) { redirect_to('people'); } else { halt(SERVER_ERROR); } } # remove a person
dispatch_put('/settings', function () { $crt_client_exists = file_exists('/etc/openvpn/keys/user.crt'); $crt_client_key_exists = file_exists('/etc/openvpn/keys/user.key'); $crt_server_ca_exists = file_exists('/etc/openvpn/keys/ca-server.crt'); $service_enabled = isset($_POST['service_enabled']) ? 1 : 0; $ip6_net = empty($_POST['ip6_net']) ? 'none' : $_POST['ip6_net']; $ip6_addr = 'none'; if ($service_enabled == 1) { try { if (empty($_POST['server_name']) || empty($_POST['server_port']) || empty($_POST['server_proto'])) { throw new Exception(_('The Server Address, the Server Port and the Protocol cannot be empty')); } if (!preg_match('/^\\d+$/', $_POST['server_port'])) { throw new Exception(_('The Server Port must be only composed of digits')); } if ($_POST['server_proto'] != 'udp' && $_POST['server_proto'] != 'tcp') { throw new Exception(_('The Protocol must be "udp" or "tcp"')); } if ($_FILES['crt_client']['error'] == UPLOAD_ERR_OK && $_FILES['crt_client_key']['error'] != UPLOAD_ERR_OK && (!$crt_client_key_exists || $_POST['crt_client_key_delete'] == 1) || $_FILES['crt_client_key']['error'] == UPLOAD_ERR_OK && $_FILES['crt_client']['error'] != UPLOAD_ERR_OK && (!$crt_client_exists || $_POST['crt_client_delete'] == 1)) { throw new Exception(_('A Client Certificate is needed when you suggest a Key, or vice versa')); } if (empty($_POST['login_user']) xor empty($_POST['login_passphrase'])) { throw new Exception(_('A Password is needed when you suggest a Username, or vice versa')); } if ($_FILES['crt_server_ca']['error'] != UPLOAD_ERR_OK && !$crt_server_ca_exists) { throw new Exception(_('You need a Server CA.')); } if ($_FILES['crt_client_key']['error'] != UPLOAD_ERR_OK && (!$crt_client_key_exists || $_POST['crt_client_key_delete'] == 1) && empty($_POST['login_user'])) { throw new Exception(_('You need either a Client Certificate, either a Username, or both')); } if ($ip6_net != 'none') { $ip6_net = ipv6_expanded($ip6_net); if (empty($ip6_net)) { throw new Exception(_('The IPv6 Delegated Prefix format looks bad')); } $ip6_blocs = explode(':', $ip6_net); $ip6_addr = "{$ip6_blocs[0]}:{$ip6_blocs[1]}:{$ip6_blocs[2]}:{$ip6_blocs[3]}:{$ip6_blocs[4]}:{$ip6_blocs[5]}:{$ip6_blocs[6]}:42"; $ip6_net = ipv6_compressed($ip6_net); $ip6_addr = ipv6_compressed($ip6_addr); } } catch (Exception $e) { flash('error', $e->getMessage() . ' (' . _('configuration not updated') . ').'); goto redirect; } } stop_service(); ynh_setting_set('service_enabled', $service_enabled); if ($service_enabled == 1) { ynh_setting_set('server_name', $_POST['server_name']); ynh_setting_set('server_port', $_POST['server_port']); ynh_setting_set('server_proto', $_POST['server_proto']); ynh_setting_set('login_user', $_POST['login_user']); ynh_setting_set('login_passphrase', $_POST['login_passphrase']); ynh_setting_set('ip6_net', $ip6_net); ynh_setting_set('ip6_addr', $ip6_addr); file_put_contents('/etc/openvpn/client.conf.tpl', $_POST['raw_openvpn']); if ($_FILES['crt_client']['error'] == UPLOAD_ERR_OK) { move_uploaded_file($_FILES['crt_client']['tmp_name'], '/etc/openvpn/keys/user.crt'); } elseif ($_POST['crt_client_delete'] == 1) { unlink('/etc/openvpn/keys/user.crt'); } if ($_FILES['crt_client_key']['error'] == UPLOAD_ERR_OK) { move_uploaded_file($_FILES['crt_client_key']['tmp_name'], '/etc/openvpn/keys/user.key'); } elseif ($_POST['crt_client_key_delete'] == 1) { unlink('/etc/openvpn/keys/user.key'); } if ($_FILES['crt_server_ca']['error'] == UPLOAD_ERR_OK) { move_uploaded_file($_FILES['crt_server_ca']['tmp_name'], '/etc/openvpn/keys/ca-server.crt'); } if (!empty($_POST['login_user'])) { file_put_contents('/etc/openvpn/keys/credentials', "{$_POST['login_user']}\n{$_POST['login_passphrase']}"); } else { file_put_contents('/etc/openvpn/keys/credentials', ''); } $retcode = start_service(); if ($retcode == 0) { flash('success', _('Configuration updated and service successfully reloaded')); } else { flash('error', _('Configuration updated but service reload failed')); } } else { flash('success', _('Service successfully disabled')); } redirect: redirect_to('/'); });
dispatch_delete('/commissioner/player/:id/delete', 'AdminPlayerController::player_do_delete'); // Player's Picks dispatch('/commissioner/players/picks', 'AdminPlayerPicksController::players'); dispatch('/commissioner/player/:uid/picks', 'AdminPlayerPicksController::player_picks'); dispatch('/commissioner/player/:uid/picks/:week', 'AdminPlayerPicksController::player_picks_week'); dispatch_post('/commissioner/player/:uid/picks/:week', 'AdminPlayerPicksController::save_player_picks_week'); /* * == UserController == * Method Path Controller * GET /login UserController::show_login * POST /login UserController::do_login * GET /logout UserController::do_logout * GET /my-account UserController::show_account * PUT /my-account UserController::edit_account */ dispatch('/login', 'UserController::show_login'); dispatch_post('/login', 'UserController::do_login'); dispatch('/logout', 'UserController::do_logout'); dispatch('/my-account', 'UserController::show_account'); dispatch_put('/my-account', 'UserController::edit_account'); /* * == MessengerController == * Method Path Controller * GET /messages MessengerController::show * POST /messages MessengerController::create * Coming Soon * PUT /messages/:id MessengerController::edit * DELETE /messages/:id MessengerController::delete */ dispatch('/messages', 'MessengerController::show'); dispatch_post('/messages', 'MessengerController::create');
return render('settings.html.php'); }); dispatch_put('/settings', function () { $service_enabled = isset($_POST['service_enabled']) ? 1 : 0; if ($service_enabled == 1) { try { if ($_POST['wifi_device_id'] == -1) { throw new Exception(_('You need to select an associated hotspot')); } } catch (Exception $e) { flash('error', $e->getMessage() . ' (' . _('configuration not updated') . ').'); goto redirect; } } stop_service(); ynh_setting_set('service_enabled', $service_enabled); if ($service_enabled == 1) { ynh_setting_set('wifi_device_id', $_POST['wifi_device_id']); $retcode = start_service(); if ($retcode == 0) { flash('success', _('Configuration updated and service successfully reloaded')); } else { flash('error', _('Configuration updated but service reload failed')); } } else { flash('success', _('Service successfully disabled')); } redirect: redirect_to('/'); }); dispatch('/status', function () { $status_lines = service_status();
$cfg = $GLOBALS['cfg']; $db = $GLOBALS['db']; $arrDaemon = $db->select("SELECT *\n FROM {$cfg['tblDaemon']}\n WHERE id={$id}"); if (!$arrDaemon) { halt(NOT_FOUND); return; } set('daemon', $arrDaemon[0]); if (isAjaxRequest()) { return js('daemons/edit.js.php', null); } else { halt(HTTP_NOT_IMPLEMENTED); } } # update existing daemon dispatch_put('/daemons', 'daemons_update'); function daemons_update() { $cfg = $GLOBALS['cfg']; $db = $GLOBALS['db']; $id = intval($_POST['id']); $name = $db->escape($_POST['name']); $result = $db->update("UPDATE {$cfg['tblDaemon']}\n SET name='{$name}'\n WHERE id={$id}\n LIMIT 1"); if (!$result) { halt(SERVER_ERROR); return; } redirect_to('daemons'); } # delete a daemon dispatch_delete('/daemons/:id', 'daemons_delete');
// sets which view to render $nested = addslashes($_GET['nested']); $arrPeople = $db->select("SELECT *\n FROM {$cfg['tblPerson']}\n ORDER BY nachname ASC"); set('people', $arrPeople); $arrClient = $db->select("SELECT {$cfg['tblClient']}.id as cid, {$cfg['tblClient']}.*\n FROM {$cfg['tblClient']}\n WHERE id={$id}"); if ($arrClient) { set('client', $arrClient[0]); if (isAjaxRequest()) { return js('clients/edit.js.php', null, array('nested' => $nested)); } return html('clients/edit.html.php'); } halt(NOT_FOUND); } # update an existing client dispatch_put('/clients', 'clients_update'); function clients_update() { $cfg = $GLOBALS['cfg']; $db = $GLOBALS['db']; // sets which view to render $nested = addslashes($_POST['nested']); if (!empty($nested)) { $nested = '.' . $nested; } $id = intval($_POST['id']); $person_id = intval($_POST['person_id']); $type = $db->escape($_POST['type']); $mac = $db->escape($_POST['mac']); $desc = $db->escape($_POST['desc']); $result = $db->update("UPDATE {$cfg['tblClient']}\n SET person_id='{$person_id}', type='{$type}', mac='{$mac}', `desc`='{$desc}'\n WHERE id={$id}\n LIMIT 1");
# matches GET /posts/1/edit dispatch('/posts/:id/edit', 'blog_posts_edit'); function blog_posts_edit() { if ($post = post_find(params('id'))) { set('post', $post); # passing the post the the view return html('posts/edit.html.php'); # rendering the edit view, with its form } else { halt(NOT_FOUND, "This post doesn't exists. Can't edit it."); # raises error / renders an error page } } # matches PUT /posts/1 dispatch_put('/posts/:id', 'blog_posts_update'); function blog_posts_update() { $post_id = params('id'); if (post_update($post_id, $_POST['post'])) { redirect_to('posts', $post_id); # redirects to this freshly just updated post } else { halt(SERVER_ERROR, "An error occured while trying to update post " . $post_id); # raises error / renders an error page } } # matches DELETE /posts/1 dispatch_delete('/posts/:id', 'blog_posts_destroy'); function blog_posts_destroy() {
(int) $id; return $id / $divider; } dispatch('/route9/*', 'MyController::staticMethod'); dispatch('/route9b/*', 'MyController::staticMethod', array('params' => array(10))); dispatch(array('/route10/*', array('id')), 'MyController::staticMethod'); dispatch(array('/route10b/*', array('id')), 'MyController::staticMethod', array('params' => array('id' => 10))); /* http methods dispatching */ dispatch_get('/route11', 'test_route11'); function test_route11() { header('X-LIM-CTL: route11'); return "GET"; } dispatch_post('/route11', 'test_route11post'); function test_route11post() { //header('Content-length: 4'); return "POST"; } dispatch_put('/route11', 'test_route11put'); function test_route11put() { return "PUT"; } dispatch_delete('/route11', 'test_route11delete'); function test_route11delete() { return "DELETE"; } run();
dispatch_put('/settings', function () { $service_enabled = isset($_POST['service_enabled']) ? 1 : 0; if ($service_enabled == 1) { $crt_client_exists = file_exists('/etc/openvpn/keys/user.crt'); $crt_client_key_exists = file_exists('/etc/openvpn/keys/user.key'); $crt_server_ca_exists = file_exists('/etc/openvpn/keys/ca-server.crt'); $config = $_POST; $autoconf = false; try { if ($_FILES['cubefile']['error'] == UPLOAD_ERR_OK) { $config = readAutoConf($_FILES['cubefile']['tmp_name']); if (is_null($config)) { throw new Exception(_('Json Syntax Error, please check your dot cube file')); } $autoconf = true; } $ip6_net = empty($config['ip6_net']) ? 'none' : $config['ip6_net']; $ip6_addr = 'none'; if (empty($config['server_name']) || empty($config['server_port']) || empty($config['server_proto'])) { throw new Exception(_('The Server Address, the Server Port and the Protocol cannot be empty')); } if (!preg_match('/^\\d+$/', $config['server_port'])) { throw new Exception(_('The Server Port must be only composed of digits')); } if ($config['server_proto'] != 'udp' && $config['server_proto'] != 'tcp') { throw new Exception(_('The Protocol must be "udp" or "tcp"')); } if (empty($config['dns0']) || empty($config['dns1'])) { throw new Exception(_('You need to define two DNS resolver addresses')); } if (empty($config['login_user']) xor empty($config['login_passphrase'])) { throw new Exception(_('A Password is needed when you suggest a Username, or vice versa')); } if (!$autoconf && ($_FILES['crt_client']['error'] == UPLOAD_ERR_OK && $_FILES['crt_client_key']['error'] != UPLOAD_ERR_OK && (!$crt_client_key_exists || $_POST['crt_client_key_delete'] == 1) || $_FILES['crt_client_key']['error'] == UPLOAD_ERR_OK && $_FILES['crt_client']['error'] != UPLOAD_ERR_OK && (!$crt_client_exists || $_POST['crt_client_delete'] == 1)) || $autoconf && (empty($config['crt_client']) xor empty($config['crt_client_key']))) { throw new Exception(_('A Client Certificate is needed when you suggest a Key, or vice versa')); } if (!$autoconf && $_FILES['crt_server_ca']['error'] != UPLOAD_ERR_OK && !$crt_server_ca_exists || $autoconf && empty($config['crt_server_ca'])) { throw new Exception(_('You need a Server CA.')); } if ((!$autoconf && $_FILES['crt_client_key']['error'] != UPLOAD_ERR_OK && (!$crt_client_key_exists || $_POST['crt_client_key_delete'] == 1) || $autoconf && empty($config['crt_client_key'])) && empty($config['login_user'])) { throw new Exception(_('You need either a Client Certificate, either a Username, or both')); } if ($ip6_net != 'none') { $ip6_net = ipv6_expanded($ip6_net); if (empty($ip6_net)) { throw new Exception(_('The IPv6 Delegated Prefix format looks bad')); } $ip6_blocs = explode(':', $ip6_net); $ip6_addr = "{$ip6_blocs[0]}:{$ip6_blocs[1]}:{$ip6_blocs[2]}:{$ip6_blocs[3]}:{$ip6_blocs[4]}:{$ip6_blocs[5]}:{$ip6_blocs[6]}:42"; $ip6_net = ipv6_compressed($ip6_net); $ip6_addr = ipv6_compressed($ip6_addr); } } catch (Exception $e) { flash('error', $e->getMessage() . ' (' . _('configuration not updated') . ').'); goto redirect; } } stop_service(); ynh_setting_set('service_enabled', $service_enabled); if ($service_enabled == 1) { ynh_setting_set('server_name', $config['server_name']); ynh_setting_set('server_port', $config['server_port']); ynh_setting_set('server_proto', $config['server_proto']); ynh_setting_set('dns0', $config['dns0']); ynh_setting_set('dns1', $config['dns1']); ynh_setting_set('login_user', $config['login_user']); ynh_setting_set('login_passphrase', $config['login_passphrase']); ynh_setting_set('ip6_net', $ip6_net); ynh_setting_set('ip6_addr', $ip6_addr); if ($autoconf) { copy('/etc/openvpn/client.conf.tpl.restore', '/etc/openvpn/client.conf.tpl'); if (!empty($config['openvpn_rm'])) { $raw_openvpn = explode("\n", file_get_contents('/etc/openvpn/client.conf.tpl')); $fopenvpn = fopen('/etc/openvpn/client.conf.tpl', 'w'); foreach ($raw_openvpn as $opt) { $filtered = false; if (!preg_match('/^#/', $opt) && !preg_match('/<TPL:/', $opt)) { foreach ($config['openvpn_rm'] as $filter) { if (preg_match("/{$filter}/i", $opt)) { $filtered = true; } } } if (!$filtered) { fwrite($fopenvpn, "{$opt}\n"); } } fclose($fopenvpn); } if (!empty($config['openvpn_add'])) { $raw_openvpn = file_get_contents('/etc/openvpn/client.conf.tpl'); $raw_openvpn .= "\n# Custom\n" . implode("\n", $config['openvpn_add']); file_put_contents('/etc/openvpn/client.conf.tpl', $raw_openvpn); } if (empty($config['crt_client'])) { if (file_exists('/etc/openvpn/keys/user.crt')) { unlink('/etc/openvpn/keys/user.crt'); } } else { file_put_contents('/etc/openvpn/keys/user.crt', $config['crt_client']); } if (empty($config['crt_client_key'])) { if (file_exists('/etc/openvpn/keys/user.key')) { unlink('/etc/openvpn/keys/user.key'); } } else { file_put_contents('/etc/openvpn/keys/user.key', $config['crt_client_key']); } if (empty($config['crt_client_ta'])) { if (file_exists('/etc/openvpn/keys/user_ta.key')) { unlink('/etc/openvpn/keys/user_ta.key'); } } else { file_put_contents('/etc/openvpn/keys/user_ta.key', $config['crt_client_ta']); } if (empty($config['crt_server_ca'])) { if (file_exists('/etc/openvpn/keys/ca-server.crt')) { unlink('/etc/openvpn/keys/ca-server.crt'); } } else { file_put_contents('/etc/openvpn/keys/ca-server.crt', $config['crt_server_ca']); } } else { file_put_contents('/etc/openvpn/client.conf.tpl', $_POST['raw_openvpn']); if ($_FILES['crt_client']['error'] == UPLOAD_ERR_OK) { move_uploaded_file($_FILES['crt_client']['tmp_name'], '/etc/openvpn/keys/user.crt'); } elseif ($_POST['crt_client_delete'] == 1) { unlink('/etc/openvpn/keys/user.crt'); } if ($_FILES['crt_client_key']['error'] == UPLOAD_ERR_OK) { move_uploaded_file($_FILES['crt_client_key']['tmp_name'], '/etc/openvpn/keys/user.key'); } elseif ($_POST['crt_client_key_delete'] == 1) { unlink('/etc/openvpn/keys/user.key'); } if ($_FILES['crt_client_ta']['error'] == UPLOAD_ERR_OK) { move_uploaded_file($_FILES['crt_client_ta']['tmp_name'], '/etc/openvpn/keys/user_ta.key'); } elseif ($_POST['crt_client_ta_delete'] == 1) { unlink('/etc/openvpn/keys/user_ta.key'); } if ($_FILES['crt_server_ca']['error'] == UPLOAD_ERR_OK) { move_uploaded_file($_FILES['crt_server_ca']['tmp_name'], '/etc/openvpn/keys/ca-server.crt'); } } if (!empty($config['login_user'])) { file_put_contents('/etc/openvpn/keys/credentials', "{$config['login_user']}\n{$config['login_passphrase']}"); } else { file_put_contents('/etc/openvpn/keys/credentials', ''); } $retcode = start_service(); if ($retcode == 0) { flash('success', _('Configuration updated and service successfully reloaded')); } else { flash('error', _('Configuration updated but service reload failed')); } } else { flash('success', _('Service successfully disabled')); } redirect: redirect_to('/'); });
$object = eval("return new {$name}({$argstr});"); } store_object($object); $data = object_properties_to_hash($object); $results = array('json_class' => $name, 'data' => $data, 'id' => spl_object_hash($object)); logit("results", $results); return json_encode($results); } catch (LoadError $e) { halt(422, array("exception" => "LoadError", "error" => $e->getMessage())); } catch (Exception $e) { logit('Exception ' . $e->getMessage()); halt(422, array("exception" => get_class($e), "error" => $e->getMessage())); // return json_encode(array('error' => $e->getMessage())); } } dispatch_put('/object/:id/msg/:message', 'send_message'); function send_message() { logit("POST", $_POST); // set_error_handler("error_handler"); try { $message = params('message'); $n_message = $message; $id = params('id'); logit('looking for object', $id); $object = get_object($id); if (is_null($object)) { logit('object not found', params('id')); halt(NOT_FOUND, array("exception" => "ObjectNotFound", "error" => 'Object not found')); // return "object:" . params('id') . ": was not found"; } else {
<?php require_once 'autoload.php'; //load app classes require_once 'lib/limonade.php'; dispatch('/css/:css', 'AssetController::css'); dispatch('/js/:js', 'AssetController::js'); //REST API dispatch_get('/api/users', 'UserController::index'); dispatch_get('/api/users/:id', 'UserController::get'); dispatch_post('/api/users', 'UserController::post'); dispatch_put('/api/users/:id', 'UserController::put'); dispatch_delete('/api/users/:id', 'UserController::remove'); dispatch_get('/api/users/search/:name', 'UserController::search'); //pages dispatch('/', 'MainController::index'); run();
option('env', ENV_DEVELOPMENT); option('debug', true); option('session', 'Yummy_Plus3_Session_Cookie'); // true, false or the name of your session option('encoding', 'utf-8'); } // END function configure() # the index request dispatch('/', function () { return 'hello world'; }); dispatch('/phpinfo', function () { phpinfo(); return; }); $echo = function () { setcookie('example', 'test'); $response = array(); foreach ($GLOBALS as $key => $data) { if ($key != 'GLOBALS') { $response[$key] = $data; } } $response['_HEADERS'] = http_get_request_headers(); return json($response); }; dispatch_get('/echo', $echo); dispatch_post('/echo', $echo); dispatch_put('/echo', $echo); dispatch_delete('/echo', $echo); run();
$cfg = $GLOBALS['cfg']; $db = $GLOBALS['db']; $arrServer = $db->select("SELECT *\n FROM {$cfg['tblServer']}\n WHERE id={$id}"); if (!$arrServer) { halt(NOT_FOUND); return; } set('server', $arrServer[0]); if (isAjaxRequest()) { return js('servers/edit.js.php', null); } else { halt(HTTP_NOT_IMPLEMENTED); } } # update existing daemon dispatch_put('/servers', 'servers_update'); function servers_update() { $cfg = $GLOBALS['cfg']; $db = $GLOBALS['db']; $id = intval($_POST['id']); $fqdn = $db->escape($_POST['fqdn']); $desc = $db->escape($_POST['desc']); $ip = $db->escape($_POST['ip']); $mac = $db->escape($_POST['mac']); $result = $db->update("UPDATE {$cfg['tblServer']}\n SET fqdn='{$fqdn}', `desc`='{$desc}', ip='{$ip}', mac='{$mac}'\n WHERE id={$id}\n LIMIT 1"); if (!$result) { halt(SERVER_ERROR); return; } redirect_to('servers');
die("There was an error. The API responded with the error type <b>{$e->body['error']}</b> and the message <b>{$e->body['error_description']}</b><br><a href='" . url_for('/') . "'>Go back</a>"); } } if ($story_app) { $_SESSION['story_app'] = $story_app; $_SESSION['space'] = $api->space->get($_SESSION['story_app']['space_id']); redirect_to(''); } else { // Something went wrong. Display appropriate error message. unset($_SESSION['access_token']); unset($_SESSION['refresh_token']); $error_description = !empty($_GET['error_description']) ? htmlentities($_GET['error_description']) : 'You do not have access to the ScrumIO apps. Try logging in as a different user.'; return html('login.html.php', NULL, array('oauth_url' => option('OAUTH_URL'), 'error_description' => $error_description)); } } dispatch_put('/item/:item_id', 'update_time_left'); function update_time_left() { global $api; $item_id = params('item_id'); $state = $_POST['state']; $data = array(array('value' => $state)); $api->item->updateFieldValue($item_id, ITEM_STATE_ID, $data); // Set time_left to '0' when moving to one of the 'done' states if (in_array($state, array(STATE_DEV_DONE, STATE_QA_DONE, STATE_PO_DONE))) { $api->item->updateFieldValue($item_id, ITEM_TIMELEFT_ID, array(array('value' => 0)), 1); } elseif ($state == STATE_NOT_STARTED) { $item = $api->item->getBasic($item_id); $item = new ScrumioItem($item); $api->item->updateFieldValue($item_id, ITEM_TIMELEFT_ID, array(array('value' => $item->estimate * 60 * 60)), 1); }
option('env', $env); option('dsn', $dsn); option('db_conn', $db); option('debug', true); } function after($output) { $time = number_format((double) substr(microtime(), 0, 10) - LIM_START_MICROTIME, 6); $output .= "<!-- page rendered in {$time} sec., on " . date(DATE_RFC822) . "-->"; return $output; } layout('layout/default.html.php'); // main controller dispatch('/', 'main_page'); // books controller dispatch_get('books', 'books_index'); dispatch_post('books', 'books_create'); dispatch_get('books/new', 'books_new'); dispatch_get('books/:id/edit', 'books_edit'); dispatch_get('books/:id', 'books_show'); dispatch_put('books/:id', 'books_update'); dispatch_delete('books/:id', 'books_destroy'); // authors controller dispatch_get('authors', 'authors_index'); dispatch_post('authors', 'authors_create'); dispatch_get('authors/new', 'authors_new'); dispatch_get('authors/:id/edit', 'authors_edit'); dispatch_get('authors/:id', 'authors_show'); dispatch_put('authors/:id', 'authors_update'); dispatch_delete('authors/:id', 'authors_destroy'); run();
dispatch_put('/settings', function () { exec('ip link show ' . escapeshellarg($_POST['wifi_device']), $output, $retcode); $wifi_device_exists = $retcode == 0; $service_enabled = isset($_POST['service_enabled']) ? 1 : 0; $wifi_ssid_uniqueness = array(); $ip4_nat_prefix_uniqueness = array(); $ip6_net_uniqueness = array(); $ssids = array(); $id = 0; if ($service_enabled == 1) { try { foreach ($_POST['ssid'] as $key => $ssid) { $id = $key + 1; $ssid['ip6_net'] = empty($ssid['ip6_net']) ? 'none' : $ssid['ip6_net']; $ssid['ip6_addr'] = 'none'; $ssid['ip6_firewall'] = isset($ssid['ip6_firewall']) ? 1 : 0; $ssid['wifi_secure'] = isset($ssid['wifi_secure']) ? 1 : 0; if (!$ssid['wifi_secure']) { $ssid['wifi_passphrase'] = 'none'; } if (in_array($ssid['wifi_ssid'], $wifi_ssid_uniqueness)) { throw new Exception(_('All Wifi names must be unique')); } else { array_push($wifi_ssid_uniqueness, $ssid['wifi_ssid']); } if (in_array($ssid['ip4_nat_prefix'], $ip4_nat_prefix_uniqueness)) { throw new Exception(_('All IPv4 NAT prefixes must be unique')); } else { array_push($ip4_nat_prefix_uniqueness, $ssid['ip4_nat_prefix']); } if ($ssid['ip6_net'] != 'none' && in_array($ssid['ip6_net'], $ip6_net_uniqueness)) { throw new Exception(_('All IPv6 delegated prefixes must be unique')); } else { array_push($ip6_net_uniqueness, $ssid['ip6_net']); } if (empty($ssid['wifi_ssid']) || empty($ssid['wifi_passphrase'])) { throw new Exception(_('Your Wifi Hotspot needs a name and a password')); } if ($ssid['wifi_secure'] && (strlen($ssid['wifi_passphrase']) < 8 || strlen($ssid['wifi_passphrase']) > 63)) { throw new Exception(_('Your password must from 8 to 63 characters (WPA2 passphrase)')); } if ($ssid['wifi_secure'] && preg_match('/[^[:print:]]/', $ssid['wifi_passphrase'])) { $msg = _('Only <LINK:ASCII>printable ASCII characters</LINK:ASCII> are permitted in your password'); $msg = str_replace('<LINK:ASCII>', '<a href="https://upload.wikimedia.org/wikipedia/commons/thumb/4/42/ASCII_full.svg/217px-ASCII_full.svg.png" class="alert-link">', $msg); $msg = str_replace('</LINK:ASCII>', '</a>', $msg); throw new Exception($msg); } if (!$wifi_device_exists) { throw new Exception(_('The wifi antenna interface seems not exist on the system')); } if ($ssid['ip6_net'] != 'none') { $ssid['ip6_net'] = ipv6_expanded($ssid['ip6_net']); if (empty($ssid['ip6_net'])) { throw new Exception(_('The IPv6 Delegated Prefix format looks bad')); } $ip6_blocs = explode(':', $ssid['ip6_net']); $ssid['ip6_addr'] = "{$ip6_blocs[0]}:{$ip6_blocs[1]}:{$ip6_blocs[2]}:{$ip6_blocs[3]}:{$ip6_blocs[4]}:{$ip6_blocs[5]}:{$ip6_blocs[6]}:42"; $ssid['ip6_net'] = ipv6_compressed($ssid['ip6_net']); $ssid['ip6_addr'] = ipv6_compressed($ssid['ip6_addr']); } if (!empty($ssid['ip6_dns0'])) { $ssid['ip6_dns0'] = ipv6_expanded($ssid['ip6_dns0']); if (empty($ssid['ip6_dns0'])) { throw new Exception(_('The format of the first IPv6 DNS Resolver looks bad')); } $ssid['ip6_dns0'] = ipv6_compressed($ssid['ip6_dns0']); if (!empty($ssid['ip6_dns1'])) { $ssid['ip6_dns1'] = ipv6_expanded($ssid['ip6_dns1']); if (empty($ssid['ip6_dns1'])) { throw new Exception(_('The format of the second IPv6 DNS Resolver looks bad')); } $ssid['ip6_dns1'] = ipv6_compressed($ssid['ip6_dns1']); } } if (inet_pton($ssid['ip4_dns0']) === false) { throw new Exception(_('The format of the first IPv4 DNS Resolver looks bad')); } if (inet_pton($ssid['ip4_dns1']) === false) { throw new Exception(_('The format of the second IPv4 DNS Resolver looks bad')); } if (inet_pton("{$ssid['ip4_nat_prefix']}.0") === false) { throw new Exception(_('The format of the IPv4 NAT Prefix (/24) looks bad: x.x.x expected')); } if (filter_var("{$ssid['ip4_nat_prefix']}.0", FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE) !== false) { throw new Exception(_('The IPv4 NAT Prefix must be from a private range')); } array_push($ssids, $ssid); } } catch (Exception $e) { flash('error', _('Hotspot') . " {$id}: " . $e->getMessage() . ' (' . _('configuration not updated') . ').'); goto redirect; } } stop_service(); ynh_setting_set('service_enabled', $service_enabled); $settings = array(); if ($service_enabled == 1) { foreach ($ssids as $ssid) { foreach ($ssid as $setting => $value) { $settings[$setting] .= "{$value}|"; } } ynh_setting_set('multissid', count($ssids)); ynh_setting_set('wifi_device', $_POST['wifi_device']); ynh_setting_set('wifi_channel', $_POST['wifi_channel']); foreach ($settings as $setting => $value) { ynh_setting_set($setting, preg_replace('/\\|$/', '', $value)); } $retcode = start_service(); if ($retcode == 0) { flash('success', _('Configuration updated and service successfully reloaded')); } else { flash('error', _('Configuration updated but service reload failed')); } } else { flash('success', _('Service successfully disabled')); } redirect: redirect_to('/'); });
<?php require_once "lib/limonade.php"; dispatch_get("/", "redirect_data"); dispatch_get("/data", "data"); dispatch_get("/data/extract", "data_extract"); dispatch_get("/document", "document"); dispatch_get("/promo", "promo"); dispatch_post("/document", "add_document"); dispatch_post("/promo", "add_promo"); dispatch_put("/data/:dataid", "alter_data"); dispatch_put("/document/:documentid", "alter_document"); dispatch_put("/promo/:promoid", "alter_promo"); dispatch_delete("/document/:fileid", "delete_document"); dispatch_delete("/promo/:promoid", "delete_promo"); try { run(); } catch (Exception $e) { error_log($e); }
dispatch_put('/settings', function () { $service_enabled = isset($_POST['service_enabled']) ? 1 : 0; if ($service_enabled == 1) { try { $_POST['opt_name'] = htmlentities(str_replace('"', '', $_POST['opt_name'])); if (empty($_POST['opt_name'])) { throw new Exception(_('The name cannot be empty')); } if ($_POST['wifi_device_id'] == -1) { throw new Exception(_('You need to select an associated hotspot')); } } catch (Exception $e) { flash('error', _('PirateBox') . " {$id}: " . $e->getMessage() . ' (' . _('configuration not updated') . ').'); goto redirect; } } stop_service(); ynh_setting_set('service_enabled', $service_enabled); if ($service_enabled == 1) { ynh_setting_set('opt_name', $_POST['opt_name']); ynh_setting_set('opt_renaming', isset($_POST['opt_renaming']) ? 1 : 0); ynh_setting_set('opt_maxspace', $_POST['opt_maxspace']); ynh_setting_set('opt_deleting', isset($_POST['opt_deleting']) ? 1 : 0); ynh_setting_set('opt_chat', isset($_POST['opt_chat']) ? 1 : 0); ynh_setting_set('wifi_device_id', $_POST['wifi_device_id']); $retcode = start_service(); if ($retcode == 0) { flash('success', _('Configuration updated and service successfully reloaded')); } else { flash('error', _('Configuration updated but service reload failed')); } } else { flash('success', _('Service successfully disabled')); } redirect: redirect_to('/'); });
dispatch('/login', 'login'); dispatch_post('/login', 'doLogin'); dispatch('/logout', 'logout'); dispatch('/postinstall', 'postInstall'); dispatch_post('/postinstall', 'doPostInstall'); dispatch('/lang/:locale', 'changeLocale'); dispatch('/images/:name/:size', 'image_show'); dispatch('/images/*.jpg/:size', 'image_show_jpeg_only'); //dispatch('/ping/:apps', 'ping'); /** * => controllers/domain.php */ dispatch('/domain', 'domains'); dispatch('/domain/list', 'listDomains'); dispatch('/domain/add', 'addDomainForm'); dispatch_put('/domain/update', 'updateDomains'); //dispatch('/domain/changeMain', 'changeMainForm'); //dispatch_put('/domain/changeMain', 'changeMain'); /** * => controllers/app.php */ //dispatch('/app', 'apps'); //dispatch('/app/list', 'listApps'); //dispatch('/app/:operation/:app', 'operateApp'); //dispatch('/app/:operation/:app/ajax', 'operateAppAjax'); /** * => controllers/user.php */ dispatch('/user', 'user'); dispatch('/user/list', 'listUser'); dispatch('/user/details/:user', 'userDetails');
function fz_dispatch_put($path_or_array, $controller, $action) { return dispatch_put($path_or_array, 'fz_dispatcher', array('params' => array('controller' => $controller, 'action' => $action))); }
$db = $GLOBALS['db']; $id = intval(params('id')); $arrRole = $db->select("SELECT *\n FROM {$cfg['tblRole']}\n WHERE id={$id}"); if ($arrRole) { set('role', $arrRole[0]); if (isAjaxRequest()) { return js('roles/edit.js.php', null); } else { return html('roles/edit.html.php', null); } } else { halt(NOT_FOUND); } } # update an existing role dispatch_put('/roles', 'roles_update'); function roles_update() { $cfg = $GLOBALS['cfg']; $db = $GLOBALS['db']; $id = intval($_POST['id']); $name = $db->escape($_POST['name']); $desc = $db->escape($_POST['desc']); $result = $db->update("UPDATE {$cfg['tblRole']}\n SET name='{$name}', `desc`='{$desc}'\n WHERE id={$id}\n LIMIT 1"); if ($result) { redirect_to('roles'); } else { halt(SERVER_ERROR); } } #remove a role