Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: hanyixuanten/browser-terminal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.3
Choose a base ref
...
head repository: hanyixuanten/browser-terminal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.4
Choose a head ref
  • 1 commit
  • 7 files changed
  • 1 contributor

Commits on Jul 15, 2024

  1. Copy the full SHA
    36a7eec View commit details
Showing with 63 additions and 25 deletions.
  1. +2 −3 commands/cd.php
  2. +9 −0 commands/clear.php
  3. +12 −0 commands/help.php
  4. +16 −0 commands/mkdir.php
  5. +10 −0 commands/pwd.php
  6. +3 −2 commands/rm.php
  7. +11 −20 terminal.php
5 changes: 2 additions & 3 deletions commands/cd.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
function cd($commands)
{
if(sizeof($commands)>2){
file_put_contents("recent.txt", "Too many arguments.<br/>", FILE_APPEND);
if (sizeof($commands) > 2) {
file_put_contents("recent.txt", "Invalid number of arguments.<br/>", FILE_APPEND);
return;
}
$pwd = file_get_contents("pwd.txt");
@@ -23,4 +23,3 @@ function cd($commands)
}
}
}
?>
9 changes: 9 additions & 0 deletions commands/clear.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
function clear($commands)
{
if (sizeof($commands) == 1) {
file_put_contents("recent.txt", "");
} else {
file_put_contents("recent.txt", "Invalid number of arguments.<br/>", FILE_APPEND);
}
}
12 changes: 12 additions & 0 deletions commands/help.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
function help($commands)
{
$help = file_get_contents("static/terminal.php/help.txt");
if (sizeof($commands) == 1) {
file_put_contents("recent.txt", $help, FILE_APPEND);
} else if (sizeof($commands) == 2 && file_get_contents("static/help/$commands[1].txt") != NULL) {
file_put_contents("recent.txt", file_get_contents("static/help/$commands[1].txt"), FILE_APPEND);
} else {
file_put_contents("recent.txt", "Invalid number of arguments.<br/>", FILE_APPEND);
}
}
16 changes: 16 additions & 0 deletions commands/mkdir.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
function mdir($commands)
{
$pwd = file_get_contents("pwd.txt");
if (sizeof($commands) == 2) {
if (!opendir("fileroot" . $pwd . "/" . $commands[1])) {
if (!mkdir("fileroot" . $pwd . "/" . $commands[1])) {
file_put_contents("recent.txt", "Error creating directory.No permissions?<br/>", FILE_APPEND);
}
} else {
file_put_contents("recent.txt", "Directory already exists.<br/>", FILE_APPEND);
}
} else {
file_put_contents("recent.txt", "Invalid number of arguments.<br/>", FILE_APPEND);
}
}
10 changes: 10 additions & 0 deletions commands/pwd.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
function pwd($commands)
{
$pwd = file_get_contents("pwd.txt");
if (sizeof($commands) == 1) {
file_put_contents("recent.txt", $pwd . "<br/>", FILE_APPEND);
} else {
file_put_contents("recent.txt", "Invalid number of arguments.<br/>", FILE_APPEND);
}
}
5 changes: 3 additions & 2 deletions commands/rm.php
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ function rm($commands)
} else {
file_put_contents("recent.txt", "Not a directory.<br/>", FILE_APPEND);
}
} else {
} else if (sizeof($commands) == 2) {
if (is_dir("fileroot" . $pwd . "/" . $commands[1])) {
file_put_contents("recent.txt", "Is a directory.<br/>Try rm -r<br/>", FILE_APPEND);
} else {
@@ -30,6 +30,7 @@ function rm($commands)
file_put_contents("recent.txt", "Error deleting.<br/>", FILE_APPEND);
}
}
} else {
file_put_contents("recent.txt", "Invalid number of arguments.<br/>", FILE_APPEND);
}
}
?>
31 changes: 11 additions & 20 deletions terminal.php
Original file line number Diff line number Diff line change
@@ -40,33 +40,24 @@
echo "<script>window.scrollTo(0,document.body.scrollHeight)</script>";
exit(0);
}
if ($commands[0] == "pwd" & sizeof($commands) == 1) {
file_put_contents("recent.txt", $pwd . "<br/>", FILE_APPEND);
} else if ($commands[0] == "mkdir" && sizeof($commands) == 2) {
if (!opendir("fileroot" . $pwd . "/" . $commands[1])) {
if (!mkdir("fileroot" . $pwd . "/" . $commands[1])) {
file_put_contents("recent.txt", "Error creating directory.No permissions?<br/>", FILE_APPEND);
}
} else {
file_put_contents("recent.txt", "Directory already exists.<br/>", FILE_APPEND);
}
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" & sizeof($commands) == 1) {
file_put_contents("recent.txt", "");
} 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") {
$help = file_get_contents("static/terminal.php/help.txt");
if (sizeof($commands) == 1) {
file_put_contents("recent.txt", $help, FILE_APPEND);
} else if (sizeof($commands) == 2 && file_get_contents("static/help/$commands[1].txt") != NULL) {
file_put_contents("recent.txt", file_get_contents("static/help/$commands[1].txt"), FILE_APPEND);
} else {
file_put_contents("recent.txt", "Unknown command.<br/>", FILE_APPEND);
}
include "commands/help.php";
help($commands);
} else {
file_put_contents("recent.txt", "Unknown command.<br/>try 'help' or 'help [command]'<br/>", FILE_APPEND);
}