Subversion Repositories oidplus

Rev

Rev 1254 | Rev 1261 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1254 Rev 1259
Line 21... Line 21...
21
 
21
 
22
// phpcs:disable PSR1.Files.SideEffects
22
// phpcs:disable PSR1.Files.SideEffects
23
\defined('INSIDE_OIDPLUS') or die;
23
\defined('INSIDE_OIDPLUS') or die;
24
// phpcs:enable PSR1.Files.SideEffects
24
// phpcs:enable PSR1.Files.SideEffects
25
 
25
 
26
class OIDplusObjectTypePluginMac extends OIDplusObjectTypePlugin {
26
class OIDplusObjectTypePluginMac extends OIDplusObjectTypePlugin
-
 
27
        implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_6 /* gridGeneratorLinks */
-
 
28
{
27
 
29
 
28
        /**
30
        /**
29
         * @return string
31
         * @return string
30
         */
32
         */
31
        public static function getObjectTypeClassName(): string {
33
        public static function getObjectTypeClassName(): string {
32
                return OIDplusMac::class;
34
                return OIDplusMac::class;
33
        }
35
        }
34
 
36
 
35
        /**
37
        /**
-
 
38
         * @param string $actionID
-
 
39
         * @param array $params
-
 
40
         * @return array
-
 
41
         * @throws OIDplusException
-
 
42
         */
-
 
43
        public function action(string $actionID, array $params): array {
-
 
44
                if ($actionID == 'generate_aai') {
-
 
45
                        _CheckParamExists($params, 'aai_bits');
-
 
46
                        _CheckParamExists($params, 'aai_multicast');
-
 
47
 
-
 
48
                        if (($params['aai_bits'] != '48') && ($params['aai_bits'] != '64')) {
-
 
49
                                throw new OIDplusException(_L("Invalid bit amount"));
-
 
50
                        }
-
 
51
 
-
 
52
                        $aai = '';
-
 
53
                        for ($i=0; $i<$params['aai_bits']/4; $i++) {
-
 
54
                                try {
-
 
55
                                        $aai .= dechex(random_int(0, 15));
-
 
56
                                } catch (\Exception $e) {
-
 
57
                                        $aai .= dechex(mt_rand(0, 15));
-
 
58
                                }
-
 
59
                        }
-
 
60
 
-
 
61
                        if ($params['aai_multicast'] == 'true') {
-
 
62
                                $aai[1] = '3';
-
 
63
                        } else {
-
 
64
                                $aai[1] = '2';
-
 
65
                        }
-
 
66
 
-
 
67
                        $aai = strtoupper($aai);
-
 
68
                        $aai = rtrim(chunk_split($aai, 2, '-'), '-');
-
 
69
 
-
 
70
                        return array("status" => 0, "aai" => $aai);
-
 
71
                } else {
-
 
72
                        return parent::action($actionID, $params);
-
 
73
                }
-
 
74
        }
-
 
75
 
-
 
76
        /**
-
 
77
         * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_6
-
 
78
         * @param OIDplusObject $objParent
-
 
79
         * @return string
-
 
80
         */
-
 
81
        public function gridGeneratorLinks(OIDplusObject $objParent): string {
-
 
82
                return
-
 
83
                        '<br>'._L('Generate a random AAI:').
-
 
84
                        '<br>- Unicast <a href="javascript:OIDplusObjectTypePluginMac.generateRandomAAI(48, false)">(AAI-48)</a> | <a href="javascript:OIDplusObjectTypePluginMac.generateRandomAAI(64, false)">(AAI-64)</a>'.
-
 
85
                        '<br>- Multicast <a href="javascript:OIDplusObjectTypePluginMac.generateRandomAAI(48, true)">(AAI-48)</a> | <a href="javascript:OIDplusObjectTypePluginMac.generateRandomAAI(64, true)">(AAI-64)</a>'.
-
 
86
                        '<br><a href="https://standards.ieee.org/products-programs/regauth/" target="_blank">('._L('Buy an OUI or CID from IEEE').')</a>';
-
 
87
        }
-
 
88
 
-
 
89
        /**
36
         * @param string $static_node_id
90
         * @param string $static_node_id
37
         * @param bool $throw_exception
91
         * @param bool $throw_exception
38
         * @return string
92
         * @return string
39
         */
93
         */
40
        public static function prefilterQuery(string $static_node_id, bool $throw_exception): string {
94
        public static function prefilterQuery(string $static_node_id, bool $throw_exception): string {