| 
									
										
										
										
											2024-08-28 09:59:13 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Config { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-01 16:23:40 +00:00
										 |  |  |     // edit the config file
 | 
					
						
							| 
									
										
										
										
											2024-11-01 16:27:57 +00:00
										 |  |  |     public function editConfigFile($updatedConfig, $config_file) { | 
					
						
							| 
									
										
										
										
											2024-11-01 16:23:40 +00:00
										 |  |  |         // first we get a fresh config file contents as text
 | 
					
						
							|  |  |  |         $config_contents = file_get_contents($config_file); | 
					
						
							|  |  |  |         if (!$config_contents) { | 
					
						
							|  |  |  |             return "Failed to read the config file \"$config_file\".";
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // loop through the variables and updated them
 | 
					
						
							|  |  |  |         foreach ($updatedConfig as $key => $newValue) { | 
					
						
							|  |  |  |             // we look for 'option' => value
 | 
					
						
							|  |  |  |             // option is always in single quotes
 | 
					
						
							|  |  |  |             // value is without quotes, because it could be true/false
 | 
					
						
							| 
									
										
										
										
											2024-11-01 16:58:53 +00:00
										 |  |  |             $pattern = "/(['\"]{$key}['\"]\s*=>\s*)([^,]+),/"; | 
					
						
							| 
									
										
										
										
											2024-11-01 16:23:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-02 15:33:18 +00:00
										 |  |  |             // prepare the value, make booleans w/out single quotes
 | 
					
						
							|  |  |  |             if ($newValue === 'true') { | 
					
						
							| 
									
										
										
										
											2024-11-01 18:01:43 +00:00
										 |  |  |                 $replacementValue = 'true'; | 
					
						
							| 
									
										
										
										
											2024-11-02 15:33:18 +00:00
										 |  |  |             } elseif ($newValue === 'false') { | 
					
						
							| 
									
										
										
										
											2024-11-01 18:01:43 +00:00
										 |  |  |                 $replacementValue = 'false'; | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 $replacementValue = var_export($newValue, true); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             // value replacing
 | 
					
						
							| 
									
										
										
										
											2024-11-01 16:23:40 +00:00
										 |  |  |             $config_contents = preg_replace($pattern, "$1{$replacementValue},", $config_contents); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // write the new config file
 | 
					
						
							|  |  |  |         if (!file_put_contents($config_file, $config_contents)) { | 
					
						
							|  |  |  |             return "Failed to write the config file \"$config_file\".";
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-28 09:59:13 +00:00
										 |  |  |     // loading the config.js
 | 
					
						
							| 
									
										
										
										
											2024-09-04 09:53:02 +00:00
										 |  |  |     public function getPlatformConfigjs($jitsiUrl, $raw = false) { | 
					
						
							| 
									
										
										
										
											2024-08-28 09:59:13 +00:00
										 |  |  |         // constructing the URL
 | 
					
						
							| 
									
										
										
										
											2024-09-04 09:53:02 +00:00
										 |  |  |         $configjsFile = $jitsiUrl . '/config.js'; | 
					
						
							| 
									
										
										
										
											2024-08-28 09:59:13 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // default content, if we can't get the file contents
 | 
					
						
							|  |  |  |         $platformConfigjs = "The file $configjsFile can't be loaded."; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // ssl options
 | 
					
						
							|  |  |  |         $contextOptions = [ | 
					
						
							|  |  |  |             'ssl' => [ | 
					
						
							|  |  |  |                 'verify_peer'		=> true, | 
					
						
							|  |  |  |                 'verify_peer_name'	=> true, | 
					
						
							|  |  |  |             ], | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  |         $context = stream_context_create($contextOptions); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // get the file
 | 
					
						
							|  |  |  |         $fileContent = @file_get_contents($configjsFile, false, $context); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if ($fileContent !== false) { | 
					
						
							| 
									
										
										
										
											2024-08-31 16:50:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             // when we need only uncommented values
 | 
					
						
							|  |  |  |             if ($raw === false) { | 
					
						
							|  |  |  |                 // remove block comments
 | 
					
						
							|  |  |  |                 $platformConfigjs = preg_replace('!/\*.*?\*/!s', '', $fileContent); | 
					
						
							|  |  |  |                 // remove single-line comments
 | 
					
						
							|  |  |  |                 $platformConfigjs = preg_replace('/\/\/[^\n]*/', '', $platformConfigjs); | 
					
						
							|  |  |  |                 // remove empty lines
 | 
					
						
							|  |  |  |                 $platformConfigjs = preg_replace('/^\s*[\r\n]/m', '', $platformConfigjs); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             // when we need the full file as it is
 | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 $platformConfigjs = $fileContent; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2024-08-28 09:59:13 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $platformConfigjs; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // loading the interface_config.js
 | 
					
						
							| 
									
										
										
										
											2024-09-04 09:53:02 +00:00
										 |  |  |     public function getPlatformInterfaceConfigjs($jitsiUrl, $raw = false) { | 
					
						
							| 
									
										
										
										
											2024-08-28 09:59:13 +00:00
										 |  |  |         // constructing the URL
 | 
					
						
							| 
									
										
										
										
											2024-09-04 09:53:02 +00:00
										 |  |  |         $interfaceConfigjsFile = $jitsiUrl . '/interface_config.js'; | 
					
						
							| 
									
										
										
										
											2024-08-28 09:59:13 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // default content, if we can't get the file contents
 | 
					
						
							|  |  |  |         $platformInterfaceConfigjs = "The file $interfaceConfigjsFile can't be loaded."; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // ssl options
 | 
					
						
							|  |  |  |         $contextOptions = [ | 
					
						
							|  |  |  |             'ssl' => [ | 
					
						
							|  |  |  |                 'verify_peer'		=> true, | 
					
						
							|  |  |  |                 'verify_peer_name'	=> true, | 
					
						
							|  |  |  |             ], | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  |         $context = stream_context_create($contextOptions); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // get the file
 | 
					
						
							|  |  |  |         $fileContent = @file_get_contents($interfaceConfigjsFile, false, $context); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if ($fileContent !== false) { | 
					
						
							| 
									
										
										
										
											2024-08-31 16:50:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             // when we need only uncommented values
 | 
					
						
							|  |  |  |             if ($raw === false) { | 
					
						
							|  |  |  |                 // remove block comments
 | 
					
						
							|  |  |  |                 $platformInterfaceConfigjs = preg_replace('!/\*.*?\*/!s', '', $fileContent); | 
					
						
							|  |  |  |                 // remove single-line comments
 | 
					
						
							|  |  |  |                 $platformInterfaceConfigjs = preg_replace('/\/\/[^\n]*/', '', $platformInterfaceConfigjs); | 
					
						
							|  |  |  |                 // remove empty lines
 | 
					
						
							|  |  |  |                 $platformInterfaceConfigjs = preg_replace('/^\s*[\r\n]/m', '', $platformInterfaceConfigjs); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             // when we need the full file as it is
 | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 $platformInterfaceConfigjs = $fileContent; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2024-08-28 09:59:13 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $platformInterfaceConfigjs; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ?>
 |