/** * Ajoute une clé API */ private function add() { $sApiKey = md5(time() * $this->oRequest->getParam('user', 'int') * rand()); $oApiKey = new ApiKey($sApiKey, $this->oRequest->getParam('user', 'int'), $this->oRequest->getParam('read', 'boolean'), $this->oRequest->getParam('write', 'boolean')); $oApiKey->store(); Logger::log('admin', Language::translate('API_ADMIN_KEY_ADDLOG') . $sApiKey . ' [' . $this->oCurrentUser->getLogin() . ']'); $this->oView->addAlert(Language::translate('API_ADMIN_KEY_ADD'), 'success'); }
public function insertNewRouter() { $check_router_hostname_exist = Router_old::getRouterByHostname($_POST['hostname']); if (!isset($_POST['allow_router_auto_assign'])) { $_POST['allow_router_auto_assign'] = 0; $_POST['router_auto_assign_login_string'] = ''; } if ($_POST['allow_router_auto_assign'] == '1' and !empty($_POST['router_auto_assign_login_string'])) { $check_router_auto_assign_login_string = Router_old::getRouterByAutoAssignLoginString($_POST['router_auto_assign_login_string']); } if (empty($_POST['hostname'])) { $message[] = array("Bitte geben Sie einen Hostname an.", 2); Message::setMessage($message); return array("result" => false, "router_id" => $router_id); } elseif (!empty($check_router_hostname_exist)) { $message[] = array("Ein Router mit dem Hostnamen {$_POST['hostname']} existiert bereits, bitte wählen Sie einen anderen Hostnamen.", 2); Message::setMessage($message); return array("result" => false, "router_id" => $router_id); } elseif (!(is_string($_POST['hostname']) and strlen($_POST['hostname']) <= 255 and preg_match("/^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])(\\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9]))*\$/", $_POST['hostname']))) { //check for valid hostname as specified in rfc 1123 //see http://stackoverflow.com/a/3824105 $message[] = array("Der Hostname ist ungültig. Erlaubt sind Hostnames nach RFC 1123.", 2); Message::setMessage($message); return array("result" => false, "router_id" => $router_id); } elseif (!empty($check_router_auto_assign_login_string)) { $message[] = array("Der Router Auto Assign Login String wird bereits verwendet.", 2); Message::setMessage($message); return array("result" => false, "router_id" => $router_id); } elseif ($_POST['allow_router_auto_assign'] == '1' and ($_POST['router_auto_assign_login_string'] == "Mac-Adresse..." or empty($_POST['router_auto_assign_login_string']) or ctype_space($_POST['router_auto_assign_login_string']))) { $message[] = array("Wenn Automatische Routerzuweisung aktiviert ist, muss eine Mac-Adresse gesetzt werden.", 2); $message[] = array("Du findest die Mac-Adresse oft auf der Rückseite des Routers.", 0); Message::setMessage($message); return array("result" => false, "router_id" => $router_id); } else { if (!is_numeric($_POST['latitude']) or !is_numeric($_POST['longitude'])) { $_POST['latitude'] = 0; $_POST['longitude'] = 0; } try { $stmt = DB::getInstance()->prepare("INSERT INTO routers (user_id, create_date, update_date, crawl_method, hostname, allow_router_auto_assign, router_auto_assign_login_string, description, location, latitude, longitude, chipset_id)\n\t\t\t\t\t\t\t\t VALUES (?, NOW(), NOW(), ?, ?, ?, ?, ?, ?, ?, ?, ?)"); $stmt->execute(array($_SESSION['user_id'], $_POST['crawl_method'], $_POST['hostname'], $_POST['allow_router_auto_assign'], $_POST['router_auto_assign_login_string'], $_POST['description'], $_POST['location'], $_POST['latitude'], $_POST['longitude'], $_POST['chipset_id'])); $router_id = DB::getInstance()->lastInsertId(); } catch (PDOException $e) { echo $e->getMessage(); echo $e->getTraceAsString(); } $crawl_cycle_id = Crawling::getLastEndedCrawlCycle(); $router_status = new RouterStatus(false, (int) $crawl_cycle_id['id'], (int) $router_id, "offline"); $router_status->store(); //add new api key do { $api_key = new ApiKey(false, ApiKey::generateApiKey(), (int) $router_id, "router", "Initial key"); $api_key_id = $api_key->store(); } while (!$api_key_id); if ($_POST['allow_router_auto_assign'] == '1' and !empty($_POST['router_auto_assign_login_string'])) { RoutersNotAssigned::deleteByAutoAssignLoginString($_POST['router_auto_assign_login_string']); } $message[] = array("Der Router {$_POST['hostname']} wurde angelegt.", 1); //Add event for new router //TODO: add Router Object to data array $event = new Event(false, 'router', (int) $router_id, 'new', array()); $event->store(); //Send Message to twitter if ($_POST['twitter_notification'] == '1') { Message::postTwitterMessage(Config::getConfigValueByName('community_name') . " hat einen neuen #Freifunk Knoten! Wo? Schau nach: " . Config::getConfigValueByName('url_to_netmon') . "/router.php?router_id={$router_id}"); } Message::setMessage($message); return array("result" => true, "router_id" => $router_id); } }
<?php require_once 'runtime.php'; require_once ROOT_DIR . '/lib/core/ApiKeyList.class.php'; require_once ROOT_DIR . '/lib/core/Router.class.php'; require_once ROOT_DIR . '/lib/core/User.class.php'; if ($_GET['section'] == "insert_add") { //add new api key do { $api_key = new ApiKey(false, ApiKey::generateApiKey(), (int) $_GET['object_id'], $_GET['object_type'], $_POST['description']); $api_key_id = $api_key->store(); } while (!$api_key_id); $message[] = array("Es wurde ein neuer API-Key " . $api_key->getApiKey() . " generiert und gespeichert.", 1); Message::setMessage($message); header('Location: ./api_key_list.php?object_id=' . $_GET['object_id'] . '&object_type=' . $_GET['object_type']); } elseif ($_GET['section'] == "delete") { $api_key = new ApiKey((int) $_GET['api_key_id']); $api_key->fetch(); $message[] = array("Der API-Key " . $api_key->getApiKey() . " wurde gelöscht.", 1); $api_key->delete(); Message::setMessage($message); header('Location: ./api_key_list.php?object_id=' . $_GET['object_id'] . '&object_type=' . $_GET['object_type']); }