[ZnoteACC] Start server from AAC (Linux only)

Discussion in 'Website Applications' started by JoccE, Jan 14, 2013.

  1. JoccE

    JoccE CopyLeft (ɔ)

    Joined:
    Aug 26, 2007
    Messages:
    3,417
    Likes Received:
    90
    Best Answers:
    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:
    1.  
    2. <?php require_once 'engine/init.php'; include 'layout/overall/header.php';
    3. protect_page();
    4. admin_only($user_data);
    5. // start
    6.  
    7. if(isset($_POST['test'])) {
    8.     if (check_if_process_is_running("theforgottenserver"))
    9.         {
    10.               echo "<h2><b><font color='green'>Server is already running</font></b></h2>";
    11.         } else
    12.         {
    13.               shell_exec('cd /home/server1/ && ./theforgottenserver > my.log 2>&1 &'); //Serverpath
    14.         }
    15. }
    16. if(isset($_POST['kill'])) {
    17.     shell_exec('killall -9 theforgottenserver');
    18. }
    19. if(isset($_POST['safe'])) {
    20.     shell_exec('killall -QUIT theforgottenserver');
    21. }
    22.  
    23.  
    24.  
    25. function check_if_process_is_running($process)
    26. {
    27.     exec("/bin/pidof $process",$response);
    28.     if ($response)
    29.     {
    30.          return true;
    31.     } else
    32.     {
    33.          return false;
    34.     }
    35. }
    36.  
    37. if (check_if_process_is_running("theforgottenserver"))
    38.         {
    39.               echo "<h2><b><font color='green'>Server is running</font></b></h2>";
    40.         } else
    41.         {
    42.               echo "<h3><b><font color='red'>Server is NOT running</font></b></h3>";
    43. }
    44.  
    45. ?>
    46.    
    47. <div id="text">
    48.     This is the beta version of JoccEs Admin panel to start/stop tibia servers<br>
    49.     <b>Functions:</b><br>
    50.     <b>Start:</b> Starts the server using ./theforgottenserver (no Autorestarter) Now with logging enabled.<br>
    51.     <b>Save and Quit:</b> Saves the server the stops it.<br>
    52.     <b>Kill Server:</b> Instantly Stops the server using "killall -9 theforgottenserver"<br>
    53.     <b>Logs:</b> Shows the startup output after you have shut down server (a bit buggy server need to be offline to read it)
    54.     <br>
    55.     <br>
    56. </div>
    57.    
    58. <script type="text/javascript">
    59.         function newPopup(url) {
    60.         popupWindow = window.open(
    61.         url,'popUpWindow','height=700,width=800,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
    62.         }
    63. </script>
    64.    
    65.     <!-- Buttons -->
    66.     <div id="buttons>">
    67.         <form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
    68.         <input type="submit" name="test" value="Start Server">
    69.         </form>
    70.        
    71.         <form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
    72.         <input type="submit" name="safe" value="Save and Quit">
    73.         </form>    
    74.        
    75.         <form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
    76.         <input type="submit" name="kill" value="Kill Server">
    77.         </form>
    78.        
    79.         <!--<form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
    80.         <input type="submit" name="test" value="Test Button do not use">
    81.         </form> -->
    82.        
    83.         <button onclick="newPopup('my.log')">Startup Logs</button>
    84.        
    85.     </div>
    86.    
    87.     <div id="info">
    88.     <br>
    89.         <b>Current Bugs:</b><br>
    90.         --NONE<br>
    91.         <br>
    92.         <b>Future Features:</b><br>
    93.         --Be able to start server with auto restarter.<br>
    94.         --More functions: Examples: Clean map and Save Server. (done just not added)<br>
    95.     </div>
    96.    
    97. <?php
    98. // end
    99.  include 'layout/overall/footer.php'; ?>
    100.  
    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:
    1.             <li>
    2.                 <a href='adminserver.php'>Admin Startup</a>
    3.             </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

    [​IMG]

    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: Jan 23, 2013
    silveralol, Amiroslo and Znote like this.
  2. cbrm

    cbrm Just another mod Staff Member Global Moderator

    Joined:
    Jan 6, 2009
    Messages:
    6,549
    Likes Received:
    852
    Best Answers:
    0
    ​Approved
     
  3. JoccE

    JoccE CopyLeft (ɔ)

    Joined:
    Aug 26, 2007
    Messages:
    3,417
    Likes Received:
    90
    Best Answers:
    1
    @up: Thanks

    Picture added :)
     
  4. Zysen

    Zysen =)

    Joined:
    Sep 18, 2010
    Messages:
    2,270
    Likes Received:
    164
    Best Answers:
    0
    seems nice. I'll test it soon. where did you get the idea? :)
     
  5. JoccE

    JoccE CopyLeft (ɔ)

    Joined:
    Aug 26, 2007
    Messages:
    3,417
    Likes Received:
    90
    Best Answers:
    1
    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.
     
  6. vTune

    vTune KakelmästareN^

    Joined:
    Jun 14, 2012
    Messages:
    3,676
    Likes Received:
    400
    Best Answers:
    0
    This is a really nice feature actually! :) Good job JoccE
     
  7. JoccE

    JoccE CopyLeft (ɔ)

    Joined:
    Aug 26, 2007
    Messages:
    3,417
    Likes Received:
    90
    Best Answers:
    1
    Thanks :)
     
  8. JoccE

    JoccE CopyLeft (ɔ)

    Joined:
    Aug 26, 2007
    Messages:
    3,417
    Likes Received:
    90
    Best Answers:
    1
    If anyone knows how to improve the log feature please send me PM :)
     
  9. JoccE

    JoccE CopyLeft (ɔ)

    Joined:
    Aug 26, 2007
    Messages:
    3,417
    Likes Received:
    90
    Best Answers:
    1
    I need someone with ModernAAC to try out my modern version :p Anyone?
     
  10. TheRealMystic

    TheRealMystic Aros.Online

    Joined:
    Oct 30, 2007
    Messages:
    265
    Likes Received:
    8
    Best Answers:
    0
    I might if I redo my server in linux.. which is highly possible...
     
  11. Diath

    Diath DIATH

    Joined:
    Jun 4, 2010
    Messages:
    1,973
    Likes Received:
    110
    Best Answers:
    0
    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.
     
  12. JoccE

    JoccE CopyLeft (ɔ)

    Joined:
    Aug 26, 2007
    Messages:
    3,417
    Likes Received:
    90
    Best Answers:
    1
    Okey :) Thanks
     
  13. JoccE

    JoccE CopyLeft (ɔ)

    Joined:
    Aug 26, 2007
    Messages:
    3,417
    Likes Received:
    90
    Best Answers:
    1
    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"
     
  14. City

    City Well-Known Member

    Joined:
    Jul 14, 2012
    Messages:
    1,077
    Likes Received:
    34
    Best Answers:
    0
    Would it be possible to convert this script to Windows somehow?
     
  15. JoccE

    JoccE CopyLeft (ɔ)

    Joined:
    Aug 26, 2007
    Messages:
    3,417
    Likes Received:
    90
    Best Answers:
    1
    Probably but now idea on how, and i don't have a windows computer i can try on.
     
  16. zakius

    zakius Enter the Ninja!

    Joined:
    Apr 30, 2009
    Messages:
    2,635
    Likes Received:
    63
    Best Answers:
    0
    this
    If you want to make windows version you can try this method ;d
     
  17. Szusi

    Szusi New Member

    Joined:
    Sep 22, 2010
    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    just, told me guys, how to do the my log? i dont even know where is the my.log file..
     
  18. JoccE

    JoccE CopyLeft (ɔ)

    Joined:
    Aug 26, 2007
    Messages:
    3,417
    Likes Received:
    90
    Best Answers:
    1
    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
     
  19. JoccE

    JoccE CopyLeft (ɔ)

    Joined:
    Aug 26, 2007
    Messages:
    3,417
    Likes Received:
    90
    Best Answers:
    1
    Anyone know if this still works?
     
  20. Znote

    Znote <?php echo $title; ?> Staff Member Global Moderator Premium User

    Joined:
    Feb 14, 2008
    Messages:
    6,364
    Likes Received:
    1,059
    Best Answers:
    149
    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?
     
    danio4don and Amiroslo like this.

Share This Page

Loading...