├── .gitattributes ├── .gitignore ├── README.md ├── admin └── index.php ├── config.php ├── functions.php ├── images ├── Raspberry_Pi_Logo-200x150.png ├── off.png ├── offline.jpg ├── on.png └── siri-small.jpg ├── index.php ├── install ├── database.sql ├── index.php ├── install.php └── pihat ├── main.php ├── scripts ├── pihat └── setup.sh ├── sms.php └── sms ├── smspi.php └── textlocal.php /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | tmp/ 9 | *.tmp 10 | *.bak 11 | *.swp 12 | *~.nib 13 | local.properties 14 | .classpath 15 | .settings/ 16 | .loadpath 17 | 18 | # External tool builders 19 | .externalToolBuilders/ 20 | 21 | # Locally stored "Eclipse launch configurations" 22 | *.launch 23 | 24 | # CDT-specific 25 | .cproject 26 | 27 | # PDT-specific 28 | .buildpath 29 | 30 | 31 | ################# 32 | ## Visual Studio 33 | ################# 34 | 35 | ## Ignore Visual Studio temporary files, build results, and 36 | ## files generated by popular Visual Studio add-ons. 37 | 38 | # User-specific files 39 | *.suo 40 | *.user 41 | *.sln.docstates 42 | 43 | # Build results 44 | 45 | [Dd]ebug/ 46 | [Rr]elease/ 47 | x64/ 48 | build/ 49 | [Bb]in/ 50 | [Oo]bj/ 51 | 52 | # MSTest test Results 53 | [Tt]est[Rr]esult*/ 54 | [Bb]uild[Ll]og.* 55 | 56 | *_i.c 57 | *_p.c 58 | *.ilk 59 | *.meta 60 | *.obj 61 | *.pch 62 | *.pdb 63 | *.pgc 64 | *.pgd 65 | *.rsp 66 | *.sbr 67 | *.tlb 68 | *.tli 69 | *.tlh 70 | *.tmp 71 | *.tmp_proj 72 | *.log 73 | *.vspscc 74 | *.vssscc 75 | .builds 76 | *.pidb 77 | *.log 78 | *.scc 79 | 80 | # Visual C++ cache files 81 | ipch/ 82 | *.aps 83 | *.ncb 84 | *.opensdf 85 | *.sdf 86 | *.cachefile 87 | 88 | # Visual Studio profiler 89 | *.psess 90 | *.vsp 91 | *.vspx 92 | 93 | # Guidance Automation Toolkit 94 | *.gpState 95 | 96 | # ReSharper is a .NET coding add-in 97 | _ReSharper*/ 98 | *.[Rr]e[Ss]harper 99 | 100 | # TeamCity is a build add-in 101 | _TeamCity* 102 | 103 | # DotCover is a Code Coverage Tool 104 | *.dotCover 105 | 106 | # NCrunch 107 | *.ncrunch* 108 | .*crunch*.local.xml 109 | 110 | # Installshield output folder 111 | [Ee]xpress/ 112 | 113 | # DocProject is a documentation generator add-in 114 | DocProject/buildhelp/ 115 | DocProject/Help/*.HxT 116 | DocProject/Help/*.HxC 117 | DocProject/Help/*.hhc 118 | DocProject/Help/*.hhk 119 | DocProject/Help/*.hhp 120 | DocProject/Help/Html2 121 | DocProject/Help/html 122 | 123 | # Click-Once directory 124 | publish/ 125 | 126 | # Publish Web Output 127 | *.Publish.xml 128 | *.pubxml 129 | 130 | # NuGet Packages Directory 131 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 132 | #packages/ 133 | 134 | # Windows Azure Build Output 135 | csx 136 | *.build.csdef 137 | 138 | # Windows Store app package directory 139 | AppPackages/ 140 | 141 | # Others 142 | sql/ 143 | *.Cache 144 | ClientBin/ 145 | [Ss]tyle[Cc]op.* 146 | ~$* 147 | *~ 148 | *.dbmdl 149 | *.[Pp]ublish.xml 150 | *.pfx 151 | *.publishsettings 152 | 153 | # RIA/Silverlight projects 154 | Generated_Code/ 155 | 156 | # Backup & report files from converting an old project file to a newer 157 | # Visual Studio version. Backup files are not needed, because we have git ;-) 158 | _UpgradeReport_Files/ 159 | Backup*/ 160 | UpgradeLog*.XML 161 | UpgradeLog*.htm 162 | 163 | # SQL Server files 164 | App_Data/*.mdf 165 | App_Data/*.ldf 166 | 167 | ############# 168 | ## Windows detritus 169 | ############# 170 | 171 | # Windows image file caches 172 | Thumbs.db 173 | ehthumbs.db 174 | 175 | # Folder config file 176 | Desktop.ini 177 | 178 | # Recycle Bin used on file shares 179 | $RECYCLE.BIN/ 180 | 181 | # Mac crap 182 | .DS_Store 183 | 184 | 185 | ############# 186 | ## Python 187 | ############# 188 | 189 | *.py[co] 190 | 191 | # Packages 192 | *.egg 193 | *.egg-info 194 | dist/ 195 | build/ 196 | eggs/ 197 | parts/ 198 | var/ 199 | sdist/ 200 | develop-eggs/ 201 | .installed.cfg 202 | 203 | # Installer logs 204 | pip-log.txt 205 | 206 | # Unit test / coverage reports 207 | .coverage 208 | .tox 209 | 210 | #Translations 211 | *.mo 212 | 213 | #Mr Developer 214 | .mr.developer.cfg 215 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | RPI control 2 | ------------ 3 | 4 | This version does work now but may be some bugs in the installer. 5 | 6 | 7 | 433Mhz Sender using Pi hat. 8 | 9 | Based on Original work from https://github.com/s7mx1/pihat 10 | 11 | 12 | Parts List 13 | ---------- 14 | 15 | 16 | 17 | [Raspberry pi](http://www.amazon.co.uk/gp/product/B008PT4GGC/ref=as_li_ss_tl?ie=UTF8&camp=1634&creative=19450&creativeASIN=B008PT4GGC&linkCode=as2&tag=raspihel-21) 18 | 19 | [8GB SD Card](http://www.amazon.co.uk/gp/product/B000VUVA62/ref=as_li_ss_tl?ie=UTF8&camp=1634&creative=19450&creativeASIN=B000VUVA62&linkCode=as2&tag=raspihel-21) 20 | 21 | [Power Adaptor](http://www.amazon.co.uk/gp/product/B00AUKR4EU/ref=as_li_ss_tl?ie=UTF8&camp=1634&creative=19450&creativeASIN=B00AUKR4EU&linkCode=as2&tag=raspihel-21) 22 | 23 | [Remote Power Sockets](http://www.amazon.co.uk/gp/product/B003XOXAVG/ref=as_li_ss_tl?ie=UTF8&camp=1634&creative=19450&creativeASIN=B003XOXAVG&linkCode=as2&tag=raspihel-21) 24 | 25 | [433 Transmitter](http://www.amazon.co.uk/gp/product/B00EQ1U5XQ/ref=as_li_ss_tl?ie=UTF8&camp=1634&creative=19450&creativeASIN=B00EQ1U5XQ&linkCode=as2&tag=raspihel-21) 26 | 27 | [Breadboard](http://www.amazon.co.uk/gp/product/B00520JLWG/ref=as_li_ss_tl?ie=UTF8&camp=1634&creative=19450&creativeASIN=B00520JLWG&linkCode=as2&tag=raspihel-21) 28 | 29 | [Dupont cables](http://www.amazon.co.uk/gp/product/B00ATMHU52/ref=as_li_ss_tl?ie=UTF8&camp=1634&creative=19450&creativeASIN=B00ATMHU52&linkCode=as2&tag=raspihel-21) 30 | 31 | 32 | 33 | 34 | 35 | Apache Setup 36 | ------------ 37 | ``` 38 | sudo apt-get install apache2 phpmyadmin php5-imagick php5-gd php-xml-parser php5-intl php5 php5-cli mysql-server mysql-client php5-mysql php5-curl -y 39 | ``` 40 | 41 | Config.php 42 | ---------- 43 | Please ensure you chmod this to 755 or 777 44 | 45 | 46 | SMS Setup 47 | ------------ 48 | 49 | Please point the url forward on your sms provider to the url for your provider 50 | 51 | i.e http://myraspberrypi.com/sms/textlocal.php 52 | 53 | or 54 | 55 | http://myraspberrypi.com/sms/smspiphp 56 | 57 | 58 | Configuring for TextLocal to Post… 59 | 60 | 61 | you need to tell text local where to POST too. Its a simple setup process: 62 | 63 | 1. Login to textlocal dashboard 64 | 2. Select ‘inboxes’ 65 | 3. Select the inbox you wish to use and press ‘settings’ 66 | 4. Find the heading ‘Forward incoming messages to a URL’ 67 | 5. Enter the URL of your /sms/textlocal.php (ensure port forward has been done) 68 | 6. Save! 69 | 7. Edit textlocal.php and where $smskey is put your inbox keyword in and ensure you add a space. 70 | 71 | 72 | Admin 73 | ----- 74 | 75 | You can now navigate to a admin panel which allows you to alter the devices etc. 76 | 77 | just go to /admin/ in the url. 78 | 79 | 80 | To do 81 | --------------- 82 | 1) Bug Hunt! - Ensure any issues you let me know 83 | 84 | 2) Finish Wake on Lan Section 85 | 86 | 3) new ideas - got an idea or want to intergrate a new sms provider email me :) 87 | 88 | For Me 89 | -------------- 90 | Any one kind enough to throw a donation my way towards another raspberry pi would be welcome - txt3rob@Gmail.com 91 | 92 | Any errors or need help email me txt3rob@gmail.com 93 | 94 | -------------------------------------------------------------------------------- /admin/index.php: -------------------------------------------------------------------------------- 1 | 21 | 22 | admin 23 | 24 | 25 | 26 | 27 | 28 | 29 |

