Rev 277 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 277 | Rev 360 | ||
---|---|---|---|
Line 28... | Line 28... | ||
28 | if (!empty($ipv4)) { |
28 | if (!empty($ipv4)) { |
29 | if (strpos($ipv4, '/') === false) $ipv4 .= '/32'; |
29 | if (strpos($ipv4, '/') === false) $ipv4 .= '/32'; |
30 | list($bare, $cidr) = explode('/', $ipv4); |
30 | list($bare, $cidr) = explode('/', $ipv4); |
31 | $this->bare = $bare; |
31 | $this->bare = $bare; |
32 | $this->cidr = $cidr; |
32 | $this->cidr = $cidr; |
33 | if (!ipv4_valid($bare)) throw new OIDplusException("Invalid IPv4"); |
33 | if (!ipv4_valid($bare)) throw new OIDplusException(_L('Invalid IPv4')); |
34 | if (!is_numeric($cidr)) throw new OIDplusException("Invalid IPv4"); |
34 | if (!is_numeric($cidr)) throw new OIDplusException(_L('Invalid IPv4')); |
35 | if ($cidr < 0) throw new OIDplusException("Invalid IPv4"); |
35 | if ($cidr < 0) throw new OIDplusException(_L('Invalid IPv4')); |
36 | if ($cidr > 32) throw new OIDplusException("Invalid IPv4"); |
36 | if ($cidr > 32) throw new OIDplusException(_L('Invalid IPv4')); |
37 | $this->bare = ipv4_normalize($this->bare); |
37 | $this->bare = ipv4_normalize($this->bare); |
38 | } |
38 | } |
39 | } |
39 | } |
40 | 40 | ||
41 | public static function parse($node_id) { |
41 | public static function parse($node_id) { |
Line 43... | Line 43... | ||
43 | if ($namespace !== 'ipv4') return false; |
43 | if ($namespace !== 'ipv4') return false; |
44 | return new self($ipv4); |
44 | return new self($ipv4); |
45 | } |
45 | } |
46 | 46 | ||
47 | public static function objectTypeTitle() { |
47 | public static function objectTypeTitle() { |
48 | return "IPv4 Network Blocks"; |
48 | return _L('IPv4 Network Blocks'); |
49 | } |
49 | } |
50 | 50 | ||
51 | public static function objectTypeTitleShort() { |
51 | public static function objectTypeTitleShort() { |
52 | return "IPv4"; |
52 | return _L('IPv4'); |
53 | } |
53 | } |
54 | 54 | ||
55 | public static function ns() { |
55 | public static function ns() { |
56 | return 'ipv4'; |
56 | return 'ipv4'; |
57 | } |
57 | } |
Line 71... | Line 71... | ||
71 | public function addString($str) { |
71 | public function addString($str) { |
72 | if (strpos($str, '/') === false) $str .= "/32"; |
72 | if (strpos($str, '/') === false) $str .= "/32"; |
73 | 73 | ||
74 | if (!$this->isRoot()) { |
74 | if (!$this->isRoot()) { |
75 | if (!ipv4_in_cidr($this->bare.'/'.$this->cidr, $str)) { |
75 | if (!ipv4_in_cidr($this->bare.'/'.$this->cidr, $str)) { |
76 | throw new OIDplusException("Cannot add this address, because it must be inside the address range of the superior range."); |
76 | throw new OIDplusException(_L('Cannot add this address, because it must be inside the address range of the superior range.')); |
77 | } |
77 | } |
78 | } |
78 | } |
79 | 79 | ||
80 | list($ipv4, $cidr) = explode('/', $str); |
80 | list($ipv4, $cidr) = explode('/', $str); |
81 | if ($cidr < 0) throw new OIDplusException("Invalid IPv4 address '$str'"); |
81 | if ($cidr < 0) throw new OIDplusException(_L('Invalid IPv4 address %1',$str)); |
82 | if ($cidr > 32) throw new OIDplusException("Invalid IPv4 address '$str'"); |
82 | if ($cidr > 32) throw new OIDplusException(_L('Invalid IPv4 address %1',$str)); |
83 | $ipv4_normalized = ipv4_normalize($ipv4); |
83 | $ipv4_normalized = ipv4_normalize($ipv4); |
84 | if (!$ipv4_normalized) throw new OIDplusException("Invalid IPv4 address '$str'"); |
84 | if (!$ipv4_normalized) throw new OIDplusException(_L('Invalid IPv4 address %1',$str)); |
85 | return 'ipv4:'.$ipv4_normalized.'/'.$cidr; // overwrite; no hierarchical tree |
85 | return 'ipv4:'.$ipv4_normalized.'/'.$cidr; // overwrite; no hierarchical tree |
86 | } |
86 | } |
87 | 87 | ||
88 | public function crudShowId(OIDplusObject $parent) { |
88 | public function crudShowId(OIDplusObject $parent) { |
89 | return $this->ipv4; |
89 | return $this->ipv4; |
Line 112... | Line 112... | ||
112 | if ($this->isRoot()) { |
112 | if ($this->isRoot()) { |
113 | $title = OIDplusIpv4::objectTypeTitle(); |
113 | $title = OIDplusIpv4::objectTypeTitle(); |
114 | 114 | ||
115 | $res = OIDplus::db()->query("select * from ###objects where parent = ?", array(self::root())); |
115 | $res = OIDplus::db()->query("select * from ###objects where parent = ?", array(self::root())); |
116 | if ($res->num_rows() > 0) { |
116 | if ($res->num_rows() > 0) { |
117 | $content = 'Please select a network block in the tree view at the left to show its contents.'; |
117 | $content = _L('Please select a network block in the tree view at the left to show its contents.'); |
118 | } else { |
118 | } else { |
119 | $content = 'Currently, no network blocks are registered in the system.'; |
119 | $content = _L('Currently, no network blocks are registered in the system.'); |
120 | } |
120 | } |
121 | 121 | ||
122 | if (!$this->isLeafNode()) { |
122 | if (!$this->isLeafNode()) { |
123 | if (OIDplus::authUtils()::isAdminLoggedIn()) { |
123 | if (OIDplus::authUtils()::isAdminLoggedIn()) { |
124 | $content .= '<h2>Manage root objects</h2>'; |
124 | $content .= '<h2>'._L('Manage root objects').'</h2>'; |
125 | } else { |
125 | } else { |
126 | $content .= '<h2>Available objects</h2>'; |
126 | $content .= '<h2>'._L('Available objects').'</h2>'; |
127 | } |
127 | } |
128 | $content .= '%%CRUD%%'; |
128 | $content .= '%%CRUD%%'; |
129 | } |
129 | } |
130 | } else { |
130 | } else { |
131 | $title = $this->getTitle(); |
131 | $title = $this->getTitle(); |
132 | 132 | ||
133 | $content = '<h2>Technical information</h2>'; |
133 | $content = '<h2>'._L('Technical information').'</h2>'; |
134 | 134 | ||
135 | $content .= '<p>IPv4/CIDR: <code>' . ipv4_normalize($this->bare) . '/' . $this->cidr . '</code><br>'; |
135 | $content .= '<p>'._L('IPv4/CIDR').': <code>' . ipv4_normalize($this->bare) . '/' . $this->cidr . '</code><br>'; |
136 | if ($this->cidr < 32) { |
136 | if ($this->cidr < 32) { |
137 | $content .= 'First address: <code>' . ipv4_cidr_min_ip($this->bare . '/' . $this->cidr) . '</code><br>'; |
137 | $content .= _L('First address').': <code>' . ipv4_cidr_min_ip($this->bare . '/' . $this->cidr) . '</code><br>'; |
138 | $content .= 'Last address: <code>' . ipv4_cidr_max_ip($this->bare . '/' . $this->cidr) . '</code></p>'; |
138 | $content .= _L('Last address').': <code>' . ipv4_cidr_max_ip($this->bare . '/' . $this->cidr) . '</code></p>'; |
139 | } else { |
139 | } else { |
140 | $content .= 'Single host address</p>'; |
140 | $content .= _L('Single host address').'</p>'; |
141 | } |
141 | } |
142 | 142 | ||
143 | $content .= '<h2>Description</h2>%%DESC%%'; |
143 | $content .= '<h2>'._L('Description').'</h2>%%DESC%%'; |
144 | 144 | ||
145 | if (!$this->isLeafNode()) { |
145 | if (!$this->isLeafNode()) { |
146 | if ($this->userHasWriteRights()) { |
146 | if ($this->userHasWriteRights()) { |
147 | $content .= '<h2>Create or change subsequent objects</h2>'; |
147 | $content .= '<h2>'._L('Create or change subsequent objects').'</h2>'; |
148 | } else { |
148 | } else { |
149 | $content .= '<h2>Subsequent objects</h2>'; |
149 | $content .= '<h2>'._L('Subsequent objects').'</h2>'; |
150 | } |
150 | } |
151 | $content .= '%%CRUD%%'; |
151 | $content .= '%%CRUD%%'; |
152 | } |
152 | } |
153 | } |
153 | } |
154 | } |
154 | } |