<commit_before><?php
/*
 * WiND - Wireless Nodes Database
 *
 * Copyright (C) 2005-2014 	by WiND Contributors (see AUTHORS.txt)
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

class node_editor_ipaddr {

	var $tpl;
	
	function __construct() {
		
	}
	
	function form_ipaddr() {
		global $db, $vars;
		$form_ipaddr = new form(array('FORM_NAME' => 'form_ipaddr'));
		$form_ipaddr->db_data('ip_addresses.hostname, ip_addresses.ip, ip_addresses.mac, ip_addresses.type, ip_addresses.always_on, ip_addresses.info');
		$form_ipaddr->db_data_values("ip_addresses", "id", get('ipaddr'));
		if (get('ipaddr') != 'add') {
			$form_ipaddr->data[1]['value'] = long2ip($form_ipaddr->data[1]['value']);
		}
		return $form_ipaddr;
	}
	
	function output() {
		if ($_SERVER['REQUEST_METHOD'] == 'POST' && method_exists($this, 'output_onpost_'.$_POST['form_name'])) return call_user_func(array($this, 'output_onpost_'.$_POST['form_name']));
		global $construct;
		$this->tpl['ip_address_method'] = (get('ipaddr') == 'add' ? 'add' : 'edit' );
		$this->tpl['form_ipaddr'] = $construct->form($this->form_ipaddr(), __FILE__);
		return template($this->tpl, __FILE__);
	}

	function output_onpost_form_ipaddr() {
		global $construct, $main, $db;
		$form_ipaddr = $this->form_ipaddr();
		$ipaddr = get('ipaddr');
		$ret = TRUE;
		$_POST['ip_addresses__ip'] = ip2long($_POST['ip_addresses__ip']);
		$ret = $form_ipaddr->db_set(array('node_id' => intval(get('node'))),
								"ip_addresses", "id", $ipaddr);
		
		if ($ret) {
			$main->message->set_fromlang('info', 'insert_success', make_ref('/node_editor', array("node" => get('node'))));<commit_msg>Add checking for ip_addresse hostnames.<commit_after><?php
/*
 * WiND - Wireless Nodes Database
 *
 * Copyright (C) 2005-2014 	by WiND Contributors (see AUTHORS.txt)
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

class node_editor_ipaddr {

	var $tpl;
	
	function __construct() {
		
	}
	
	function form_ipaddr() {
		global $db, $vars;
		$form_ipaddr = new form(array('FORM_NAME' => 'form_ipaddr'));
		$form_ipaddr->db_data('ip_addresses.hostname, ip_addresses.ip, ip_addresses.mac, ip_addresses.type, ip_addresses.always_on, ip_addresses.info');
		$form_ipaddr->db_data_values("ip_addresses", "id", get('ipaddr'));
		if (get('ipaddr') != 'add') {
			$form_ipaddr->data[1]['value'] = long2ip($form_ipaddr->data[1]['value']);
		}
		return $form_ipaddr;
	}
	
	function output() {
		if ($_SERVER['REQUEST_METHOD'] == 'POST' && method_exists($this, 'output_onpost_'.$_POST['form_name'])) return call_user_func(array($this, 'output_onpost_'.$_POST['form_name']));
		global $construct;
		$this->tpl['ip_address_method'] = (get('ipaddr') == 'add' ? 'add' : 'edit' );
		$this->tpl['form_ipaddr'] = $construct->form($this->form_ipaddr(), __FILE__);
		return template($this->tpl, __FILE__);
	}

	function output_onpost_form_ipaddr() {
		global $construct, $main, $db;
		$form_ipaddr = $this->form_ipaddr();
		$ipaddr = get('ipaddr');
		$ret = TRUE;
		$_POST['ip_addresses__ip'] = ip2long($_POST['ip_addresses__ip']);
		$_POST['ip_addresses__hostname'] = validate_hostname($_POST['ip_addresses__hostname']);
		$ret = $form_ipaddr->db_set(array('node_id' => intval(get('node'))),
								"ip_addresses", "id", $ipaddr);
		
		if ($ret) {
			$main->message->set_fromlang('info', 'insert_success', make_ref('/node_editor', array("node" => get('node'))));
{'fraction_non_alphanumeric': 0.15683297180043385, 'fraction_numerical': 0.005639913232104121, 'mean_word_length': 5.043250327653998, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4362247', 'n_tokens_mistral': 1618, 'n_tokens_neox': 1529, 'n_words': 397}