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
$postData = file_get_contents("php://input");
$postData = json_decode($postData, true);
$uid = $postData['id'];
$uname = $postData['username'];
$filename = $postData['filename'];
$language = $postData['language'];
......@@ -11,22 +12,22 @@ $ret_stat = 0;
if(strcmp($language, "cpp") == 0)
{
$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)
{
unlink($uid . "/" . $base);
unlink("../users/" . $uname . "/" . $base);
}
}
else if(strcmp($language, "java") == 0)
{
$base = basename($filename, ".java");
system("javac " . $uid . "/" . $filename , $ret_stat);
system("javac ../users/" . $uname . "/" . $filename , $ret_stat);
if($ret_stat != 0)
{
unlink($uid . "/" . $base . ".class");
unlink("../users/" . $uname . "/" . $base . ".class");
}
}
......
-- phpMyAdmin SQL Dump
-- version 5.0.2
-- version 5.0.3
-- https://www.phpmyadmin.net/
--
-- 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
-- PHP Version: 7.4.10
-- PHP Version: 7.4.11
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
......@@ -24,49 +24,48 @@ SET time_zone = "+00:00";
-- --------------------------------------------------------
--
-- Table structure for table `users`
-- Table structure for table `userdata`
--
CREATE TABLE `users` (
`id` int(11) NOT NULL,
CREATE TABLE `userdata` (
`username` varchar(50) NOT NULL,
`name` varchar(50) DEFAULT NULL,
`password` varchar(255) DEFAULT NULL,
`email` varchar(255) DEFAULT NULL,
`img_url` text DEFAULT 'https://bain.design/wp-content/uploads/2014/08/People-Avatar-Set-Rectangular-12.jpg',
`n_attempts` int(11) NOT NULL DEFAULT 0,
`correct_timeline` text DEFAULT '[]',
`rating` int(11) NOT NULL DEFAULT 0
`n_files` int(11) DEFAULT NULL,
`img_url` text DEFAULT NULL,
`n_attempts` int(11) DEFAULT NULL,
`correct_timeline` text DEFAULT NULL,
`rating` int(11) DEFAULT NULL
) 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
(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);
CREATE TABLE `users` (
`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 table `users`
-- Indexes for table `userdata`
--
ALTER TABLE `users`
ADD PRIMARY KEY (`id`);
ALTER TABLE `userdata`
ADD PRIMARY KEY (`username`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `users`
-- Indexes for table `users`
--
ALTER TABLE `users`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=25;
ADD PRIMARY KEY (`username`);
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
\ No newline at end of file
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
<?php
$postData = file_get_contents("php://input");
$postData = json_decode($postData, true);
$uid = $postData['id'];
$uname = $postData['username'];
$filename = $postData['filename'];
$language = $postData['language'];
$input_data = $postData['input_data'];
......@@ -10,29 +11,29 @@ $input_data = $postData['input_data'];
$ret_stat = 0;
$template = strval(rand(1, 1000000));
$in_fname = $uid . "/" . "temp_in" . $template;
$in_fname = "../users/" . $uname . "/" . "temp_in" . $template;
$file = fopen($in_fname, 'w');
file_put_contents($in_fname, $input_data);
fclose($file);
$out_fname = $uid . "/" . "temp_out" . $template;
$out_fname = "../users/" . $uname . "/" . "temp_out" . $template;
if(strcmp($language, "cpp") == 0)
{
$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)
{
$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)
{
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)
......
<?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,27 +15,29 @@ if (isset($postData) && !empty($postData)) {
$msg = "file already exists";
clearstatcache();
echo json_encode($msg);
} else {
// $sql1 = "SELECT n_files from userdata where username = $username";
// $sql2 = "UPDATE userdata SET n_files = n_files+1 WHERE username = $username ";
// $result = mysqli_query($mysqli, $sql1);
// if($result == 10){
// $msg = "maximum limit(10) exceeded";
// echo json_encode($msg);
// }
// else{
// if($result = mysqli_query($mysqli, $sql2)) {
$myfile = fopen($path, "w");
fwrite($myfile, $data);
fclose($myfile);
}
else {
$sql1 = "SELECT n_files from userdata where username = $username";
$sql2 = "UPDATE userdata SET n_files = n_files+1 WHERE username = $username ";
$result = mysqli_query($mysqli, $sql1);
if($result == 10){
$msg = "maximum limit(10) reached";
echo json_encode($msg);
}
else{
if($result = mysqli_query($mysqli, $sql2)) {
$myfile = fopen($path, "w");
fwrite($myfile, $data);
fclose($myfile);
$msg = "file successfully uploaded";
clearstatcache();
echo json_encode($msg);
// }
// else{
// http_response_code(404);
// }
$msg = "file successfully uploaded";
clearstatcache();
echo json_encode($msg);
}
else{
http_response_code(404);
}
}
}
......
......@@ -4,8 +4,8 @@ $postData = file_get_contents("php://input");
if(isset($postData) && !empty($postData)) {
$request = json_decode($postData);
// $username = trim($request->username);
$dir = trim($request->dir);
$path = trim($request->currdir) . '/' . $dir;
$dirname = trim($request->dirname);
$path = trim($request->currdir) . '/' . $dirname;
if(file_exists($path)) {
$msg = "directory already exists";
clearstatcache();
......
......@@ -20,7 +20,8 @@ if (isset($postData) && !empty($postData)) {
];
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);
}
......
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