Welcome to the RPI-Control Admin Panel

30 |
31 |
32 | 33 |
34 |
'; 35 | } 36 | 37 | function footer2() 38 | { 39 | echo ' 40 |
41 | 42 | 43 | 44 | '; 45 | } 46 | 47 | $step = (isset($_GET['step']) && $_GET['step'] != '') ? $_GET['step'] : ''; 48 | switch($step){ 49 | case '1': 50 | header2(); 51 | step_1(); 52 | footer2(); 53 | break; 54 | case '2': 55 | header2(); 56 | step_2(); 57 | footer2(); 58 | break; 59 | case '3': 60 | header2(); 61 | step_3(); 62 | footer2(); 63 | break; 64 | case '4': 65 | header2(); 66 | step_4(); 67 | footer2(); 68 | break; 69 | case '5': 70 | header2(); 71 | step_5(); 72 | footer2(); 73 | break; 74 | case '6': 75 | header2(); 76 | step_6(); 77 | footer2(); 78 | break; 79 | case '7': 80 | header2(); 81 | step_7(); 82 | footer2(); 83 | break; 84 | default: 85 | header2(); 86 | step_1(); 87 | footer2(); 88 | } 89 | ?> 90 | 91 | 95 |
96 | Add DevicesRemove Devices
97 | Add UsersRemove Users
98 | Add WolRemove WOL
99 |
100 | Main Page 101 |
102 | 106 | 111 | 112 | 124 |
125 | Device Name:
126 | Brand: 127 | 131 |
132 | Remote ID:
133 | Channel: 134 | 143 | Back 144 |
145 | "; 154 | } else { 155 | include ($configfile); 156 | include ($functionsfile); 157 | add_device ($devicename,$devicebrand,$deviceremoteid,$devicechannel); 158 | } 159 | } 160 | } 161 | 162 | function step_3(){ 163 | GLOBAL $configfile; 164 | GLOBAL $functionsfile; 165 | include ($configfile); 166 | include ($functionsfile); 167 | ?> 168 | 169 |

Remove Device

170 |
171 | 183 |
184 | 192 |
back 193 |
194 | 207 | 219 |

Allow Control

220 |
221 | Name:
222 | Mobile Number:
223 | Back
224 |
225 | 226 | "; 237 | } else { 238 | GLOBAL $configfile; 239 | include (''.$configfile.''); 240 | include (''.$functionsfile.''); 241 | adduser ($name,$number); 242 | } 243 | } 244 | } 245 | 246 | function step_5(){ 247 | GLOBAL $configfile; 248 | GLOBAL $functionsfile; 249 | include ($configfile); 250 | include ($functionsfile); 251 | ?> 252 | 253 |

Remove User

254 |
255 | 267 |
268 | 276 |
back 277 |
278 | 294 | 306 |

Wake On LAN

307 |
308 | Name:
309 | MAC: ?
310 | Back 311 |
312 | "; 320 | } else { 321 | GLOBAL $configfile; 322 | include (''.$configfile.''); 323 | GLOBAL $functionsfile; 324 | include (''.$functionsfile.''); 325 | addmac ($name,$mac); 326 | } 327 | } 328 | } 329 | function step_7(){ 330 | GLOBAL $configfile; 331 | GLOBAL $functionsfile; 332 | include ($configfile); 333 | include ($functionsfile); 334 | ?> 335 | 336 |

Remove Wake on Lan Device

