コード例 #1
0
ファイル: api.php プロジェクト: wAmpIre/netmon
 private function event()
 {
     if ($this->get_request_method() == "GET" && isset($this->_request['id'])) {
         $event = new Event((int) $this->_request['id']);
         if ($event->fetch()) {
             $domxmldata = $event->getDomXMLElement($this->domxml);
             $this->response($this->finishxml($domxmldata), 200);
         } else {
             $this->error_code = 1;
             $this->error_message = "Event not found";
             $this->response($this->finishxml(), 404);
         }
     } elseif ($this->get_request_method() == "POST" or $this->get_request_method() == "GET" && !isset($this->_request['id']) && count($_GET) > 1) {
         if ($this->isApiKeyValid($this->api_key)) {
             $data = !empty($_POST) ? $_POST : $_GET;
             $event = new Event(false, false, $this->_request['object'], (int) $this->_request['object_id'], $this->_request['action'], $this->_request['data']);
             $event_id = $event->store();
             if ($event_id != false) {
                 header('Location: ' . ConfigLine::configByName('url_to_netmon') . '/api/rest/event/' . $event_id);
             } else {
                 $this->authentication = false;
                 $this->error_code = 2;
                 $this->error_message = "The Event could not be created. Your request seems to miss some data.";
                 $this->response($this->finishxml(), 400);
             }
         } else {
             $this->error_code = 2;
             $this->error_message = "The api_key is not valid.";
             $this->response($this->finishxml(), 401);
         }
     } else {
         $this->response('', 406);
     }
 }
