diff --git a/file_list.php b/file_list.php index 3e9d6f7..66ef744 100644 --- a/file_list.php +++ b/file_list.php @@ -26,140 +26,142 @@ */ //includes files - require_once dirname(__DIR__, 2) . "/resources/require.php"; - require_once "resources/check_auth.php"; +require_once dirname(__DIR__, 2) . "/resources/require.php"; +require_once "resources/check_auth.php"; //check permissions - if (permission_exists('edit_view')) { - //access granted - } - else { - echo "access denied"; - exit; - } +if (permission_exists('edit_view')) { + //access granted +} else { + echo "access denied"; + exit; +} + +//add multi-lingual support +$language = new text(); +$text = $language->get(); + +//set the domain and user +$domain_uuid = $_SESSION['domain_uuid'] ?? ''; +$user_uuid = $_SESSION['user_uuid'] ?? ''; + +//ensure database and settings objects are created +global $database; +if (empty($database) || !($database instanceof database)) { + $database = database::new(); +} +if (empty($settings) || !($settings instanceof settings)) { + $settings = new settings(['database' => $database, 'domain_uuid' => $domain_uuid, 'user_uuid' => $user_uuid]); +} //add css and javascript - require_once "header.php"; +require_once "header.php"; //define function recur_dir - function recur_dir($dir) { - clearstatcache(); - $html_dir_list = ''; - $html_file_list = ''; - $dir_handle = opendir($dir); - $dir_array = array(); - if (($dir_handle)) { - $x = 0; - while (false !== ($file = readdir($dir_handle))) { - if ($file != "." AND $file != "..") { - $newpath = $dir.'/'.$file; - $level = explode('/',$newpath); - if ( - substr(strtolower($newpath), -4) == ".svn" || - substr(strtolower($newpath), -4) == ".git" || - substr(strtolower($newpath), -3) == ".db" || - substr(strtolower($newpath), -4) == ".jpg" || - substr(strtolower($newpath), -4) == ".gif" || - substr(strtolower($newpath), -4) == ".png" || - substr(strtolower($newpath), -4) == ".ico" || - substr(strtolower($newpath), -4) == ".ttf" - ) { - //ignore certain files (and folders) - } - else { - $dir_array[] = $newpath; - } - if ($x > 1000) { break; } - $x++; - } - } +function recur_dir($dir) { + clearstatcache(); + $html_dir_list = ''; + $html_file_list = ''; + $dir_handle = opendir($dir); + $dir_array = array(); + if (!($dir_handle)) { + return; + } + $x = 0; + while (false !== ($file = readdir($dir_handle))) { + if ($file === '.' || $file === '..') { + continue; } - - asort($dir_array); - foreach ($dir_array as $newpath){ - $level = explode('/',$newpath); - - if (is_dir($newpath)) { - $dirname = end($level); - $html_dir_list .= "
\n"; - $html_dir_list .= "".$dirname.""; - $html_dir_list .= "
".recur_dir($newpath)."
\n"; - $html_dir_list .= "
\n"; - } - else { - $filename = end($level); - $filesize = round(filesize($newpath)/1024, 2); - $newpath = str_replace ('//', '/', $newpath); - $newpath = str_replace ("\\", "/", $newpath); - $html_file_list .= "
\n"; - $html_file_list .= ""; - $html_file_list .= "".$filename."\n"; - $html_file_list .= "
\n"; - } + $newpath = $dir . '/' . $file; + $level = explode('/', $newpath); + if ( + substr(strtolower($newpath), -4) == ".svn" || + substr(strtolower($newpath), -4) == ".git" || + substr(strtolower($newpath), -3) == ".db" || + substr(strtolower($newpath), -4) == ".jpg" || + substr(strtolower($newpath), -4) == ".gif" || + substr(strtolower($newpath), -4) == ".png" || + substr(strtolower($newpath), -4) == ".ico" || + substr(strtolower($newpath), -4) == ".ttf" + ) { + //ignore certain files (and folders) + continue; } + $dir_array[] = $newpath; + //only allow up to 1000 files + if (++$x > 1000) { break; } + } - closedir($dir_handle); - return $html_dir_list ."\n". $html_file_list; + //finished with directory + closedir($dir_handle); + + //sort directories + asort($dir_array); + + foreach ($dir_array as $new_path) { + $level = explode('/', $new_path); + + if (is_dir($new_path)) { + $dirname = end($level); + $html_dir_list .= "
\n"; + $html_dir_list .= "folder$dirname"; + $html_dir_list .= "
" . recur_dir($new_path) . "
\n"; + $html_dir_list .= "
\n"; + } else { + $filename = end($level); + $filesize = round(filesize($new_path) / 1024, 2); + $new_path = str_replace('//', '/', $new_path); + $new_path = str_replace("\\", "/", $new_path); + $html_file_list .= "
\n"; + $html_file_list .= ""; + $html_file_list .= "file$filename\n"; + $html_file_list .= "
\n"; + } } + //return completed html + return $html_dir_list . "\n" . $html_file_list; +} + //get the directory if (!isset($_SESSION)) { session_start(); } + switch ($_SESSION["app"]["edit"]["dir"]) { case 'scripts': - $edit_directory = $settings->get('switch', 'scripts'); + $edit_directory = $settings->get('switch', 'scripts', '/usr/share/freeswitch/scripts'); break; case 'php': $edit_directory = dirname(__DIR__, 2); break; case 'grammar': - $edit_directory = $settings->get('switch', 'grammar'); + $edit_directory = $settings->get('switch', 'grammar', '/usr/share/freeswitch/grammar'); break; case 'provision': switch (PHP_OS) { case "Linux": if (file_exists('/usr/share/fusionpbx/templates/provision')) { $edit_directory = '/usr/share/fusionpbx/templates/provision'; - } - elseif (file_exists('/etc/fusionpbx/resources/templates/provision')) { + } elseif (file_exists('/etc/fusionpbx/resources/templates/provision')) { $edit_directory = '/etc/fusionpbx/resources/templates/provision'; - } - else { - $edit_directory = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision"; + } else { + $edit_directory = dirname(__DIR__, 2) . "/resources/templates/provision"; } break; case "FreeBSD": - if (file_exists('/usr/local/share/fusionpbx/templates/provision')) { - $edit_directory = '/usr/share/fusionpbx/templates/provision'; - } - elseif (file_exists('/usr/local/etc/fusionpbx/resources/templates/provision')) { - $edit_directory = '/usr/local/etc/fusionpbx/resources/templates/provision'; - } - else { - $edit_directory = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision"; - } - break; - case "NetBSD": - if (file_exists('/usr/local/share/fusionpbx/templates/provision')) { - $edit_directory = '/usr/share/fusionpbx/templates/provision'; - } - else { - $edit_directory = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision"; - } - break; case "OpenBSD": + case "NetBSD": if (file_exists('/usr/local/share/fusionpbx/templates/provision')) { $edit_directory = '/usr/share/fusionpbx/templates/provision'; - } - else { - $edit_directory = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision"; + } else { + $edit_directory = dirname(__DIR__, 2) . "/resources/templates/provision"; } break; default: - $edit_directory = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision/"; + $edit_directory = dirname(__DIR__, 2) . "/resources/templates/provision/"; } break; case 'xml': - $edit_directory = $settings->get('switch', 'conf'); + $edit_directory = $settings->get('switch', 'conf', '/etc/freeswitch/autoload_configs'); break; default: //do not allow unknown settings @@ -167,8 +169,7 @@ function recur_dir($dir) { } // keyboard shortcut bindings -echo "\n"; -echo "\n"; +echo "\n"; //save file key_press('ctrl+s', 'down', 'window', null, null, "$('form#frm_edit').submit(); return false;", true); @@ -182,13 +183,16 @@ function recur_dir($dir) { echo "\n"; echo "\n"; -echo "
".$text['label-files']."
\n"; +echo "
\n"; +echo " \n"; +echo " \n"; +echo $text['label-files']; +echo " \n"; +echo "
\n"; echo "
\n"; if (file_exists($edit_directory)) { - $edit_html_list = recur_dir($edit_directory); - - echo $edit_html_list; + echo recur_dir($edit_directory); } echo "
\n"; diff --git a/index.php b/index.php index b6b2e06..16c5b49 100644 --- a/index.php +++ b/index.php @@ -1,50 +1,57 @@ - Portions created by the Initial Developer are Copyright (C) 2008-2024 - the Initial Developer. All Rights Reserved. + The Initial Developer of the Original Code is + Mark J Crane + Portions created by the Initial Developer are Copyright (C) 2008-2024 + the Initial Developer. All Rights Reserved. - Contributor(s): - Mark J Crane - James Rose -*/ + Contributor(s): + Mark J Crane + James Rose + */ -//includes files +// Include required files and check access require_once dirname(__DIR__, 2) . "/resources/require.php"; require_once "resources/check_auth.php"; -//check permissions +// Check permissions if (permission_exists('edit_view')) { //access granted - } - else { - echo "access denied"; - exit; - } + } else { + echo "access denied"; + exit; +} -//add multi-lingual support +// Add multi-lingual support $language = new text; $text = $language->get(); -//create the settings object - if (!$settings) { - $settings = new settings(); +// Set the domain and user UUIDs + $domain_uuid = $_SESSION['domain_uuid'] ?? ''; + $user_uuid = $_SESSION['user_uuid'] ?? ''; + +// Ensure the database and settings objects are created + global $database; + if (empty($database) || !($database instanceof database)) { + $database = database::new(); + } + if (empty($settings) || !($settings instanceof settings)) { + $settings = new settings(['database' => $database, 'domain_uuid' => $domain_uuid, 'user_uuid' => $user_uuid]); } //set the directory title and mode @@ -82,11 +89,6 @@ //save the sanitized value $_SESSION['app']['edit']['dir'] = $dir; -//ensure we have a settings object for older installs -if (empty($settings) || !($settings instanceof settings)) { - $settings = new settings(['database' => database::new(), 'domain_uuid' => $domain_uuid ?? $_SESSION['domain_uuid'] ?? '', 'user_uuid' => $user_uuid ?? $_SESSION['user_uuid'] ?? '']); -} - //load editor preferences/defaults $setting_size = $settings->get('editor', 'font_size', '12px'); $setting_theme = $settings->get('editor', 'theme', 'cobalt'); @@ -94,543 +96,750 @@ $setting_indenting = $settings->get('editor', 'indent_guides','false'); $setting_numbering = $settings->get('editor', 'line_numbers','true'); -//get and then set the favicon - $favicon = $settings->get('theme', 'favicon', PROJECT_ROOT .'/themes/default/favicon.ico'); +// Get the favicon + $favicon = $settings->get('theme', 'favicon', PROJECT_ROOT . '/themes/default/favicon.ico'); -//create a token - $key_name = '/app/edit/'.$mode; +// Create a token for file saving + $key_name = '/app/edit/' . $mode; $_SESSION['keys'][$key_name] = bin2hex(random_bytes(32)); $_SESSION['token'] = hash_hmac('sha256', $key_name, $_SESSION['keys'][$key_name]); - //The buffer must be empty - while(ob_get_level() > 0) +// Make sure the output buffer is empty + while (ob_get_level() > 0) { ob_get_clean(); + } ?> - - - <?php echo $title; ?> - - - - + + + + + + +
+ +
+
Loading file list...
+
Loading clips...
+
+ +
+ +
+
    +
    + + + + + + + + + + + +
    +
    + +
    +
    +
    + +
    +   + New File +
    + Line: + Column: +
    +
    + + +
    +
    + + - - - -
    - - - - -
    - -
    - - - -
    -
    - -
    -
    - -
    -
    -
    - -
    -
    - -
    -
    - -
    -
    - -
    -
    - -
    -
    - -
    -
    - -
    -
    - -
    -
    - -
    -
    -
    - -
    -
    -
    - - - - - - + diff --git a/resources/get_php_methods.php b/resources/get_php_methods.php index d531ef7..6f66b2d 100644 --- a/resources/get_php_methods.php +++ b/resources/get_php_methods.php @@ -1,81 +1,233 @@ [], + "functions" => [], + "superglobals"=> [] +]; + +// Get the list of classes and interfaces. $classes_to_scan = $autoload->get_class_list(); $interfaces = array_keys($autoload->get_interfaces()); +// Loop over each class (skipping interfaces and internal classes). foreach ($classes_to_scan as $class => $path) { - // Skip interfaces - if (in_array($class, $interfaces)) { - continue; - } - - // Guard against removed classes - if (!class_exists($class)) { - continue; - } - - // Create the RefectionClass for inspecting class - $ref = new ReflectionClass($class); - - // Skip internal classes - if ($ref->isInternal()) { - continue; - } - - $methods = []; - foreach ($ref->getMethods(ReflectionMethod::IS_PUBLIC) as $method) { - // Skip __construct - if ($method->getName() === '__construct') { - continue; - } - - // Get method parameters - $params = []; - foreach ($method->getParameters() as $param) { - $type = $param->hasType() ? $param->getType() . " " : ""; - $default = ""; - if ($param->isOptional() && $param->isDefaultValueAvailable()) { - $default = " = " . var_export($param->getDefaultValue(), true); - } - $params[] = $type . "$" . $param->getName() . $default; - } - - // Get the doc comment and clean it up - $doc = $method->getDocComment(); - if ($doc !== false) { - $doc = trim(preg_replace('/(^\/\*\*|\*\/$)/', '', $doc)); - $doc = preg_replace('/^\s*\*\s?/m', '', $doc); - } else { - $doc = ""; - } - - // Get the return type, if any - $return_type = ""; - if ($method->hasReturnType()) { - $rt = $method->getReturnType(); - $return_type = $rt->getName(); - if ($rt->allowsNull()) { - $return_type = "?" . $return_type; - } - } - - $methods[] = [ - "name" => $method->getName(), - "params" => "(" . implode(", ", $params) . ")", - "doc" => $doc, - "static" => $method->isStatic(), - "meta" => $return_type - ]; - } - $class_methods[$class] = $methods; + if (in_array($class, $interfaces)) { + continue; + } + // classes can be removed during development + if (!class_exists($class)) { + continue; + } + + $ref = new ReflectionClass($class); + if ($ref->isInternal()) { + continue; + } + + $methods = []; + // Retrieve public methods. + foreach ($ref->getMethods(ReflectionMethod::IS_PUBLIC) as $method) { + if ($method->getName() === '__construct') { + continue; + } + + $params = []; + foreach ($method->getParameters() as $param) { + $type = $param->hasType() ? $param->getType() . " " : ""; + $default = ""; + if ($param->isOptional() && $param->isDefaultValueAvailable()) { + $default = " = " . var_export($param->getDefaultValue(), true); + } + $params[] = $type . '$' . $param->getName() . $default; + } + + // Clean up the PHPDoc block. + $doc = $method->getDocComment(); + if ($doc !== false) { + // Remove the /** and */ markers. + $doc = trim(preg_replace('/(^\/\*\*|\*\/$)/', '', $doc)); + // Remove leading asterisks and any extra indentation. + $doc = preg_replace('/^\s*\*\s?/m', '', $doc); + $doc = preg_replace('/^\s+/m', '', $doc); + } else { + $doc = ""; + } + + $return_type = ""; + if ($method->hasReturnType()) { + $rt = $method->getReturnType(); + $return_type = $rt->getName(); + if ($rt->allowsNull()) { + $return_type = '?' . $return_type; + } + } + + // Build a method completion entry. + // Use "::" for static methods and "->" for instance methods. + $displayName = $class . ($method->isStatic() ? "::" : "->") . $method->getName(); + $methods[] = [ + "name" => $method->getName(), + "params" => "(" . implode(", ", $params) . ")", + "doc" => $doc, + "static" => $method->isStatic(), + "meta" => $return_type + ]; + } + + // Scan for declared properties. + $properties = []; + // You may filter here to include only public properties if desired. + foreach ($ref->getProperties() as $property) { + if (!$property->isPublic() && !$property->isProtected() && !$property->isPrivate()){ + continue; + } + + // Build the display name: use "::$" for static properties and "->" for instance ones. + if ($property->isStatic()) { + $displayName = $class . "::$" . $property->getName(); + } else { + $displayName = $class . "->" . $property->getName(); + } + + // Get the property PHPDoc if it exists. + $propDoc = $property->getDocComment(); + if ($propDoc !== false) { + $propDoc = trim(preg_replace('/(^\/\*\*|\*\/$)/', '', $propDoc)); + $propDoc = preg_replace('/^\s*\*\s?/m', '', $propDoc); + $propDoc = preg_replace('/^\s+/m', '', $propDoc); + } else { + $propDoc = ""; + } + + // Determine the visibility. + if ($property->isPublic()) { + $visibility = "public"; + } elseif ($property->isProtected()) { + $visibility = "protected"; + } elseif ($property->isPrivate()) { + $visibility = "private"; + } else { + $visibility = ""; + } + if ($property->isStatic()) { + $visibility .= " static"; + } + + $properties[] = [ + "name" => $property->getName(), + "display" => $displayName, + "doc" => $propDoc, + "meta" => trim($visibility) + ]; + } + + // Only add the class if there is at least one method or property. + if (!empty($methods) || !empty($properties)) { + $result["classes"][$class] = [ + "methods" => $methods, + "properties" => $properties + ]; + } +} + +// Process global (user-defined) functions. +$userFunctions = get_defined_functions()['user']; +$functions = []; +foreach ($userFunctions as $funcName) { + $reflection = new ReflectionFunction($funcName); + + $params = []; + foreach ($reflection->getParameters() as $parameter) { + $type = $parameter->hasType() ? $parameter->getType() . " " : ""; + $default = ""; + if ($parameter->isOptional() && $parameter->isDefaultValueAvailable()) { + $default = " = " . var_export($parameter->getDefaultValue(), true); + } + $params[] = $type . '$' . $parameter->getName() . $default; + } + + $docComment = $reflection->getDocComment() ?: ''; + // Clean up the function's PHPDoc block. + $docComment = trim(preg_replace('/(^\/\*\*|\*\/$)/', '', $docComment)); + $docComment = preg_replace('/^\s*\*\s?/m', '', $docComment); + $docComment = preg_replace('/^\s+/m', '', $docComment); + + $returnType = $reflection->getReturnType(); + $returnTypeName = $returnType ? $returnType->getName() : ''; + + $functions[] = [ + "name" => $reflection->getName(), + "params" => "(" . implode(", ", $params) . ")", + "doc" => $docComment, + "static" => false, + "meta" => $returnTypeName + ]; } +$result["functions"] = $functions; + +// Add PHP superglobals. +$superglobals = [ + [ + "name" => '$_GET', + "params" => "", + "doc" => "PHP Superglobal: Contains variables passed via URL query parameters.", + "static" => false, + "meta" => "superglobal" + ], + [ + "name" => '$_POST', + "params" => "", + "doc" => "PHP Superglobal: Contains variables passed via HTTP POST.", + "static" => false, + "meta" => "superglobal" + ], + [ + "name" => '$_COOKIE', + "params" => "", + "doc" => "PHP Superglobal: Contains cookie data.", + "static" => false, + "meta" => "superglobal" + ], + [ + "name" => '$_SERVER', + "params" => "", + "doc" => "PHP Superglobal: Contains server and execution environment information.", + "static" => false, + "meta" => "superglobal" + ], + [ + "name" => '$_FILES', + "params" => "", + "doc" => "PHP Superglobal: Contains information about files uploaded via HTTP POST.", + "static" => false, + "meta" => "superglobal" + ], + [ + "name" => '$_REQUEST', + "params" => "", + "doc" => "PHP Superglobal: Contains data from GET, POST, and COOKIE.", + "static" => false, + "meta" => "superglobal" + ], + [ + "name" => '$_ENV', + "params" => "", + "doc" => "PHP Superglobal: Contains environment variables.", + "static" => false, + "meta" => "superglobal" + ] +]; +$result["superglobals"] = $superglobals; header('Content-Type: application/json'); -echo json_encode($class_methods); +echo json_encode($result); +exit();