diff --git a/freifunk-versions.php b/freifunk-versions.php
index b3190c0..25edc36 100644
--- a/freifunk-versions.php
+++ b/freifunk-versions.php
@@ -1,266 +1,252 @@
URL
+function firmware_get_versions( $base_url, $domain, $branch ) {
+ $release = firmware_get_release( $base_url, $domain, $branch );
+ $factory_regex = "/^(?:.*$release-)(.*)\.(?:bin|img|img\.gz)$/";
+ $upgrade_regex = "/^(?:.*$release-)(.*)(?:-sysupgrade\..*)$/";
+ $cache_key = 'ff_firmware_versions_' . $domain . '_' . $branch;
+ if ( WP_DEBUG || ( false === ( $versions = get_transient( $cache_key ) ) ) ) {
+ $versions = [];
+ $url = "$base_url/$domain/$branch/images/images.list";
+ $http_response = wp_remote_get( $url );
+ $input = wp_remote_retrieve_body( $http_response );
+
+ foreach ( explode( "\n", $input ) as $line ) {
+ $ret = sscanf( $line, '%s %s', $folder, $filename );
+ if ( $ret !== 2 ) {
+ continue;
+ }
+
+ $url = "$base_url/$domain/$branch/images/$folder/$filename";
+ if ( $folder === 'sysupgrade' ) {
+ $result = firmware_parse_version( $filename, $upgrade_regex );
+ if ( $result !== NULL ) {
+ $versions[$result[0]][$result[1]]['upgrade'] = $url;
+ }
+ } else {
+ $result = firmware_parse_version( $filename, $factory_regex );
+ if ( $result !== NULL ) {
+ $versions[$result[0]][$result[1]]['factory'] = $url;
+ }
+ }
+ }
+
+ $cachetime = FIRMWARE_CACHETIME * MINUTE_IN_SECONDS;
+ set_transient( $cache_key, $versions, $cachetime );
+ }
+ return $versions;
}
-if ( ! shortcode_exists( 'ff_hh_latestversion' ) ) {
- add_shortcode( 'ff_hh_latestversion', 'ff_hh_shortcode_latestversion' );
+function firmware_parse_version( $filename, $regex ) {
+ if ( preg_match( $regex, $filename, $matches ) ) {
+ $hw = $matches[1];
+ $hw_ver = '1';
+ if ( preg_match( '/^(.*?)-?v(\d+)$/', $hw, $matches ) ) {
+ $hw = $matches[1];
+ $hw_ver = $matches[2];
+ }
+ return [$hw, $hw_ver];
+ } else {
+ return NULL;
+ }
}
+
// Example:
-// [ff_hh_latestversion]
-// [ff_hh_latestversion domain="ffhh-sued" branch="experimental"]
-function ff_hh_shortcode_latestversion( $atts, $content, $name ) {
- $domain = 'ffhh';
- $branch = 'stable';
- if ( is_array( $atts ) ) {
- if ( array_key_exists( 'domain', $atts ) && ! empty( $atts['domain'] ) ) {
- $domain = $atts['domain'];
- }
- if ( array_key_exists( 'branch', $atts ) && ! empty( $atts['branch'] ) ) {
- $branch = $atts['branch'];
- }
- }
-
- $branch_url = FF_HH_UPDATES_URL . $domain . '/' . $branch;
- if ( $domain === 'multi' ) { $branch_url = $branch_url . '/images'; }
- $sw_ver = ff_hh_getlatest( $branch_url, $domain, $branch );
- $outstr = "$sw_ver";
- return $outstr;
+// [ff_firmware_release]
+// [ff_firmware_release domain="ffhh" branch="experimental"]
+function firmware_release( $atts, $content, $name ) {
+ $domain = 'multi';
+ $branch = 'stable';
+ if ( is_array( $atts ) ) {
+ if ( array_key_exists( 'domain', $atts ) && ! empty( $atts['domain'] ) ) {
+ $domain = $atts['domain'];
+ }
+ if ( array_key_exists( 'branch', $atts ) && ! empty( $atts['branch'] ) ) {
+ $branch = $atts['branch'];
+ }
+ }
+ $sw_ver = firmware_get_release( FIRMWARE_BASE_URL, $domain, $branch );
+ $outstr = "$sw_ver";
+ return $outstr;
}
-if ( ! shortcode_exists( 'ff_hh_versions' ) ) {
- add_shortcode( 'ff_hh_versions', 'ff_hh_shortcode_versions' );
-}
// Example:
-// [ff_hh_versions]
-// [ff_hh_versions domain="ffhh-sued" branch="experimental" grep="ubiquiti"]
-function ff_hh_shortcode_versions( $atts, $content, $name ) {
- $domain = 'ffhh';
- $branch = 'stable';
- $grep = false;
- $filter = false;
- if ( is_array( $atts ) ) {
- if ( array_key_exists( 'domain', $atts ) && ! empty( $atts['domain'] ) ) {
- $domain = $atts['domain'];
- }
- if ( array_key_exists( 'branch', $atts ) && ! empty( $atts['branch'] ) ) {
- $branch = $atts['branch'];
- }
- if ( array_key_exists( 'grep', $atts ) && ! empty( $atts['grep'] ) ) {
- $grep = $atts['grep'];
- }
- if ( array_key_exists( 'filter', $atts ) && ! empty( $atts['filter'] ) ) {
- $filter = explode ( ',', $atts['filter'] );
- }
- }
+// [ff_firmware_versions]
+// [ff_firmware_versions prefix="ubiquiti,ubnt" filter="ac-pro"]
+function firmware_versions( $atts, $content, $name ) {
+ $domain = 'multi';
+ $branch = 'stable';
+ $prefix = false;
+ $filter = false;
+ if ( is_array( $atts ) ) {
+ if ( array_key_exists( 'domain', $atts ) && ! empty( $atts['domain'] ) ) {
+ $domain = $atts['domain'];
+ }
+ if ( array_key_exists( 'branch', $atts ) && ! empty( $atts['branch'] ) ) {
+ $branch = $atts['branch'];
+ }
+ if ( array_key_exists( 'prefix', $atts ) && ! empty( $atts['prefix'] ) ) {
+ $prefix = explode ( ',', $atts['prefix'] );
+ }
+ if ( array_key_exists( 'filter', $atts ) && ! empty( $atts['filter'] ) ) {
+ $filter = explode ( ',', $atts['filter'] );
+ }
+ }
- $branch_url = FF_HH_UPDATES_URL . $domain . '/' . $branch;
- if ( $domain === 'multi' ) { $branch_url = $branch_url . '/images'; }
- $manifest = ff_hh_getmanifest( $branch_url, $domain, $branch );
+ $versions = firmware_get_versions( FIRMWARE_BASE_URL, $domain, $branch );
+ if ( $prefix ) {
+ $filtered = [];
+ foreach ( $versions as $hw => $hw_versions ) {
+ foreach ( $prefix as $pfx ) {
+ if ( strpos ( $hw, $pfx ) === 0 ) {
+ $hw = substr( $hw, strlen($pfx) );
+ $hw = trim( $hw, '-' );
+ $filtered[$hw] = $hw_versions;
+ }
+ }
+ }
+ $versions = $filtered;
+ }
+ if ( $filter ) {
+ $filtered = [];
+ foreach ( $versions as $hw => $hw_versions ) {
+ foreach ( $filter as $flt ) {
+ if ( strpos ( $hw, $flt ) === FALSE ) {
+ $filtered[$hw] = $hw_versions;
+ }
+ }
+ }
+ $versions = $filtered;
+ }
- $outstr = "
";
- $outstr .= '
Modell | Erstinstallation | Aktualisierung |
';
+ $outstr = "\n";
+ $outstr .= "\n
\nModell | Erstinstallation | Aktualisierung |
";
- ksort($manifest);
- foreach ( $manifest as $hw => $versions ) {
- // select some models
- if ( $grep && ( false === strpos( $hw, $grep ) ) ) {
- continue;
- }
- // filter others
- if ( $filter ) {
- $filtered = false;
- foreach ( $filter as $flt ) {
- if ( strpos ( $hw, $flt ) !== false ) {
- $filtered = true;
- break;
- }
- }
- if ( $filtered ) {
- continue;
- }
- }
+ ksort($versions);
+ foreach ( $versions as $hw => $hw_versions ) {
+ $hw = firmware_beautify_hw_name( $hw, $prefix );
+ $outstr .= sprintf( "\n%s | ", $hw );
- $hw = ff_hh_beautify_hw_name( $hw, $grep );
- $outstr .= sprintf( "\n
%s | ", $hw );
+ // factory images
+ $factory_links = [];
+ foreach ( $hw_versions as $hw_ver => $urls ) {
+ if ( ! array_key_exists( 'factory', $urls ) ) {
+ continue;
+ }
+ $factory_url = $urls['factory'];
+ $factory_links[] = "$hw_ver.x";
+ }
+ if ( count($factory_links) > 0 ) {
+ $outstr .= 'Version ' . join( ', ', $factory_links ) . ' | ';
+ } else {
+ $outstr .= ' | ';
+ }
- // factory versions
- $hw_ver_links = array();
- foreach ( $versions as $hw_ver => $filename ) {
- if ( strpos( $hw, 'Unifi Ac Pro' ) || strpos( $hw, 'Unifi Ac Lite' ) ) {
- continue;
- }
+ // upgrade images
+ $upgrade_links = [];
+ foreach ( $hw_versions as $hw_ver => $urls ) {
+ if ( ! array_key_exists( 'upgrade', $urls ) ) {
+ continue;
+ }
+ $upgrade_url = $urls['upgrade'];
+ $upgrade_links[] = "$hw_ver.x";
+ }
+ if ( count($upgrade_links) > 0 ) {
+ $outstr .= 'Version ' . join( ', ', $upgrade_links ) . ' | ';
+ } else {
+ $outstr .= ' | ';
+ }
- $filename = str_replace( '-sysupgrade', '', $filename );
- if (strpos($filename,'netgear') !== false) {
- $filename = str_replace( '.bin', '.img', $filename );
- $filename = str_replace( '.tar', '.img', $filename );
- }
- $hw_ver_links[] = sprintf(
- '%s.x',
- $branch_url . '/factory/',
- $filename,
- $hw_ver
- );
- }
- if ( count($hw_ver_links) > 0) {
- $outstr .= 'Hardware Ver. ' . join( ', ', $hw_ver_links ) . ' | ';
- } else {
- $outstr .= 'Benutze das Imagezur Aktualisierung | ';
- }
+ $outstr .= "
";
+ }
- // sysupgrade versions
- $hw_ver_links = array();
- foreach ( $versions as $hw_ver => $filename ) {
- $hw_ver_links[] = sprintf(
- '%s.x',
- $branch_url . '/sysupgrade/',
- $filename,
- $hw_ver
- );
- }
- $outstr .= 'Hardware Ver. ' . join( ', ', $hw_ver_links ) . ' | ';
+ $outstr .= "\n
";
+ $outstr .= "\n
\n";
- $outstr .= '';
- }
-
- $outstr .= '
';
- $outstr .= '
';
- // $outstr .= ''.print_r( $manifest, true ).'
';
- return $outstr;
+ return $outstr;
}
-// some crude rules to add capitalization and whitespace to the
-// hardware model name.
-// set $discard_vendor to strip the vendor name
-// (used for single-vendor lists, e.g. $discard_vendor = 'tp-link' )
-function ff_hh_beautify_hw_name( $hw, $discard_vendor = '' ) {
- if ( ! strncmp( $hw, 'tp-link', 7 ) ) {
- if ( $discard_vendor ) $hw = str_replace( $discard_vendor, '', $hw );
- $hw = strtoupper( $hw );
- $hw = str_replace( '-', ' ', $hw );
- $hw = str_replace( ' TL ', ' TL-', $hw );
- } elseif ( ! strncmp( $hw, 'ubiquiti', 8 ) ) {
- if ( $discard_vendor ) $hw = str_replace( $discard_vendor, '', $hw );
- $hw = str_replace( 'bullet-m', 'bullet-m', $hw );
- $hw = str_replace( '-', ' ', $hw );
- $hw = ucwords( $hw );
- } elseif ( ! strncmp( $hw, 'ubnt', 4 ) ) {
- if ( $discard_vendor ) $hw = str_replace( $discard_vendor, '', $hw );
- $hw = str_replace( 'erx', 'ER-X', $hw );
- $hw = str_replace( 'sfp', 'SFP', $hw );
- $hw = trim( $hw, ' -' );
- $hw = ucwords( $hw );
- } elseif ( ! strncmp( $hw, 'd-link', 6 ) ) {
- if ( $discard_vendor ) $hw = str_replace( $discard_vendor, '', $hw );
- $hw = strtoupper( $hw );
- $hw = str_replace( '-', ' ', $hw );
- $hw = str_replace( ' DIR ', ' DIR-', $hw );
- } elseif ( ! strncmp( $hw, 'linksys', 7 ) ) {
- if ( $discard_vendor ) $hw = str_replace( $discard_vendor, '', $hw );
- $hw = strtoupper( $hw );
- $hw = str_replace( '-', ' ', $hw );
- $hw = str_replace( ' WRT', ' WRT-', $hw );
- } elseif ( ! strncmp( $hw, 'buffalo', 7 ) ) {
- if ( $discard_vendor ) $hw = str_replace( $discard_vendor, '', $hw );
- $hw = strtoupper( $hw );
- $hw = str_replace( 'HP-AG300H-WZR-600DHP', 'HP-AG300H & WZR-600DHP', $hw );
- $hw = str_replace( '-WZR', 'WZR', $hw );
- } elseif ( ! strncmp( $hw, 'netgear', 7 ) ) {
- if ( $discard_vendor ) $hw = str_replace( $discard_vendor, '', $hw );
- $hw = strtoupper( $hw );
- $hw = str_replace( '-', '', $hw );
- } elseif ( ! strncmp( $hw, 'allnet', 6 ) ) {
- if ( $discard_vendor ) $hw = str_replace( $discard_vendor, '', $hw );
- $hw = strtoupper( $hw );
- $hw = str_replace( '-', '', $hw );
- } elseif ( ! strncmp( $hw, 'gl-', 3 ) ) {
- if ( $discard_vendor ) $hw = str_replace( $discard_vendor, '', $hw );
- $hw = strtoupper( $hw );
- $hw = str_replace( '-', '', $hw );
- } elseif ( ! strncmp( $hw, 'onion-omega', 11 ) ) {
- if ( $discard_vendor ) $hw = str_replace( $discard_vendor, '', $hw );
- } elseif ( ! strncmp( $hw, 'alfa', 4 ) ) {
- if ( $discard_vendor ) $hw = str_replace( $discard_vendor, '', $hw );
- $hw = strtoupper( $hw );
- $hw = str_replace( '-', '', $hw );
- } elseif ( ! strncmp( $hw, 'wd', 2 ) ) {
- if ( $discard_vendor ) $hw = str_replace( $discard_vendor, '', $hw );
- $hw = strtoupper( $hw );
- $hw = str_replace( '-', '', $hw );
- } elseif ( ! strncmp( $hw, '8devices', 8 ) ) {
- if ( $discard_vendor ) $hw = str_replace( $discard_vendor, '', $hw );
- $hw = strtoupper( $hw );
- $hw = str_replace( 'CARAMBOLA2-BOARD', 'Carambola 2', $hw );
- $hw = str_replace( '-', '', $hw );
- } elseif ( ! strncmp( $hw, 'meraki', 6 ) ) {
- if ( $discard_vendor ) $hw = str_replace( $discard_vendor, '', $hw );
- $hw = strtoupper( $hw );
- $hw = str_replace( 'meraki', '', $hw );
- $hw = str_replace( '-', '', $hw );
- } elseif ( ! strncmp( $hw, 'openmesh', 8 ) ) {
- if ( $discard_vendor ) $hw = str_replace( $discard_vendor, '', $hw );
- $hw = strtoupper( $hw );
- $hw = str_replace( 'openmesh', '', $hw );
- $hw = str_replace( '-', '', $hw );
- }
- return $hw;
+// Add capitalization and whitespace to the hardware model name.
+function firmware_beautify_hw_name( $hw, $prefix ) {
+ $vendor = '';
+ if ( $prefix ) {
+ $vendor = $prefix[0];
+ }
+
+ if ( $vendor === '8devices' ) {
+ $hw = str_replace( 'carambola2-board', 'carambola 2', $hw );
+ $hw = ucwords( $hw );
+ } elseif ( $vendor === 'buffalo' ) {
+ $hw = str_replace( 'hp-ag300h-wzr-600dhp', 'hp-ag300h & wzr-600dhp', $hw );
+ $hw = strtoupper( $hw );
+ } elseif ( $vendor === 'd-link' ) {
+ $hw = str_replace( '-', ' ', $hw );
+ $hw = str_replace( 'dir ', 'dir-', $hw );
+ $hw = strtoupper( $hw );
+ } elseif ( $vendor === 'onion' ) {
+ $hw = ucwords( $hw );
+ } elseif ( $vendor === 'tp-link' ) {
+ $hw = str_replace( 'n-nd', 'n/nd', $hw );
+ $hw = str_replace( '-', ' ', $hw );
+ $hw = str_replace( 'tl ', 'tl-', $hw );
+ $hw = strtoupper( $hw );
+ $hw = str_replace( 'ARCHER', 'Archer', $hw );
+ } elseif ( $vendor === 'ubiquiti' ) {
+ $hw = str_replace( '-', ' ', $hw );
+ $hw = ucwords( $hw );
+ $hw = str_replace( 'Ac', 'AC', $hw );
+ $hw = str_replace( 'Ap', 'AP', $hw );
+ $hw = str_replace( 'Erx', 'ER-X', $hw );
+ $hw = str_replace( 'Sfp', 'SFP', $hw );
+ $hw = str_replace( 'Xw', 'XW', $hw );
+ } else {
+ $hw = strtoupper( $hw );
+ }
+
+ return $hw;
+}
+
+if ( ! shortcode_exists( 'ff_firmware_release' ) ) {
+ add_shortcode( 'ff_firmware_release', 'firmware_release' );
+}
+
+if ( ! shortcode_exists( 'ff_firmware_versions' ) ) {
+ add_shortcode( 'ff_firmware_versions', 'firmware_versions' );
}