Commit b19ad184 authored by Ayush's avatar Ayush

Merge branch 'master' of https://git.cse.iitb.ac.in/ayushjangir/sfcode

Merge
parents d8ec8044 f97fa5e5
<?php <?php
$postData = file_get_contents("php://input"); $postData = file_get_contents("php://input");
$postData = json_decode($postData, true);
$uid = $postData['id']; $uname = $postData['username'];
$filename = $postData['filename']; $filename = $postData['filename'];
$language = $postData['language']; $language = $postData['language'];
...@@ -11,22 +12,22 @@ $ret_stat = 0; ...@@ -11,22 +12,22 @@ $ret_stat = 0;
if(strcmp($language, "cpp") == 0) if(strcmp($language, "cpp") == 0)
{ {
$base = basename($filename, ".cpp"); $base = basename($filename, ".cpp");
system("g++ " . $uid . "/" . $filename . " -o " . $uid . "/" . $base , $ret_stat); system("g++ ../users/" . $uname . "/" . $filename . " -o ../users/" . $uname . "/" . $base , $ret_stat);
if($ret_stat != 0) if($ret_stat != 0)
{ {
unlink($uid . "/" . $base); unlink("../users/" . $uname . "/" . $base);
} }
} }
else if(strcmp($language, "java") == 0) else if(strcmp($language, "java") == 0)
{ {
$base = basename($filename, ".java"); $base = basename($filename, ".java");
system("javac " . $uid . "/" . $filename , $ret_stat); system("javac ../users/" . $uname . "/" . $filename , $ret_stat);
if($ret_stat != 0) if($ret_stat != 0)
{ {
unlink($uid . "/" . $base . ".class"); unlink("../users/" . $uname . "/" . $base . ".class");
} }
} }
......
-- phpMyAdmin SQL Dump -- phpMyAdmin SQL Dump
-- version 5.0.2 -- version 5.0.3
-- https://www.phpmyadmin.net/ -- https://www.phpmyadmin.net/
-- --
-- Host: localhost -- Host: localhost
-- Generation Time: Oct 28, 2020 at 02:33 AM -- Generation Time: Dec 06, 2020 at 03:21 PM
-- Server version: 10.4.14-MariaDB -- Server version: 10.4.14-MariaDB
-- PHP Version: 7.4.10 -- PHP Version: 7.4.11
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION; START TRANSACTION;
...@@ -24,47 +24,46 @@ SET time_zone = "+00:00"; ...@@ -24,47 +24,46 @@ SET time_zone = "+00:00";
-- -------------------------------------------------------- -- --------------------------------------------------------
-- --
-- Table structure for table `users` -- Table structure for table `userdata`
-- --
CREATE TABLE `users` ( CREATE TABLE `userdata` (
`id` int(11) NOT NULL,
`username` varchar(50) NOT NULL, `username` varchar(50) NOT NULL,
`name` varchar(50) DEFAULT NULL, `n_files` int(11) DEFAULT NULL,
`password` varchar(255) DEFAULT NULL, `img_url` text DEFAULT NULL,
`email` varchar(255) DEFAULT NULL, `n_attempts` int(11) DEFAULT NULL,
`img_url` text DEFAULT 'https://bain.design/wp-content/uploads/2014/08/People-Avatar-Set-Rectangular-12.jpg', `correct_timeline` text DEFAULT NULL,
`n_attempts` int(11) NOT NULL DEFAULT 0, `rating` int(11) DEFAULT NULL
`correct_timeline` text DEFAULT '[]',
`rating` int(11) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- --------------------------------------------------------
-- --
-- Dumping data for table `users` -- Table structure for table `users`
-- --
INSERT INTO `users` (`id`, `username`, `name`, `password`, `email`, `img_url`, `n_attempts`, `correct_timeline`, `rating`) VALUES CREATE TABLE `users` (
(24, 'ayushjangir', 'Ayush Jangir', '$2y$10$VXSfup83ux6QKRIt4LPPZ.lAz7GbvN6yT/Tk5LH5eNKk1oussrwHm', 'jangirayush59@gmail.com', 'https://bain.design/wp-content/uploads/2014/08/People-Avatar-Set-Rectangular-12.jpg', 150, '[0,1,1,0,1,0,1,1,0,1,1,1,0,0,0,1,1,1,0,1,1,1,0,1,1,0,0,0,1,0,1,0,1,1,1,1,1,1,1,0,1,0,1,1,1,0,1,1,0,0,0,1,0,0,1,0,1,0,1,1,0,1,0,0,0,1,0,1,1,1,1,0,0,0,0,1,0,0,0,0,1,1,0,0,0,0,1,0,0,0,0,1,0,1,0,1,1,0,0,1,1,0,1,0,0,0,0,0,0,1,1,1,1,0,0,0,1,1,1,1,0,0,1,0,1,1,1,1,1,0,1,1,1,1,0,1,1,1,0,0,0,0,1,0,1,0,1,1,1,1]', 1278); `username` varchar(50) NOT NULL,
`name` varchar(50) DEFAULT NULL,
`password` varchar(255) DEFAULT NULL,
`email` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- --
-- Indexes for dumped tables -- Indexes for dumped tables
-- --
-- --
-- Indexes for table `users` -- Indexes for table `userdata`
-- --
ALTER TABLE `users` ALTER TABLE `userdata`
ADD PRIMARY KEY (`id`); ADD PRIMARY KEY (`username`);
-- --
-- AUTO_INCREMENT for dumped tables -- Indexes for table `users`
--
--
-- AUTO_INCREMENT for table `users`
-- --
ALTER TABLE `users` ALTER TABLE `users`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=25; ADD PRIMARY KEY (`username`);
COMMIT; COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
......
<?php <?php
$postData = file_get_contents("php://input"); $postData = file_get_contents("php://input");
$postData = json_decode($postData, true);
$uid = $postData['id']; $uname = $postData['username'];
$filename = $postData['filename']; $filename = $postData['filename'];
$language = $postData['language']; $language = $postData['language'];
$input_data = $postData['input_data']; $input_data = $postData['input_data'];
...@@ -10,29 +11,29 @@ $input_data = $postData['input_data']; ...@@ -10,29 +11,29 @@ $input_data = $postData['input_data'];
$ret_stat = 0; $ret_stat = 0;
$template = strval(rand(1, 1000000)); $template = strval(rand(1, 1000000));
$in_fname = $uid . "/" . "temp_in" . $template; $in_fname = "../users/" . $uname . "/" . "temp_in" . $template;
$file = fopen($in_fname, 'w'); $file = fopen($in_fname, 'w');
file_put_contents($in_fname, $input_data); file_put_contents($in_fname, $input_data);
fclose($file); fclose($file);
$out_fname = $uid . "/" . "temp_out" . $template; $out_fname = "../users/" . $uname . "/" . "temp_out" . $template;
if(strcmp($language, "cpp") == 0) if(strcmp($language, "cpp") == 0)
{ {
$base = basename($filename, ".cpp"); $base = basename($filename, ".cpp");
system("./" . $uid . "/" . $base . " < " . $in_fname . " > " . $out_fname, $ret_stat); system("./../users/" . $uname . "/" . $base . " < " . $in_fname . " > " . $out_fname, $ret_stat);
} }
else if(strcmp($language, "java") == 0) else if(strcmp($language, "java") == 0)
{ {
$base = basename($filename, ".java"); $base = basename($filename, ".java");
system("java -cp " . $uid . "/ " . $base . " < " . $in_fname . " > " . $out_fname, $ret_stat); system("java -cp ../users/" . $uname . "/ " . $base . " < " . $in_fname . " > " . $out_fname, $ret_stat);
} }
else if(strcmp($language, "python") == 0) else if(strcmp($language, "python") == 0)
{ {
system("python3 " . $uid . "/" . $filename . " < " . $in_fname . " > " . $out_fname, $ret_stat); system("python3 ../users/" . $uname . "/" . $filename . " < " . $in_fname . " > " . $out_fname, $ret_stat);
} }
if($ret_stat != 0) if($ret_stat != 0)
......
<?php
include_once("database.php");
$postData = file_get_contents("php://input");
if (isset($postData) && !empty($postData)) {
$request = json_decode($postData);
$username = trim($request->username);
$data = trim($request->text);
$filename = trim($request->filename);
$lang = trim($request->language);
$path = '../users/' . $username . '/' . trim($request->path) . '/' . $filename . $lang;
if (unlink($path)) {
$msg = "file successfully deleted";
clearstatcache();
echo json_encode($msg);
}
else {
http_response_code(404);
}
}
?>
...@@ -15,16 +15,17 @@ if (isset($postData) && !empty($postData)) { ...@@ -15,16 +15,17 @@ if (isset($postData) && !empty($postData)) {
$msg = "file already exists"; $msg = "file already exists";
clearstatcache(); clearstatcache();
echo json_encode($msg); echo json_encode($msg);
} else { }
// $sql1 = "SELECT n_files from userdata where username = $username"; else {
// $sql2 = "UPDATE userdata SET n_files = n_files+1 WHERE username = $username "; $sql1 = "SELECT n_files from userdata where username = $username";
// $result = mysqli_query($mysqli, $sql1); $sql2 = "UPDATE userdata SET n_files = n_files+1 WHERE username = $username ";
// if($result == 10){ $result = mysqli_query($mysqli, $sql1);
// $msg = "maximum limit(10) exceeded"; if($result == 10){
// echo json_encode($msg); $msg = "maximum limit(10) reached";
// } echo json_encode($msg);
// else{ }
// if($result = mysqli_query($mysqli, $sql2)) { else{
if($result = mysqli_query($mysqli, $sql2)) {
$myfile = fopen($path, "w"); $myfile = fopen($path, "w");
fwrite($myfile, $data); fwrite($myfile, $data);
fclose($myfile); fclose($myfile);
...@@ -32,10 +33,11 @@ if (isset($postData) && !empty($postData)) { ...@@ -32,10 +33,11 @@ if (isset($postData) && !empty($postData)) {
$msg = "file successfully uploaded"; $msg = "file successfully uploaded";
clearstatcache(); clearstatcache();
echo json_encode($msg); echo json_encode($msg);
// } }
// else{ else{
// http_response_code(404); http_response_code(404);
// } }
}
} }
......
...@@ -4,8 +4,8 @@ $postData = file_get_contents("php://input"); ...@@ -4,8 +4,8 @@ $postData = file_get_contents("php://input");
if(isset($postData) && !empty($postData)) { if(isset($postData) && !empty($postData)) {
$request = json_decode($postData); $request = json_decode($postData);
// $username = trim($request->username); // $username = trim($request->username);
$dir = trim($request->dir); $dirname = trim($request->dirname);
$path = trim($request->currdir) . '/' . $dir; $path = trim($request->currdir) . '/' . $dirname;
if(file_exists($path)) { if(file_exists($path)) {
$msg = "directory already exists"; $msg = "directory already exists";
clearstatcache(); clearstatcache();
......
...@@ -20,7 +20,8 @@ if (isset($postData) && !empty($postData)) { ...@@ -20,7 +20,8 @@ if (isset($postData) && !empty($postData)) {
]; ];
mkdir('../users/' . $authData['username']); mkdir('../users/' . $authData['username']);
$sql1 = "INSERT INTO userdata(username,n_files,img_url,n_attempts,correct_timeline,rating) VALUES ('$username',0,'https://bain.design/wp-content/uploads/2014/08/People-Avatar-Set-Rectangular-12.jpg',0,'[]',0)";
$mysqli->query($sql1);
echo json_encode($authData); echo json_encode($authData);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment