Commit b0783ed1 authored by thiaramus's avatar thiaramus
Browse files

Added a fidoconf class to parse fidoconf area settings on the fly. Based on...

Added a fidoconf class to parse fidoconf area settings on the fly. Based on husky2ini.php with very little changes.
parent 1e5b4784
<?php
/*
* webJAM - A modern JAM MessageBase Editor
* Copyright (C) 2017 Philipp Giebel (stimpy@kuehlbox.wtf)
*
* This program is free software: you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program.
* If not, see (http://www.gnu.org/licenses/).
*
* * filename: fidoconf.class.php
* * description: A fidoconf parser. Based entirely on husky2ini.php by Philipp Giebel (stimpy@kuehlbox.wtf)
* * author: Roman Litvinenko (temp@thiaramus.com)
*
*/
class fidoconf
{
private $fidoconf;
public function __construct($fidoconf) {
if (file_exists($fidoconf) && is_file($fidoconf) && is_readable($fidoconf)) {
$this->fidoconf = $fidoconf;
} else {
$this->fidoconf = null;
}
}
public function parseAreas() {
$file = $this->fidoconf;
$areas = [];
if (!file_exists($file) || !is_file($file) || !is_readable($file)) {
return $areas;
}
$fp = fopen($file, 'r');
$echos = array();
if ($fp) {
while (($line = fgets($fp)) !== false) {
if (preg_match("/^\s*([\w]+)\s+([^\s]+)\s+([^\s]+)\s+(.*)/i", $line, $matches)) {
preg_match_all("/(-\S+)\s([^-\s]+)\s?/", $matches[4], $omatches);
$opts = array();
for ($i = 0; $i < count($omatches[1]); $i++) {
$opts[substr($omatches[1][$i], 1)] = $omatches[2][$i];
}
if (array_key_exists('b', $opts)) {
if (strtolower($opts['b']) == 'jam') {
if (array_key_exists('d', $opts)) {
if ((substr($opts['d'], 0, 1) == '"') OR (substr($opts['d'], 0, 1) == '"')) $opts['d'] = substr($opts['d'], 1);
if ((substr($opts['d'], -1) == '"') OR (substr($opts['d'], -1) == '"')) $opts['d'] = substr($opts['d'], 0, -1);
}
$group = 'internal';
if (array_key_exists('g', $opts)) {
$group = $opts['g'];
} elseif (strtolower($matches[1]) == 'netmailarea') {
$group = 'netmail';
}
if (array_key_exists('d', $opts)) {
$description = $opts['d'];
} else {
$description = '(' . $group . ') ';
}
$echos[strtolower($matches[2])] = array(
'filename' => $matches[3],
'group' => $group,
'description' => $description
);
}
}
}
}
asort($echos);
if (array_key_exists('netmail', $echos)) {
$areas ['netmail'] = [
'filename' => $echos['netmail']['filename'],
'group' => $echos['netmail']['group'],
'description' => $echos['netmail']['description']
];
}
foreach ($echos as $echo => $conf) {
if ($echo != 'netmail') {
$areas [$echo] = [
'filename' => $conf['filename'],
'group' => $conf['group'],
'description' => $conf['description']
];
}
}
fclose($fp);
}
return $areas;
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment