Forum
  • Search
  • Member List
  • Calendar
Hello There, Guest! Login Register — Login with Facebook

[IDEA] Start/stop XBMC from web gui
Thank you for your donation

Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Threaded Mode | Linear Mode
Idea: Start/stop XBMC from web gui
9th Apr, 2013, 01:23 AM
Post: #1
Fred Offline
Registered
Posts: 321
Joined: Apr 2013
Reputation: 36
Start/stop XBMC from web gui
I was looking for a way to run bash scripts from my phone or Ipad in a user friendly way. Main reason for this is that I want to be able to start XBMC and pause all downloads in one click, and vice versa.
I wasn't able to find anything that suited my needs so I decided to 'hack' something together. I say 'hack' because my knowledge on doing this in a neat way is limited.
The result for now is a web gui with two buttons:

   

Start XBMC button:
starts XBMC
pauses nzbget downloads, nzb scans and processing
pauses all downloads in transmission
shuts down couchpotato
shuts down sickbeard


Stop XBMC button:
stops XBMC
resumes nzbget downloads, nzb scans and processing
resumes all downloads in transmission
starts couchpotato
starts sickbeard



How did I put this together [guide/tutorial if you want]:

[1]Create bash scripts
Created the bash scripts:
Code:
sudo nano startxbmc.sh

Inserted the following lines:
Code:
#!/bin/bash
sudo /etc/init.d/xbmc start
sudo nzbget -c /usr/local/etc/nzbget/nzbget.conf -P D2
sudo nzbget -c /usr/local/etc/nzbget/nzbget.conf -P O
sudo nzbget -c /usr/local/etc/nzbget/nzbget.conf -P S
sudo transmission-remote --auth=xbian:raspberry --torrent all --stop
sudo /etc/init.d/couchpotato stop
sudo /etc/init.d/sickbeard stop

Made it executable:
Code:
sudo chmod +x startxbmc.sh

Did the same for the stopxbmc.sh script which contains the following:

Code:
#!/bin/bash
sudo /etc/init.d/xbmc stop
sudo /etc/init.d/sickbeard start
sudo /etc/init.d/couchpotato start
sudo nzbget -c /usr/local/etc/nzbget/nzbget.conf -U D2
sudo nzbget -c /usr/local/etc/nzbget/nzbget.conf -U O
sudo nzbget -c /usr/local/etc/nzbget/nzbget.conf -U S
sudo transmission-remote --auth=xbian:raspberry --torrent all --start

[2] Set up PHP webserver
Now we are going to need a webserver with php support to run the bash files from a web gui. I used the following guide for this:

http://www.simonthepiman.com/how_to_setup_a_web_server_with_php_support.php

In the step where the lighttpd.conf is edited you can also change the port if you would like.

[3] Design a web GUI
Now we have to build a basic web page with the buttons by changing index.php. I have set this up very simple with some basic formatting. The php code is below, I haven’t commented it yet sorry for that. It roughly contains 3 parts, the first part contains the php code that is called when a button is pushed. The second part contains the styling for the buttons en the final part is the html code for the web page.

PHP Code:
<?php
    
if (isset($_POST['startbutton']))
    {
        
exec('sudo /path/to/your/scriptfolder/startupscript.sh > /dev/null 2>&1 &');
    }

    if (isset(
$_POST['stopbutton']))
    {
        
exec('sudo /path/to/your/scriptfolder/shutdownscript.sh > /dev/null 2>&1 &');
    }
?>
<html>
<head>
<title>XBMC Control</title>

<style type="text/css">
.button_style1 {
    -moz-box-shadow:inset 0px 1px 0px 0px #97c4fe;
    -webkit-box-shadow:inset 0px 1px 0px 0px #97c4fe;
    box-shadow:inset 0px 1px 0px 0px #97c4fe;
    background-color:#3d94f6;
    -moz-border-radius:6px;
    -webkit-border-radius:6px;
    border-radius:6px;
    border:1px solid #337fed;
    display:inline-block;
    color:#ffffff;
    font-family:arial;
    font-size:8.0em;
    font-weight:bold;
    padding:6px 24px;
    text-decoration:none;
    text-shadow:1px 1px 0px #1570cd;
}.button_style1:hover {
    background-color:#1e62d0;
}.button_style1:active {
    position:relative;
    top:1px;
}
/* This imageless css button was generated by CSSButtonGenerator.com */
</style>

</head>
<body style="background-color:#000000">
<center>
<br>
    <form method="post">
    <p>
        <button name="startbutton" class="button_style1">Start XBMC</button>
    </p>
    </form>
<br>
    <form method="post">
    <p>
        <button name="stopbutton" class="button_style1">Stop XBMC</button>
    </p>
    </form>
</center>
</body>
</html> 

[4] Create nopasswd exceptions for bash scripts
Because there are some sudo commands in our website we want to make some exceptions so they can be executed without the need of a password. For this I implemented the following solution.
I have absolutely no idea how safe or unsafe this method is.

Code:
sudo visudo

Add the following line at the end:

Code:
www-data ALL=NOPASSWD: /path/to/your/scriptfolder/startupscript.sh, path/to/your/scriptfolder/shutdownscript.sh

[5] Push your buttons
Go to the website:

Code:
http://yourraspberrypi-IP

Or if you have changed the port in step 2

Code:
http://yourraspberrypi-IP:portnumber



What’s next:

[1] First of all I would like to know if someone knows there is already something similar to this (I was not able to find it), which is probably better than this. If there is not then:
[2] I would like to know if you think this method is safe and if not, how to implement this better.
[3] I would like to make the web gui better looking but I have close to none experience with this, I had the following things in mind:
- Adjust it automatically to screensize (so the buttons are not to small on a phone and not to big on an Ipad or computerscreen)
- Add some feedback to it (XBMC started successfully etc.)
- Disable the buttons for a minute after they are pressed.

So suggestions and recommendations on this and also on other aspects are more than welcome. I have put this together starting with close to no knowledge of php, html and linux, so there will be enough room for improvement.

Please read rules and do a search before you post! . FAQs . How to post log file? . Looking for answers? Please start here
Find all posts by this user
Quote this message in a reply
« Next Oldest | Next Newest »
Post Reply 


Messages In This Thread
Start/stop XBMC from web gui - Fred - 9th Apr, 2013 01:23 AM
Re: Start/stop XBMC from web gui - f1vefour - 9th Apr, 2013, 12:07 PM
RE: Start/stop XBMC from web gui - Fred - 9th Apr, 2013, 04:57 PM
Re: Start/stop XBMC from web gui - f1vefour - 10th Apr, 2013, 01:25 AM
RE: Start/stop XBMC from web gui - Fred - 10th Apr, 2013, 04:10 AM
Re: Start/stop XBMC from web gui - f1vefour - 10th Apr, 2013, 08:11 AM
RE: Start/stop XBMC from web gui - wuschl - 11th Apr, 2013, 12:21 AM
Re: RE: Start/stop XBMC from web gui - f1vefour - 11th Apr, 2013, 05:23 AM
RE: Start/stop XBMC from web gui - wuschl - 11th Apr, 2013, 10:41 PM

Possibly Related Threads...
Thread: Author Replies Views: Last Post
  read out XBMC play, pause stop status lukeg01 36 106,741 11th Apr, 2014 05:22 AM
Last Post: CurlyMo

  • View a Printable Version
  • Send this Thread to a Friend
  • Subscribe to this thread
Forum Jump:

Current time: 1st Jun, 2025, 04:58 PM Powered By MyBB, © 2002-2025 MyBB Group.