[ZnoteACC] Start server from AAC (Linux only)

JoccE

CopyLeft (ɔ)
Joined
Aug 26, 2007
Messages
3,417
Best answers
1
Likes
90
Location
Sweden, Stockholm
#1
So.... i have made a weird admin panel script to start/stop the server from www. if you for example wants to start the server from the phone or like me renting servers too people and don't want them to have ssh access.

The old thread in discussing section: http://otland.net/f251/simple-admin-panel-ots-178011/#post1726553
So.
Begin with creating a adminserver.php in your /var/www/ and add this:

PHP:
<?php require_once 'engine/init.php'; include 'layout/overall/header.php'; 
protect_page();
admin_only($user_data);
// start

if(isset($_POST['test'])) { 
    if (check_if_process_is_running("theforgottenserver"))
		{
			  echo "<h2><b><font color='green'>Server is already running</font></b></h2>";
		} else
		{
			  shell_exec('cd /home/server1/ && ./theforgottenserver > my.log 2>&1 &'); //Serverpath
		}
}
if(isset($_POST['kill'])) {
	shell_exec('killall -9 theforgottenserver');
}
if(isset($_POST['safe'])) {
	shell_exec('killall -QUIT theforgottenserver');
}



function check_if_process_is_running($process)
{
    exec("/bin/pidof $process",$response);
    if ($response)
    {
         return true;
    } else
    {
         return false;
    }
}

if (check_if_process_is_running("theforgottenserver"))
		{
			  echo "<h2><b><font color='green'>Server is running</font></b></h2>";
		} else
		{
			  echo "<h3><b><font color='red'>Server is NOT running</font></b></h3>";
}

?>
	
<div id="text">
	This is the beta version of JoccEs Admin panel to start/stop tibia servers<br>
	<b>Functions:</b><br>
	<b>Start:</b> Starts the server using ./theforgottenserver (no Autorestarter) Now with logging enabled.<br> 
	<b>Save and Quit:</b> Saves the server the stops it.<br>
	<b>Kill Server:</b> Instantly Stops the server using "killall -9 theforgottenserver"<br>
	<b>Logs:</b> Shows the startup output after you have shut down server (a bit buggy server need to be offline to read it)
	<br>
	<br>
</div>
	
<script type="text/javascript">
		function newPopup(url) {
		popupWindow = window.open(
		url,'popUpWindow','height=700,width=800,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
		}
</script>
	
	<!-- Buttons -->
	<div id="buttons>">
		<form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
		<input type="submit" name="test" value="Start Server">
		</form>
		
		<form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
		<input type="submit" name="safe" value="Save and Quit">
		</form>		
		
		<form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
		<input type="submit" name="kill" value="Kill Server">
		</form>
		
		<!--<form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
		<input type="submit" name="test" value="Test Button do not use">
		</form> -->
		
		<button onclick="newPopup('my.log')">Startup Logs</button>
		
	</div>
	
	<div id="info">
	<br>
		<b>Current Bugs:</b><br>
		--NONE<br>
		<br>
		<b>Future Features:</b><br>
		--Be able to start server with auto restarter.<br>
		--More functions: Examples: Clean map and Save Server. (done just not added)<br> 
	</div>
	
<?php
// end
 include 'layout/overall/footer.php'; ?>
On line 7 you need to change the path to the server files.

Then go to /var/www/layout/widget/loggedin.php

and add this under the "if (is_admin($user_data)) {"

PHP:
			<li>
				<a href='adminserver.php'>Admin Startup</a>
			</li>





The startup login wont work until you make a "ln -s" from the my.log in serverpath too somewhere in the www folder example: ln -s /home/server1/my.log /var/www/my.log



I know that this is not "professionally made" or anything, but i suck at PHP and HTML. But it works and you can only use it if your name is in config.php as web admin.
I have not seen anything like it tho and it is a pretty nice function.

If anyone wants too remake it. Go ahead, please release it. The word of ZNOTE: Because open communities are good communities. :3
 
Last edited:

JoccE

CopyLeft (ɔ)
Joined
Aug 26, 2007
Messages
3,417
Best answers
1
Likes
90
Location
Sweden, Stockholm
#5
seems nice. I'll test it soon. where did you get the idea? :)
Oh i got a dedicated server where i dont want my clients to have ssh access :p So i use this instead

And then they wanted too see server output ofc.. :p so i made some weird solution for that.
 

Diath

DIATH
Joined
Jun 4, 2010
Messages
1,973
Best answers
0
Likes
102
Location
Saint Petersburg, Russian Federation
#11
Instead of using killall you should retrieve process id while spawning it and then killing it directly by the id, you'll avoid killing any other server running under the same name, also no need to cd to the directory, you can call the binary by full path (always some less calls). Another thing is check_if_process_is_running, first of all there's no reason to define a function when you use it only once, you should do that only when something is repetitive and please avoid such function names, CheckProcess perhaps would be way simpler and cleaner.
 

JoccE

CopyLeft (ɔ)
Joined
Aug 26, 2007
Messages
3,417
Best answers
1
Likes
90
Location
Sweden, Stockholm
#12
Instead of using killall you should retrieve process id while spawning it and then killing it directly by the id, you'll avoid killing any other server running under the same name, also no need to cd to the directory, you can call the binary by full path (always some less calls). Another thing is check_if_process_is_running, first of all there's no reason to define a function when you use it only once, you should do that only when something is repetitive and please avoid such function names, CheckProcess perhaps would be way simpler and cleaner.
Okey :) Thanks
 

JoccE

CopyLeft (ɔ)
Joined
Aug 26, 2007
Messages
3,417
Best answers
1
Likes
90
Location
Sweden, Stockholm
#13
Security issue :)

Now you can only start one process of the server. If it is already started you will just get a output saying "Server is already running"
 

Szusi

New Member
Joined
Sep 22, 2010
Messages
7
Best answers
0
Likes
0
#17
just, told me guys, how to do the my log? i dont even know where is the my.log file..
 

JoccE

CopyLeft (ɔ)
Joined
Aug 26, 2007
Messages
3,417
Best answers
1
Likes
90
Location
Sweden, Stockholm
#18
just, told me guys, how to do the my log? i dont even know where is the my.log file..
You need to make a link for it from the server path to the web path

ln /path/to/serverlog /path/to/www

There is probably a better way but as i said i am not a PHP programmer
 

Znote

<?php echo $title; ?>
Staff member
Global Moderator
Premium User
Joined
Feb 14, 2008
Messages
6,367
Best answers
150
Likes
1,060
Location
Norway, Oslo
#20
The code looks OK for Znote AAC 1.5

Would like to implement something like this into the official repo, how does the console monitoring work?
 
Top