140 likes | 336 Views
Networking 2 Project. Android App to control an IRC Bot. Background. What is IRC and what does an IRC Bot do?
E N D
Networking 2 Project Android App to control an IRC Bot
Background • What is IRC and what does an IRC Bot do? • IRC is Internet Relay Chat. It is a place that you can connect to and send messages, and files from all over the world. You have the ability to chat privately and in channels with many people. • IRC Bots are clients that sit in channels and have the ability to manipulate the channels. The Bot itself can control the channel and make it so other people can control the channel. This means it can make it so you can kick and ban people and give them rights.
The Project • What I wanted to do with this app: • Start and Stop a PHP Bot from the app • Change the settings of the bot • Server • Port • Server Password • Channel • Name of the Bot • Run commands on the server • View the settings • Change the server • Run on Wi-Fi and 3G
Research • What I had to find out? • How to execute commands directly from php on a Linux Box. • exec(“/usr/bin/php –f /var/www/bot.php &”) • How to Post to a website with a Android. (Next Slide) • Brush up on Menu’s and HttpGet to get the data.
Posting with Android • String address = BotControl.Server + "/post.php"; //get address • HttpClient client = new DefaultHttpClient(); • HttpPost post = new HttpPost(address); • List<NameValuePair> pairs = new ArrayList<NameValuePair>(); • pairs.add(new BasicNameValuePair("serv", serv.getText().toString())); • pairs.add(new BasicNameValuePair("port", port.getText().toString())); • pairs.add(new BasicNameValuePair("name", name.getText().toString())); • pairs.add(new BasicNameValuePair("nick", nick.getText().toString())); • pairs.add(new BasicNameValuePair("chan", chan.getText().toString())); • pairs.add(new BasicNameValuePair("pass", pass.getText().toString())); • //try catches • post.setEntity(new UrlEncodedFormEntity(pairs)); • //try catches • HttpResponse response = client.execute(post);
How is this done? • The server (Ubuntu 10.10) runs a apache web server with PHP and MYSQL also. • The Bot is a PHP script that gets its settings from the MYSQL database. • The app connects to the server and runs commands to start and stop the Bot, through PHP scripts. • The app posts to the web server to manipulate the settings. • The app gets information from the server by talking to the web server also.
The Bot • The Bot is a PHP script that runs on the server that I have the ability to execute with certain commands. • To execute the bot from command line you would do something similar to this. /usr/bin/php –f /var/www/bot.php & • To kill the bot you would do something like this: $output = shell_exec("ps | grep php | awk '{print $1}'"); if ($output != null) { kill($output); echo "Killed process id:/" $output /""; } else { echo “Bot is not running!"; }
The Bot Continued… • Kill command continued: function kill($PID){ if(is_running($PID)){ exec("kill -KILL$PID"); return true; }else return false; } function is_running($PID){ exec("ps $PID", $ProcessState); return(count($ProcessState) >= 2); }
The App • Settings Page • Has the ability to change the Server, Port, Channel,Name, Nickname, and the password to get into the server. • When you click submit the app posts to a web server to update the database.
The App Continued… • Menu • You have the ability to Edit Settings, View Settings, Start Bot, Stop Bot, Run Command(on the server), and change the servers address. • View Settings • You can view the current settings by hitting the View settings button.
The App Continued… • Command Page • Here you can run any command you want on the Linux server, even shut it down if you want. You will just have to authenticate if you wanted to do that. • Server Address • Here you can change the server address.