@@ -99,14 +99,43 @@ function option(string $value, string $desc, $attributes = []): string
9999 'default ' => 'OS default version ' ,
100100];
101101
102+
103+ $ platform = $ _SERVER ['HTTP_SEC_CH_UA_PLATFORM ' ] ?? '' ;
104+ $ ua = $ _SERVER ['HTTP_USER_AGENT ' ] ?? '' ;
105+ $ auto_os = null ;
106+ $ auto_osvariant = null ;
107+
108+ if (!empty ($ platform ) || !empty ($ ua )) {
109+ $ platform = strtolower (trim ($ platform , '" ' ));
110+ if ($ platform === 'windows ' || stripos ($ ua , 'Windows ' ) !== false ) {
111+ $ auto_os = 'windows ' ;
112+ } elseif ($ platform === 'macos ' || stripos ($ ua , 'Mac ' ) !== false ) {
113+ $ auto_os = 'osx ' ;
114+ } elseif ($ platform === 'linux ' || stripos ($ ua , 'Linux ' ) !== false ) {
115+ $ auto_os = 'linux ' ;
116+ if (stripos ($ ua , 'Ubuntu ' ) !== false ) {
117+ $ auto_osvariant = 'linux-ubuntu ' ;
118+ } elseif (stripos ($ ua , 'Debian ' ) !== false ) {
119+ $ auto_osvariant = 'linux-debian ' ;
120+ } elseif (stripos ($ ua , 'Fedora ' ) !== false ) {
121+ $ auto_osvariant = 'linux-fedora ' ;
122+ } elseif (stripos ($ ua , 'Red Hat ' ) !== false || stripos ($ ua , 'RedHat ' ) !== false ) {
123+ $ auto_osvariant = 'linux-redhat ' ;
124+ }
125+ }
126+ }
127+
102128$ defaults = [
103- 'os ' => 'linux ' ,
129+ 'os ' => $ auto_os ?? 'linux ' ,
104130 'version ' => 'default ' ,
105131 'usage ' => 'web ' ,
106132];
107133
108134$ options = array_merge ($ defaults , $ _GET );
109- if (!array_key_exists ('osvariant ' , $ options ) || !array_key_exists ($ options ['osvariant ' ], $ os [$ options ['os ' ]]['variants ' ])) {
135+
136+ if ($ auto_osvariant && (!array_key_exists ('osvariant ' , $ options ) || !array_key_exists ($ options ['osvariant ' ], $ os [$ options ['os ' ]]['variants ' ]))) {
137+ $ options ['osvariant ' ] = $ auto_osvariant ;
138+ } elseif (!array_key_exists ('osvariant ' , $ options ) || !array_key_exists ($ options ['osvariant ' ], $ os [$ options ['os ' ]]['variants ' ])) {
110139 $ options ['osvariant ' ] = array_key_first ($ os [$ options ['os ' ]]['variants ' ]);
111140}
112141?>
0 commit comments