337 |
338 | 350 | 351 | 359 | back 360 |
361 | 370 | -------------------------------------------------------------------------------- /config.php: -------------------------------------------------------------------------------- 1 | getMessage(); 24 | } 25 | ?> -------------------------------------------------------------------------------- /functions.php: -------------------------------------------------------------------------------- 1 | prepare("SELECT * FROM `devices`"); 22 | $devices->execute(); 23 | 24 | //List Users 25 | $users = $dbh->prepare("SELECT * FROM `users`"); 26 | $users->execute(); 27 | 28 | //List wol 29 | $wollist = $dbh->prepare("SELECT * FROM `wol`"); 30 | $wollist->execute(); 31 | 32 | function wollistings () 33 | { 34 | GLOBAL $dbh; 35 | echo '
'; 36 | //List wol 37 | $wollist = $dbh->prepare("SELECT * FROM `wol`"); 38 | $wollist->execute(); 39 | $wolcount = $wollist->rowCount(); 40 | if ($wolcount < 1) { 41 | // No devices 42 | } else { 43 | foreach ($wollist as $wol ){ 44 | 45 | echo ''.$wol['computer'].' '; 46 | 47 | } 48 | } 49 | echo '
'; 50 | } 51 | function updatestate ($dev,$state) 52 | { 53 | // update database with state 54 | GLOBAL $dbh; 55 | $updatestate = $dbh->prepare("UPDATE `devices` SET `state` = :state WHERE `name` = :name"); 56 | $updatestate ->bindParam(':name', $dev); 57 | $updatestate ->bindParam(':state', $state); 58 | $updatestate->execute(); 59 | } 60 | 61 | function commandit ($brand,$remote,$channel,$state) 62 | { 63 | // execute command 64 | passthru ('sudo pihat --brand='.$brand.' --repeats=15 --id='.$remote.' --channel='.$channel.' --state='.$state.''); 65 | } 66 | 67 | function insertsms ($user,$message) 68 | { 69 | GLOBAL $dbh; 70 | $insertsms = $dbh->prepare ("INSERT INTO smshistory (user,command) VALUES (:user,:message)"); 71 | $insertsms->bindParam(':user', $user); 72 | $insertsms->bindParam(':message', $message); 73 | $insertsms->execute(); 74 | } 75 | 76 | function updatehistory ($command,$user) 77 | { 78 | GLOBAL $dbh; 79 | $updatehistory = $dbh->prepare("UPDATE `smshistory` SET `completed` = 1 WHERE `command` = :command AND `user` = :user "); 80 | $updatehistory->bindParam(':command', $command); 81 | $updatehistory->bindParam(':user', $user); 82 | $updatehistory->execute(); 83 | } 84 | 85 | function wol ($computer) 86 | { 87 | GLOBAL $dbh; 88 | $wol = $dbh->prepare("SELECT * FROM `wol` WHERE computer = :computer"); 89 | $wol->bindParam(':computer', $computer); 90 | $wol->execute(); 91 | $count = $wol->rowCount(); 92 | if ($count == "0") { 93 | echo "No Computer with that name found"; 94 | exit(); 95 | } 96 | $wol2 = $wol->fetch(PDO::FETCH_ASSOC); 97 | $mac = $wol2['mac']; 98 | passthru ('wakeonlan '.$mac.''); 99 | echo "Wake on Lan Command Sent"; 100 | } 101 | 102 | function add_device ($devicename,$devicebrand,$deviceremoteid,$devicechannel) { 103 | GLOBAL $dbh; 104 | include('config.php'); 105 | $checkdev = $dbh->prepare("SELECT * FROM `devices` WHERE (`channel` = :channel OR `name` = :name)"); 106 | $checkdev->bindParam(':channel', $devicechannel); 107 | $checkdev->bindParam(':name', $devicename); 108 | $checkdev->execute(); 109 | $count = $checkdev->rowCount(); 110 | 111 | if ($count > 0) { 112 | echo "Device with the same name or channel number already exists"; 113 | } else { 114 | $insertdev = $dbh->prepare("INSERT INTO `devices` (`name`, `brand`, `remoteid`, `channel`, `state`) VALUES (:name, :brand, :remote, :channel, 0)"); 115 | $insertdev->bindParam(':name', $devicename); 116 | $insertdev->bindParam(':brand', $devicebrand); 117 | $insertdev->bindParam(':remote', $deviceremoteid); 118 | $insertdev->bindParam(':channel', $devicechannel); 119 | $insertdev->execute(); 120 | echo "
Device Added to Database
"; 121 | } 122 | } 123 | 124 | function addmac ($name,$mac) { 125 | GLOBAL $dbh; 126 | $checkmac = $dbh->prepare("SELECT * FROM `wol` WHERE (`computer` = :computer OR `mac` = :mac)"); 127 | $checkmac->bindParam(':computer', $name); 128 | $checkmac->bindParam(':mac', $mac); 129 | $checkmac->execute(); 130 | $countmac = $checkmac->rowCount(); 131 | 132 | if ($countmac > 0) { 133 | echo "Computer name or mac already in database"; 134 | } else { 135 | 136 | $insertmac= $dbh->prepare("INSERT INTO `wol` (`computer`, `mac`) VALUES (:computer, :mac)"); 137 | $insertmac->bindParam(':computer', $name); 138 | $insertmac->bindParam(':mac', $mac); 139 | $insertmac->execute(); 140 | echo "
WOL Added to Database
"; 141 | } 142 | } 143 | function adduser ($name,$number) { 144 | GLOBAL $dbh; 145 | $checkuser = $dbh->prepare("SELECT * FROM `users` WHERE (`number` = :number OR `name` = :name)"); 146 | $checkuser->bindParam(':name', $name); 147 | $checkuser->bindParam(':number', $number); 148 | $checkuser->execute(); 149 | $countuser = $checkuser->rowCount(); 150 | 151 | if ($countuser > "0") { 152 | echo "User or Number already in database"; 153 | } else { 154 | $insertuser= $dbh->prepare("INSERT INTO `users` (`name`, `number`) VALUES (:name, :number)"); 155 | $insertuser->bindParam(':name', $name); 156 | $insertuser->bindParam(':number', $number); 157 | $insertuser->execute(); 158 | echo "
User Added to Database
"; 159 | } 160 | } 161 | 162 | function uptime () 163 | { 164 | $data = shell_exec('uptime'); 165 | $uptime = explode(' up ', $data); 166 | $uptime = explode(',', $uptime[1]); 167 | $uptime = $uptime[0]; 168 | 169 | echo ('Current server uptime: '.$uptime.' 170 | '); 171 | } 172 | 173 | function removeuser ($name) { 174 | GLOBAL $dbh; 175 | GLOBAL $configfile; 176 | include($configfile); 177 | $remuser = $dbh->prepare("DELETE FROM `users` WHERE `name` = :name"); 178 | $remuser->bindParam(':name', $name); 179 | $remuser->execute(); 180 | echo "User Removed"; 181 | } 182 | 183 | function removewol ($comp) { 184 | GLOBAL $dbh; 185 | GLOBAL $configfile; 186 | include($configfile); 187 | $remwol = $dbh->prepare("DELETE FROM `wol` WHERE `computer` = :computer "); 188 | $remwol->bindParam(':computer', $comp); 189 | $remwol->execute(); 190 | echo "Wol Removed"; 191 | } 192 | 193 | function removedevice ($device) { 194 | GLOBAL $dbh; 195 | GLOBAL $configfile; 196 | include($configfile); 197 | $remdev = $dbh->prepare("DELETE FROM `devices` WHERE `name` = :name "); 198 | $remdev->bindParam(':name', $device); 199 | $remdev->execute(); 200 | echo "".$device." has been removed."; 201 | } 202 | 203 | function refreshpage ($url) { 204 | header('Location: '.$url.''); 205 | } 206 | 207 | function allon() { 208 | GLOBAL $devices; 209 | 210 | foreach ($devices as $device){ 211 | $dev = $device['name']; 212 | $brand = $device['brand']; 213 | $remote = $device['remoteid']; 214 | $channel = $device['channel']; 215 | $state = "1"; 216 | 217 | // execute command and update the state in DB 218 | commandit ($brand,$remote,$channel,$state); 219 | updatestate ($dev,$state); 220 | } 221 | } 222 | 223 | function alloff() { 224 | GLOBAL $devices; 225 | 226 | foreach ($devices as $device){ 227 | $dev = $device['name']; 228 | $brand = $device['brand']; 229 | $remote = $device['remoteid']; 230 | $channel = $device['channel']; 231 | $state = "0"; 232 | 233 | // execute command and update the state in DB 234 | commandit ($brand,$remote,$channel,$state); 235 | updatestate ($dev,$state); 236 | } 237 | } 238 | 239 | ?> -------------------------------------------------------------------------------- /images/Raspberry_Pi_Logo-200x150.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/random-robbie/RPI-Control/5e7130d5939e83957614e25e9cca8d59e8b3d9c0/images/Raspberry_Pi_Logo-200x150.png -------------------------------------------------------------------------------- /images/off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/random-robbie/RPI-Control/5e7130d5939e83957614e25e9cca8d59e8b3d9c0/images/off.png -------------------------------------------------------------------------------- /images/offline.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/random-robbie/RPI-Control/5e7130d5939e83957614e25e9cca8d59e8b3d9c0/images/offline.jpg -------------------------------------------------------------------------------- /images/on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/random-robbie/RPI-Control/5e7130d5939e83957614e25e9cca8d59e8b3d9c0/images/on.png -------------------------------------------------------------------------------- /images/siri-small.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/random-robbie/RPI-Control/5e7130d5939e83957614e25e9cca8d59e8b3d9c0/images/siri-small.jpg -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | prepare("SELECT * FROM `devices` WHERE `name` = :name"); 47 | $devlookup->bindParam(':name', $dev); 48 | $devlookup->execute(); 49 | $count = $devlookup->rowCount(); 50 | if ($count == "1"){ 51 | $devid = $devlookup->fetch(PDO::FETCH_ASSOC); 52 | $brand = $devid['brand']; 53 | $remote = $devid['remoteid']; 54 | $channel = $devid['channel']; 55 | 56 | 57 | 58 | // execute command and update the state in DB 59 | commandit ($brand,$remote,$channel,$state); 60 | updatestate ($dev,$state); 61 | } else { 62 | wol ($dev); 63 | } 64 | } 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | ?> 76 | -------------------------------------------------------------------------------- /install/database.sql: -------------------------------------------------------------------------------- 1 | -- phpMyAdmin SQL Dump 2 | -- version 3.4.11.1deb2 3 | -- http://www.phpmyadmin.net 4 | -- 5 | -- Host: localhost 6 | -- Generation Time: Dec 19, 2013 at 11:38 AM 7 | -- Server version: 5.5.31 8 | -- PHP Version: 5.4.4-14+deb7u4 9 | 10 | SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; 11 | SET time_zone = "+00:00"; 12 | 13 | 14 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; 15 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; 16 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; 17 | /*!40101 SET NAMES utf8 */; 18 | 19 | -- 20 | -- Database: `rpicontrol` 21 | -- 22 | 23 | -- -------------------------------------------------------- 24 | 25 | -- 26 | -- Table structure for table `devices` 27 | -- 28 | 29 | CREATE TABLE IF NOT EXISTS `devices` ( 30 | `name` varchar(11) NOT NULL, 31 | `brand` varchar(2) NOT NULL, 32 | `remoteid` varchar(20) NOT NULL, 33 | `channel` varchar(2) NOT NULL, 34 | `state` varchar(2) NOT NULL DEFAULT '0' 35 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 36 | 37 | -- -------------------------------------------------------- 38 | 39 | -- 40 | -- Table structure for table `smshistory` 41 | -- 42 | 43 | CREATE TABLE IF NOT EXISTS `smshistory` ( 44 | `user` varchar(25) NOT NULL, 45 | `command` varchar(160) NOT NULL, 46 | `completed` varchar(1) NOT NULL DEFAULT '0', 47 | `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP 48 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 49 | 50 | -- -------------------------------------------------------- 51 | 52 | 53 | -- 54 | -- Table structure for table `users` 55 | -- 56 | 57 | CREATE TABLE IF NOT EXISTS `users` ( 58 | `name` varchar(25) NOT NULL, 59 | `number` varchar(25) NOT NULL 60 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 61 | 62 | -- 63 | -- Table structure for table `wol` 64 | -- 65 | 66 | CREATE TABLE IF NOT EXISTS `wol` ( 67 | `computer` varchar(50) NOT NULL, 68 | `mac` varchar(50) NOT NULL 69 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 70 | -------------------------------------------------------------------------------- /install/index.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Installation Script 5 | 6 | 7 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /install/install.php: -------------------------------------------------------------------------------- 1 | 21 | 22 | Install 23 | 24 | 25 | 26 | 27 | 28 | 29 |

