Explorar el Código

Added addscript

3ndur4nce hace 3 años
padre
commit
4ffc414936
Se han modificado 2 ficheros con 51 adiciones y 23 borrados
  1. 19 2
      WebPage/place/postactions.php
  2. 32 21
      WebPage/place/scripts.php

+ 19 - 2
WebPage/place/postactions.php

@@ -17,9 +17,26 @@ if($place == "assets" && $sched == "save"){
     if(isset($script)){
         $shell = trim($_POST["shell"]);
         $data = trim($_POST["script"]);
-        $editscript = "UPDATE scripts set shell = ?, data = ? where id = $script";
+        $scriptname = trim($_POST["scriptname"]);
+        $editscript = "UPDATE scripts set name = ?, shell = ?, data = ? where id = $script";
         if($stmt = mysqli_prepare($link, $editscript)){
-            mysqli_stmt_bind_param($stmt, "ss", $shell, $data);
+            mysqli_stmt_bind_param($stmt, "sss", $scriptname, $shell, $data);
+            if(mysqli_stmt_execute($stmt)){
+                header("location: ?a=scripts&script=$script");
+                exit;
+            }else{
+                echo "Oops! Something went wrong. Please try again later.";
+            }
+        }
+    }
+}elseif($place == "scripts" && $do == "newscript"){
+    if(isset($script)){
+        $shell = trim($_POST["shell"]);
+        $data = trim($_POST["script"]);
+        $scriptname = trim($_POST["scriptname"]);
+        $addscript = "INSERT into scripts (name, shell, data) values (?, ?, ?)";
+        if($stmt = mysqli_prepare($link, $addscript)){
+            mysqli_stmt_bind_param($stmt, "sss", $scriptname, $shell, $data);
             if(mysqli_stmt_execute($stmt)){
                 header("location: ?a=scripts&script=$script");
                 exit;

+ 32 - 21
WebPage/place/scripts.php

@@ -2,6 +2,7 @@
     <a>Scripts</a><br>
     <?php
     
+    echo "<a href='?a=scripts&script=newscript' class='collumnbutton'>--> New <--</a>";
     $getscriptsqry = mysqli_query($link, "select * from scripts ORDER BY name ASC");
     while($row = mysqli_fetch_array($getscriptsqry)){
         echo "<a href='?a=scripts&script=".$row['id']."' class='collumnbutton'>".$row['name']."</a>";
@@ -9,28 +10,35 @@
 echo "</div>";
 
     if(isset($script)){
-        $getscriptsqry = mysqli_query($link, "select * from scripts where id = $script");
-        while($row = mysqli_fetch_array($getscriptsqry)){
-            $scriptname = $row['name'];
-            $scriptdata = $row['data'];
-            $shell = $row['shell'];
-        }
-        if($shell == 'powershell'){
-            $powershell = "powershell' selected='selected";
-            $cmd = "cmd";
-            $bash = "bash";
-        }elseif($shell == 'cmd'){
-            $powershell = "powershell";
-            $cmd = "cmd' selected='selected";
-            $bash = "bash";
-        }elseif($shell == 'bash'){
-            $powershell = "powershell";
-            $cmd = "cmd";
-            $bash = "bash' selected='selected";
+        if($script != 'newscript'){
+            $do = "scriptedit";
+            $getscriptsqry = mysqli_query($link, "select * from scripts where id = $script");
+            while($row = mysqli_fetch_array($getscriptsqry)){
+                $scriptname = $row['name'];
+                $scriptdata = $row['data'];
+                $shell = $row['shell'];
+            }
+            if($shell == 'powershell'){
+                $powershell = "powershell' selected='selected";
+                $cmd = "cmd";
+                $bash = "bash";
+            }elseif($shell == 'cmd'){
+                $powershell = "powershell";
+                $cmd = "cmd' selected='selected";
+                $bash = "bash";
+            }elseif($shell == 'bash'){
+                $powershell = "powershell";
+                $cmd = "cmd";
+                $bash = "bash' selected='selected";
+            }
+        }else{
+            $do = "newscript";
         }
+        
         echo "<div class='editcollumn'>
-        <a>$scriptname</a><br>
-        <form action='?a=scripts&script=$script&do=scriptedit' method='POST'>
+        <a>Name</a><br>
+        <form action='?a=scripts&script=$script&do=$do' method='POST'>
+            <input type='text' name='scriptname' class='input' placeholder='Script Name' value='$scriptname'><br>
             <select id='shell' name='shell'>
                 <option value='$cmd'>CMD</option>
                 <option value='$powershell'>PowerShell</option>
@@ -40,4 +48,7 @@ echo "</div>";
             <input type='submit' class='button' value='Save'>
             </form>
         ";
-    }
+    }
+
+
+