Max2Play Home › Forums › Max2Play Development (Ideas, Wishes) › [SOLVED][BUG] Service.php match Config File Parameter
- This topic has 1 reply, 2 voices, and was last updated 7 years, 10 months ago by flysurfer Moderator.
-
21. Dezember 2016 at 11:55 #25103
Hello!
I’ve found a bug in the function getConfigFileParameter and saveConfigFileParameter in PHP File Service.phpIf you have two or more parameters in the configfile which are named very similar,
(for example: ABCDEF1 and ABCDEF10)
both of them where found in the function getConfigFileParameter.
If you save the Parameter ABCDEF1 the parameter ABCDEF10 will be overwritten with the parameter name ABCDEF1 and the given value for this parameter.
Afterwards you will find the the parameter ABCDEF1 twice in the config file.The function deleteConfigFileParameter will delete ABCDEF10 too!!!
Maybe you can add the spearator in the matching pattern …
for example in function getConfigFileParameter:
$output = trim(shell_exec(‚grep -aP „^[ \t]*‘.$parameter.'[ \t]*‘.$separator.'“ ‚.$configfile.‘ | sed -n -e „s/^[ \t]*[A-Za-z_0-9\.]*‘.$separator.’//p“‚));Please make sure that this will be corrected in the next release!
br
Sample Code (this works for me):
/** * Function to save specific Parameter to specified Configfile * @param string $configfile * @param string $parameter * @param string $value */ public function saveConfigFileParameter($configfile = '', $parameter = '', $value = '', $separator = '='){ if(file_exists($configfile)){ $old_parameter = trim($this->getConfigFileParameter($configfile, $parameter)); if($old_parameter == $value){ //No changes return false; } //Check for empty entry //$param_exists = shell_exec('grep -aP "^[ \t]*'.$parameter.'" '.$configfile.' | wc -l'); $param_exists = shell_exec('grep -aP "^[ \t]*'.$parameter.'[ \t]*'.$seperator.'" '.$configfile.' | wc -l'); if($old_parameter != '' || $param_exists > 0){ //$this->writeDynamicScript(array('sed -i "s/^[ \t]*'.$parameter.'.*$/'.$parameter.$separator.str_replace(array('/'),array('\/'),$value).'/g" '.$configfile)); $this->writeDynamicScript(array('sed -i "s/^[ \t]*'.$parameter.'[ \t]*'.$separator.'.*$/'.$parameter.$separator.str_replace(array('/'),array('\/'),$value).'/g" '.$configfile)); $this->view->message[] = _("Update Configfile - existing Entry changed"); }else{ //check for Newline in Last Line in config file if(strpos(shell_exec('xxd -p '.$configfile.' | tail -c 3'), '0a') === FALSE){ //Newline missing -> add one $parameter = "\n".$parameter; } $this->writeDynamicScript(array('echo "'.$parameter.$separator.$value.'" >> '.$configfile)); $this->view->message[] = _("Update Configfile - new Entry created"); } } else{ $this->writeDynamicScript(array('echo "'.$parameter.$separator.$value.'" > '.$configfile)); $this->view->message[] = _("Update Configfile - new Configfile created"); } return true; } /** * Function to delete specific Parameter from specified Configfile * @param string $configfile * @param string $parameter */ public function deleteConfigFileParameter($configfile = '', $parameter = '', $separator = '\='){ if(!file_exists($configfile)) return false; //$param_exists = shell_exec('grep -aP "^[ \t]*'.$parameter.'" '.$configfile.' | wc -l'); $param_exists = shell_exec('grep -aP "^[ \t]*'.$parameter.'[ \t]*'.$seperator.'" '.$configfile.' | wc -l'); if($param_exists > 0){ //$this->writeDynamicScript(array('sed -i "s/^[ \t]*'.$parameter.'.*$//g" '.$configfile)); $this->writeDynamicScript(array('sed -i "s/^[ \t]*'.$parameter.'[ \t]*'.$separator.'.*$//g" '.$configfile)); } return true; } /** * Function to get specific Parameter from specified Configfile * @return boolean */ public function getConfigFileParameter($configfile = '', $parameter = '', $separator = '\='){ if(!file_exists($configfile)) return false; //$output = trim(shell_exec('grep -aP "^[ \t]*'.$parameter.'" '.$configfile.' | sed -n -e "s/^[ \t]*[A-Za-z_0-9\.]*'.$separator.'//p"')); $output = trim(shell_exec('grep -aP "^[ \t]*'.$parameter.'[ \t]*'.$separator.'" '.$configfile.' | sed -n -e "s/^[ \t]*[A-Za-z_0-9\.]*'.$separator.'//p"')); return $output; }
- This topic was modified 7 years, 11 months ago by preslmayer.
- This topic was modified 7 years, 10 months ago by Christoph.
-
You must be logged in to reply to this topic.