Welcome to the RPI-Control Installer

30 |
31 |
'; 32 | } 33 | 34 | function footer2() 35 | { 36 | echo ' 37 |
38 |
39 | 40 | '; 41 | } 42 | 43 | $step = (isset($_GET['step']) && $_GET['step'] != '') ? $_GET['step'] : ''; 44 | switch($step){ 45 | case '1': 46 | header2(); 47 | step_1(); 48 | footer2(); 49 | break; 50 | case '2': 51 | header2(); 52 | step_2(); 53 | footer2(); 54 | break; 55 | case '3': 56 | header2(); 57 | step_3(); 58 | footer2(); 59 | break; 60 | case '4': 61 | header2(); 62 | step_4(); 63 | footer2(); 64 | break; 65 | case '5': 66 | header2(); 67 | step_5(); 68 | footer2(); 69 | break; 70 | case '6': 71 | header2(); 72 | step_6(); 73 | footer2(); 74 | break; 75 | case '7': 76 | header2(); 77 | step_7(); 78 | footer2(); 79 | break; 80 | case '8': 81 | header2(); 82 | echo (' 83 |
Please SSH in to your pi and run the following script '.$current.'scripts/setup.sh

84 | This is required to finish the installation. 85 |
86 | Once complete please remove this folder 87 | 88 |
'); 89 | footer2(); 90 | break; 91 | default: 92 | header2(); 93 | step_1(); 94 | footer2(); 95 | } 96 | ?> 97 | 98 | 108 |

