optimize terminal.php

This commit is contained in:
2024-10-14 23:04:58 +08:00
parent 0a3a07be1e
commit 95a7e6c39b
11 changed files with 17 additions and 41 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
<?php
function cat($commands)
function func($commands)
{
$pwd = file_get_contents("pwd.txt");
if (sizeof($commands) > 2) {
+1 -1
View File
@@ -1,5 +1,5 @@
<?php
function cd($commands)
function func($commands)
{
if (sizeof($commands) > 2) {
file_put_contents("recent.txt", "Invalid number of arguments.<br/>", FILE_APPEND);
+1 -1
View File
@@ -1,5 +1,5 @@
<?php
function clear($commands)
function func($commands)
{
if (sizeof($commands) == 1) {
file_put_contents("recent.txt", "");
+1 -1
View File
@@ -1,5 +1,5 @@
<?php
function help($commands)
function func($commands)
{
$help = file_get_contents("static/terminal.php/help.txt");
if (sizeof($commands) == 1) {
+1 -1
View File
@@ -1,5 +1,5 @@
<?php
function ls($commands)
function func($commands)
{
$pwd = file_get_contents("pwd.txt");
if (sizeof($commands) == 1) {
+1 -1
View File
@@ -1,5 +1,5 @@
<?php
function mdir($commands)
function func($commands)
{
$pwd = file_get_contents("pwd.txt");
if (sizeof($commands) == 2) {
+1 -1
View File
@@ -1,5 +1,5 @@
<?php
function pwd($commands)
function func($commands)
{
$pwd = file_get_contents("pwd.txt");
if (sizeof($commands) == 1) {
+1 -1
View File
@@ -7,7 +7,7 @@ function deleteDirectory($dir)
}
return rmdir($dir);
}
function rm($commands)
function func($commands)
{
$pwd = file_get_contents("pwd.txt");
if ($commands[1] == "-r") {
+1 -1
View File
@@ -1,5 +1,5 @@
<?php
function touc($commands)
function func($commands)
{
$pwd = file_get_contents("pwd.txt");
if (sizeof($commands) == 2) {
+1 -2
View File
@@ -1,3 +1,2 @@
make php
write php
write help.txt <command_name>.txt
edit terminal.php
+5 -28
View File
@@ -40,34 +40,11 @@ if (!opendir("fileroot")) {
echo "<script>window.scrollTo(0,document.body.scrollHeight)</script>";
exit(0);
}
if ($commands[0] == "pwd") {
include "commands/pwd.php";
pwd($commands);
} else if ($commands[0] == "mkdir") {
include "commands/mkdir.php";
mdir($commands);
} else if ($commands[0] == "rm") {
include "commands/rm.php";
rm($commands);
} else if ($commands[0] == "clear") {
include "commands/clear.php";
clear($commands);
} else if ($commands[0] == "cd") {
include "commands/cd.php";
cd($commands);
} else if ($commands[0] == "help") {
include "commands/help.php";
help($commands);
} else if ($commands[0] == "touch") {
include "commands/touch.php";
touc($commands);
} else if ($commands[0] == "cat") {
include "commands/cat.php";
cat($commands);
} else if ($commands[0] == "ls") {
include "commands/ls.php";
ls($commands);
} else {
if(file_get_contents("commands/$commands[0].php") != NULL){
include "commands/$commands[0].php";
func($commands);
}
else{
file_put_contents("recent.txt", "Unknown command.<br/>try 'help' or 'help [command]'<br/>", FILE_APPEND);
}
echo "<script>window.location.href=\"terminal.php\";</script>";