<?php

$username = $_POST["username"];
$password = $_POST["password"];
$mqtt_username = $_POST["mqtt_username"];
$mqtt_password = $_POST["mqtt_password"];
$web_username = '';
$web_password = '';

// load config file and read in data
$config_file = fopen("/etc/nyquist/SIP.config", "r");

if(!$config_file){
   
} else { 
   // go through the config file one line at a time
  while(!feof($config_file)) {

      $line_text = fgets($config_file);

      if(strpos($line_text, 'WEB_USERNAME =') !== FALSE){
          $web_username = str_replace("WEB_USERNAME = ","",$line_text);
          $web_username = trim($web_username);
      }
      if(strpos($line_text, 'WEB_PASSWORD =') !== FALSE){
          $web_password = str_replace("WEB_PASSWORD = ","",$line_text);
          $web_password = trim($web_password);
      }
  }
  fclose($config_file);
	
  if($username==$web_username && $password==$web_password){

      $script_path = 'sudo /usr/local/bin/update_mqtt_password "' . $mqtt_password . '"';
      $run_script = shell_exec($script_path);		
  }
}
?>