Our LICENSE will go here.

109 |
110 |

111 | I agree to the license 112 | 113 |

114 | 115 |
116 | '; 129 | } 130 | if (!extension_loaded('mysql')) { 131 | $pre_error .= 'MySQL extension needs to be loaded for our site to work!
'; 132 | } 133 | if (!extension_loaded('PDO')) { 134 | $pre_error .= 'PDO extension needs to be loaded for our site to work!
'; 135 | } 136 | if (!is_writable($configfile)) { 137 | $pre_error .= 'config.php needs to be writeable for RPI-Control to be installed!'; 138 | } 139 | ?> 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 |
PHP Version:5.0+= '5.0') ? 'Ok' : 'Not Ok'; ?>
MySQL:On
Mysql PDO:On
config.phpWritable
166 |
167 | 168 | 169 |
170 | "; 181 | } else { 182 | $connection = mysql_connect($database_host, $database_username, $database_password); 183 | if (!$connection) { 184 | die('Could not connect: ' . mysql_error()); 185 | } 186 | 187 | $sql = 'CREATE DATABASE '.$database_name.''; 188 | if (mysql_query($sql, $connection)) { 189 | echo "Database ".$database_name." created successfully\n"; 190 | } else { 191 | echo 'Error creating database: ' . mysql_error() . "\n"; 192 | } 193 | $filename = "database.sql"; 194 | // Select database 195 | mysql_select_db($database_name) or die('Error selecting MySQL database: ' . mysql_error()); 196 | 197 | // Temporary variable, used to store current query 198 | $templine = ''; 199 | // Read in entire file 200 | $lines = file($filename); 201 | // Loop through each line 202 | foreach ($lines as $line) 203 | { 204 | // Skip it if it's a comment 205 | if (substr($line, 0, 2) == '--' || $line == '') 206 | continue; 207 | 208 | // Add this line to the current segment 209 | $templine .= $line; 210 | // If it has a semicolon at the end, it's the end of the query 211 | if (substr(trim($line), -1, 1) == ';') 212 | { 213 | // Perform the query 214 | mysql_query($templine) or print('Error performing query \'' . $templine . '\': ' . mysql_error() . '

