Subversion Repositories oidplus

Rev

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($ipv6)) {
28
                if (!empty($ipv6)) {
29
                        if (strpos($ipv6, '/') === false) $ipv6 .= '/128';
29
                        if (strpos($ipv6, '/') === false) $ipv6 .= '/128';
30
                        list($bare, $cidr) = explode('/', $ipv6);
30
                        list($bare, $cidr) = explode('/', $ipv6);
31
                        $this->bare = $bare;
31
                        $this->bare = $bare;
32
                        $this->cidr = $cidr;
32
                        $this->cidr = $cidr;
33
                        if (!ipv6_valid($bare)) throw new OIDplusException("Invalid IPv6");
33
                        if (!ipv6_valid($bare)) throw new OIDplusException(_L('Invalid IPv6'));
34
                        if (!is_numeric($cidr)) throw new OIDplusException("Invalid IPv6");
34
                        if (!is_numeric($cidr)) throw new OIDplusException(_L('Invalid IPv6'));
35
                        if ($cidr < 0) throw new OIDplusException("Invalid IPv6");
35
                        if ($cidr < 0) throw new OIDplusException(_L('Invalid IPv6'));
36
                        if ($cidr > 128) throw new OIDplusException("Invalid IPv6");
36
                        if ($cidr > 128) throw new OIDplusException(_L('Invalid IPv6'));
37
                        $this->bare = ipv6_normalize($this->bare);
37
                        $this->bare = ipv6_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 !== 'ipv6') return false;
43
                if ($namespace !== 'ipv6') return false;
44
                return new self($ipv6);
44
                return new self($ipv6);
45
        }
45
        }
46
 
46
 
47
        public static function objectTypeTitle() {
47
        public static function objectTypeTitle() {
48
                return "IPv6 Network Blocks";
48
                return _L('IPv6 Network Blocks');
49
        }
49
        }
50
 
50
 
51
        public static function objectTypeTitleShort() {
51
        public static function objectTypeTitleShort() {
52
                return "IPv6";
52
                return _L('IPv6');
53
        }
53
        }
54
 
54
 
55
        public static function ns() {
55
        public static function ns() {
56
                return 'ipv6';
56
                return 'ipv6';
57
        }
57
        }
Line 71... Line 71...
71
        public function addString($str) {
71
        public function addString($str) {
72
                if (strpos($str, '/') === false) $str .= "/128";
72
                if (strpos($str, '/') === false) $str .= "/128";
73
 
73
 
74
                if (!$this->isRoot()) {
74
                if (!$this->isRoot()) {
75
                        if (!ipv6_in_cidr($this->bare.'/'.$this->cidr, $str)) {
75
                        if (!ipv6_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($ipv6, $cidr) = explode('/', $str);
80
                list($ipv6, $cidr) = explode('/', $str);
81
                if ($cidr < 0) throw new OIDplusException("Invalid IPv6 address '$str'");
81
                if ($cidr < 0) throw new OIDplusException(_L('Invalid IPv6 address %1',$str));
82
                if ($cidr > 128) throw new OIDplusException("Invalid IPv6 address '$str'");
82
                if ($cidr > 128) throw new OIDplusException(_L('Invalid IPv6 address %1',$str));
83
                $ipv6_normalized = ipv6_normalize($ipv6);
83
                $ipv6_normalized = ipv6_normalize($ipv6);
84
                if (!$ipv6_normalized) throw new OIDplusException("Invalid IPv6 address '$str'");
84
                if (!$ipv6_normalized) throw new OIDplusException(_L('Invalid IPv6 address %1',$str));
85
                return 'ipv6:'.$ipv6_normalized.'/'.$cidr; // overwrite; no hierarchical tree
85
                return 'ipv6:'.$ipv6_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->ipv6;
89
                return $this->ipv6;
Line 112... Line 112...
112
                if ($this->isRoot()) {
112
                if ($this->isRoot()) {
113
                        $title = OIDplusIpv6::objectTypeTitle();
113
                        $title = OIDplusIpv6::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>IPv6/CIDR: <code>' . ipv6_normalize($this->bare) . '/' . $this->cidr . '</code><br>';
135
                        $content .= '<p>'._L('IPv6/CIDR').': <code>' . ipv6_normalize($this->bare) . '/' . $this->cidr . '</code><br>';
136
                        if ($this->cidr < 128) {
136
                        if ($this->cidr < 128) {
137
                                $content .= 'First address: <code>' . ipv6_cidr_min_ip($this->bare . '/' . $this->cidr) . '</code><br>';
137
                                $content .= _L('First address').': <code>' . ipv6_cidr_min_ip($this->bare . '/' . $this->cidr) . '</code><br>';
138
                                $content .= 'Last address: <code>' . ipv6_cidr_max_ip($this->bare . '/' . $this->cidr) . '</code></p>';
138
                                $content .= _L('Last address').': <code>' . ipv6_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
        }