Deep Gandhi
Deep Gandhi

Reputation: 39

How to create linux terminal like tutorialspoint?

TutorialsPoint Java Compiler

In tutorialspoint, they have created linux terminal using term.js.

I have integrated same github library in my project, it is working fine but I am trying to understand the flow of tutorialspoint.

My assumption:

I am running nodejs server using forever.js under root user, I want to implement same type of functionality. What is correct way to do this? and if there is another way please elaborate.

Upvotes: 1

Views: 237

Answers (1)

mertyildiran
mertyildiran

Reputation: 6613

I think they are creating a new user each time you visit the page and providing you a subshell of that user. It can be easily achieve by using Shell Programming techniques. Creating a new user each time thing is probably nothing more than a security measure.

So I will briefly explain the concept in 5 steps:

1 - Create a new user:

shell_exec('useradd --expiredate 2016-09-10 [username]');

http://www.computerhope.com/unix/useradd.htm

2 - Login to this newly created user account:

shell_exec('su [username]');

3 - Get user input to the PHP script using AJAX(dynamically).

4 - Execute user's command and send the output to user:

<?php
$output = shell_exec("[user's command]");
echo "<pre>$output</pre>";
?>

5 - Repeat from 3.

Upvotes: 1

Related Questions