'); 215 | // Reset temp variable to empty 216 | $templine = ''; 217 | } 218 | } 219 | echo "
Tables imported successfully
Next Step If no Errors"; 220 | 221 | GLOBAL $configfile; 222 | $handle = fopen($configfile, 'w') or die('Cannot open file: '.$configfile); 223 | $data = 'getMessage(); 246 | } 247 | ?>'; 248 | fwrite($handle, $data); 249 | } 250 | header ('Location install.php?step=4'); 251 | } 252 | ?> 264 |
265 |

266 | 267 | 268 |

269 |

270 | 271 | 272 |

273 |

274 | 275 | 276 |

277 |

278 | 279 | 280 |

281 |
282 |

283 | 284 |

285 |
286 |
287 | 293 | 294 | 306 |
307 | Device Name:
308 | Brand: 309 | 313 |
314 | Remote ID:
315 | Channel: 316 | 325 |
326 |
327 | "; 336 | } else { 337 | include ($configfile); 338 | include ($functionsfile); 339 | add_device ($devicename,$devicebrand,$deviceremoteid,$devicechannel); 340 | } 341 | } 342 | } 343 | function step_5(){ 344 | // Removed as no longer required. 345 | header ('location: install.php?step=6'); 346 | 347 | } 348 | function step_6(){ 349 | 350 | ?> 351 | 363 |

Allow Control

364 |
365 | Name:
366 | Mobile Number:
367 |
368 |
369 | "; 380 | } else { 381 | GLOBAL $configfile; 382 | include (''.$configfile.''); 383 | include (''.$functionsfile.''); 384 | adduser ($name,$number); 385 | } 386 | } 387 | } 388 | function step_7(){ 389 | GLOBAL $configfile; 390 | include (''.$configfile.''); 391 | GLOBAL $dbh; 392 | GLOBAL $functionsfile; 393 | ?> 394 | 406 |

Wake On LAN

407 |
408 | Name:
409 | MAC: ?
410 | 411 |
412 | "; 420 | } else { 421 | GLOBAL $configfile; 422 | include (''.$configfile.''); 423 | GLOBAL $functionsfile; 424 | include (''.$functionsfile.''); 425 | addmac ($name,$mac); 426 | } 427 | } 428 | } 429 | ?> 430 | -------------------------------------------------------------------------------- /install/pihat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/random-robbie/RPI-Control/5e7130d5939e83957614e25e9cca8d59e8b3d9c0/install/pihat -------------------------------------------------------------------------------- /main.php: -------------------------------------------------------------------------------- 1 | 13 | 14 | 15 | Home 16 | 17 | 18 | 19 | 20 | 29 | 30 | 31 | 32 |
33 |
34 |