コード例 #2
0
if ($_GET['section'] == "router_auto_assign") {
    $router_data = Router_old::getRouterByAutoAssignLoginString($_GET['router_auto_assign_login_string']);
    if (empty($router_data)) {
        $router = RoutersNotAssigned::getRouterByAutoAssignLoginString($_GET['router_auto_assign_login_string']);
        if (empty($router)) {
            //Make DB Insert
            try {
                DB::getInstance()->exec("INSERT INTO routers_not_assigned (create_date, update_date, hostname, router_auto_assign_login_string, interface)\n\t\t\t\t\t\t\t VALUES (NOW(), NOW(), '{$_GET['hostname']}', '{$_GET['router_auto_assign_login_string']}', '{$_GET['interface']}');");
            } catch (PDOException $e) {
                echo $e->getMessage();
            }
            $not_assigned_id = DB::getInstance()->lastInsertId();
            //Make history
            $actual_crawl_cycle = Crawling::getActualCrawlCycle();
            $event = new Event(false, (int) $actual_crawl_cycle['id'], 'not_assigned_router', (int) $not_assigned_id, 'new', array('router_auto_assign_login_string' => $_GET['router_auto_assign_login_string']));
            $event->store();
            echo "error;new_not_assigned;;{$_GET['router_auto_assign_login_string']}";
        } else {
            try {
                $result = DB::getInstance()->exec("UPDATE routers_not_assigned SET\n\t\t\t\t\t\t\t\t\t  update_date = NOW()\n\t\t\t\t\t\t\t\t   WHERE id = '{$router['id']}'");
            } catch (PDOException $e) {
                echo $e->getMessage();
            }
            echo "error;updated_not_assigned;;{$_GET['router_auto_assign_login_string']}";
        }
    } elseif ($router_data['allow_router_auto_assign'] == 0) {
        echo "error;autoassign_not_allowed;{$_GET['router_auto_assign_login_string']}";
    } elseif (!empty($router_data['router_auto_assign_hash'])) {
        echo "error;already_assigned;{$_GET['router_auto_assign_login_string']}";
    } else {
        //generate random string
コード例 #3
0
 public function testPopulateReverseOneToOne()
 {
     $event = new Event();
     $event->setTitle('Test Event');
     $event->setStartDate('today');
     $event->populateEventSlot();
     $event->populateEventDetail();
     $event->store();
 }
コード例 #4
0
 public function testDeleteForceCascadeManyToMany()
 {
     $event = new Event();
     $event->setTitle('Delete Restrict Event');
     $event->setStartDate(new fDate());
     $event->associateArtists(array(1));
     $event->store();
     $event->delete(TRUE);
     $this->assertEquals(FALSE, $event->exists());
 }
コード例 #5
0
ファイル: Router.class.php プロジェクト: wAmpIre/netmon
 public function store()
 {
     if ($this->getUserId() != 0 and $this->getHostname() != "" and $this->getCrawlMethod() != "" and $this->getChipsetId() != 0) {
         $router_test = new Router(false, false, $this->getHostname());
         $router_test->fetch();
         if ($this->getRouterId() != 0 and !($router_test->getRouterId() != $this->getRouterId() and $router_test->getHostname() == $this->getHostname())) {
             try {
                 $stmt = DB::getInstance()->prepare("UPDATE routers SET\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tuser_id = ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\thostname = ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tdescription = ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tlocation = ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tlatitude = ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tlongitude = ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tchipset_id = ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcrawl_method = ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tupdate_date = NOW()\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE id=?");
                 $stmt->execute(array($this->getUserId(), $this->getHostname(), $this->getDescription(), $this->getLocation(), $this->getLatitude(), $this->getLongitude(), $this->getChipsetId(), $this->getCrawlMethod(), $this->getRouterId()));
                 return $stmt->rowCount();
             } catch (PDOException $e) {
                 echo $e->getMessage();
                 echo $e->getTraceAsString();
             }
         } elseif ($router_test->getRouterId() == 0) {
             try {
                 $stmt = DB::getInstance()->prepare("INSERT INTO routers (user_id, hostname, description, location, \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tlatitude, longitude, chipset_id, crawl_method,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcreate_date, update_date)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tVALUES (?, ?, ?, ?, ?, ?, ?, ?, NOW(), NOW())");
                 $stmt->execute(array($this->getUserId(), $this->getHostname(), $this->getDescription(), $this->getLocation(), $this->getLatitude(), $this->getLongitude(), $this->getChipsetId(), $this->getCrawlMethod()));
                 $this->setRouterId((int) DB::getInstance()->lastInsertId());
                 //create event for new router
                 $event = new Event(false, false, 'router', $this->getRouterId(), 'new', array('hostname' => $router->getHostname()));
                 $event->store();
                 return $this->getRouterId();
             } catch (PDOException $e) {
                 echo $e->getMessage();
                 echo $e->getTraceAsString();
             }
         }
     }
     return false;
 }
コード例 #6
0
ファイル: Consumable.php プロジェクト: mrjwc/printmaster
 /**
  * Install a consumable to a printer
  */
 public function installTo($printer)
 {
     global $db;
     #printf('Installing consumable %s to printer %s.', $this->getName(), $printer->getName());
     #fCore::dump($printer);
     // Validation checks
     // 1. Check printer model is compatible
     $models = $this->getModels();
     if (!in_array($printer->getModelId(), $models)) {
         $this->err = sprintf('Consumable %s not compatible with printer %s.', $this->getName(), $printer->getName());
         return FALSE;
     }
     // 2. Check quantity
     if ($this->getQty() < 1) {
         $this->err = sprintf('No stock of the consumable %s.', $this->getName());
         return FALSE;
     }
     // Finished validation
     // Add 'event'
     try {
         $e = new Event();
         $e->setPrinterId($printer->getId());
         $e->setConsumableId($this->getId());
         $e->setDate(date('Y-m-d H:i:s'));
         $e->setCost($this->getCost());
         $e->store();
     } catch (fExpectedException $e) {
         #fMessaging::create('error', fURL::get(), $e->getMessage());
         $this->err = $e->getMessage();
         return FALSE;
     } catch (fSQLException $e) {
         #fMessaging::create('error', fURL::get(), 'Database error: ' . $e->getMessage());
         $this->err = $e->getMessage();
         return FALSE;
     }
     // Decrease stock
     try {
         $sql = 'UPDATE consumables SET qty = qty - 1 WHERE id = %i LIMIT 1';
         $query = $db->execute($sql, $this->getId());
     } catch (fSQLException $e) {
         $this->err = $e->getMessage();
         return FALSE;
     }
     // Return true
     #echo 'Done!';
     return TRUE;
 }
コード例 #7
0
ファイル: routereditor.class.php プロジェクト: wAmpIre/netmon
 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);
     }
 }