RPi Control

35 |
36 |

37 |
Remote Switch Using The Raspberry Pi
38 |

39 |
40 |
41 | 42 |
43 |
44 |
45 |
46 | '; 50 | if ($device['state'] == "1") 51 | { 52 | echo ''; 53 | } else { 54 | echo ''; 55 | } 56 | echo '
'; 57 | } 58 | ?> 59 |
60 |
61 | 62 | 63 |
64 |
65 |

66 | 68 |

69 |
70 |
71 |
72 |
73 |

Action performed

74 |
75 |
76 |

The Action has been performed

77 | Okay 78 |
79 |
80 | 81 |
82 | 83 |
84 |

Stats

85 |
86 | 87 |
88 |
 89 | Uptime: 
 90 | 
 91 | 
 92 | System Information:
 93 | 
 94 | 
 95 | 
 96 | Memory Usage (MB): 
 97 | 
 98 | 
 99 | 
100 | Disk Usage: 
101 | 
102 | 
103 | 
104 | CPU Information: 
105 | 
106 | 
107 |
108 |

Back

109 | 110 |
111 | 112 |
113 |

115 |

116 |
117 |
118 | 119 | 120 | 121 | 122 |
123 | 124 | 125 |
126 |

Wake On Lan

127 |
128 | 129 |
130 |

132 |
133 | Back

134 |

135 |
136 |
137 |

139 |

140 |
141 | 142 | 143 | 144 | -------------------------------------------------------------------------------- /scripts/pihat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/random-robbie/RPI-Control/5e7130d5939e83957614e25e9cca8d59e8b3d9c0/scripts/pihat -------------------------------------------------------------------------------- /scripts/setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | sudo apt-get update 3 | sudo apt-get upgrade -y 4 | sudo apt-get install wakeonlan -y 5 | sudo echo "www-data ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers 6 | sudo cp pihat /usr/bin/pihat 7 | sudo chmod 777 /usr/bin/pihat 8 | echo "setup complete" 9 | -------------------------------------------------------------------------------- /sms.php: -------------------------------------------------------------------------------- 1 | prepare("SELECT * FROM `users` WHERE `number` = :number"); 18 | $permission->bindParam(':number', $number); 19 | $permission->execute(); 20 | $permish = $permission->fetch(PDO::FETCH_ASSOC); 21 | $user = $permish['name']; 22 | $count = $permission->rowCount(); 23 | if ($count == "0") 24 | { 25 | echo "Permission Denied"; 26 | exit (); 27 | } 28 | 29 | // Record who sent the message 30 | insertsms ($user,$message); 31 | 32 | 33 | // Seperate Message 34 | $comm = explode( ' ', $message ); 35 | $dev=$comm[0]; 36 | $onoroff=$comm[1]; 37 | 38 | 39 | 40 | 41 | 42 | //Is it a wake on lan request? 43 | if ($dev == "wol") 44 | { 45 | wol ($onoroff); 46 | updatehistory ($message,$user); 47 | exit(); 48 | } 49 | 50 | $on = strtoupper($onoroff); 51 | // Set on or off state 52 | if ($on == "ON") { 53 | $state = "1"; 54 | } else { 55 | $state = "0"; 56 | } 57 | 58 | 59 | 60 | 61 | 62 | // Find Device in DB 63 | $devlookup = $dbh->prepare("SELECT * FROM `devices` WHERE `name` = :name"); 64 | $devlookup->bindParam(':name', $dev); 65 | $devlookup->execute(); 66 | $count = $devlookup->rowCount(); 67 | if ($count == "0") { 68 | echo "No Device with ".$dev." has been found in the Database"; 69 | exit(); 70 | } 71 | $devlookup2 = $devlookup->fetch(PDO::FETCH_ASSOC); 72 | $brand = $devlookup2['brand']; 73 | $remote = $devlookup2['remoteid']; 74 | $channel = $devlookup2['channel']; 75 | 76 | 77 | 78 | 79 | // execute command 80 | commandit ($brand,$remote,$channel,$state); 81 | // Update the Web Interface 82 | updatestate ($dev,$state); 83 | //Update SMS History 84 | updatehistory ($message,$user); 85 | ?> 86 | -------------------------------------------------------------------------------- /sms/smspi.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /sms/textlocal.php: -------------------------------------------------------------------------------- 1 | 34 | --------------------------------------------------------------------------------