These steps are based on http://triplescomputers.com/blog/uncategorized/solution-switch-windows-10-from-raidide-to-ahci-operation/
If you tried installing before this tutorial, it might be that your installation ended up in an unbootable state. You can read the following article to fix that: How to fix “Failed to start MokManager” / “import_mok_state() failed” after failed Ubuntu Installation
]]>Failed to open \EFI\BOOT\mmx64.efi – Not Found
Failed to load image \EFI\BOOT\mmx64.efi: Not Found
Failed to start MokManager: Not Found
Something has gone seriously wrong: import_mok_state() failed
The reason that this error occurs is because the installation set a few variables in the UEFI variable store that it should initialize the MOK manager (the MOK manager is used to enroll keys in UEFI). It should initialize the MOK manager, but only when the installation succeeded.
The way I got this fixed was eventually pretty easy, but it took me some time to find out:
You can use this tutorial to understand how to sideload apps:
http://www.xbmchub.com/blog/2013/06/02/how-to-install-xbmc-to-the-ouya-gaming-console/
Notice: I made this special download because the version on m.spotify.com is outdated, and looks horrible on your OUYA.
Here are some previews of Spotify running on my OUYA:
Have fun!Update: The login screen is in portrait mode, once you are logged in, you will have landscape.
]]>It combines the bandwidth statistics of the given servers, and creates a awesome graph for it.
Put the following code below your host-tree:
- bandwidth.graph_title Total Bandwidth of all servers in MB/s
- bandwidth.totalup.sum [server1]:if_eth0.up [server2]:if_eth0.up [server3]:if_eth0.up [server4]:if_eth0.up
- bandwidth.totalup.label Total up bandwidth usage of all servers
- bandwidth.totaldown.sum [server1]:if_eth0.down [server2]:if_eth0.down [server3]:if_eth0.down [server4]:if_eth0.down
- bandwidth.totaldown.label Total down bandwidth usage of all servers
Replace [server1] – [server4] with your server names, use the server names that you used in your host tree.
Basically it generate 2 lines, upload and download, and uses the “sum” function to get the total of all servers combined,
]]>First I added the following HTML/JavaScript before the body tag:
- <div id="adsense_mobile_top" style="display:none;">
- <script type="text/javascript"><!--
- window.googleAfmcRequest = {
- client: 'xxx',
- format: 'xxx',
- output: 'html',
- slotname: 'xxx',
- };
- //--></script>
- <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_afmc_ads.js"></script>
- </div>
- <div id="adsense_top" style="display:none;">
- <script type="text/javascript"><!--
- google_ad_client = "xxx";/
- google_ad_slot = "xxx";
- google_ad_width = xxx;
- google_ad_height = xxx;
- //-->
- </script>
- <script type="text/javascript"
- src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
- </script>
- </div>
Make sure you fill in your own Adsense data.
Then I added the following HTML code to the place where I wanted the ad to be:
- <div id="google_ads_top">
- <div align="center">
- </div>
- </div>
Then I added the following javascript before the body tag:
- <script type="text/javascript">
- function loadAd(){
- var mobile = (/iphone|ipad|ipod|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));
- var ads_top = $("#adsense_top").find("iframe");
- if (mobile || ((/android/i.test(navigator.userAgent.toLowerCase())) && (/mobile/i.test(navigator.userAgent.toLowerCase())))) {
- ads_top = $("#adsense_mobile_top").find("iframe");
- }
- else
- {
- ads_top.css('position', 'static');
- }
- $(ads_top).appendTo("#google_ads_top div");
- $("#adsense_top").remove();
- $('div').live('pagehide',function(event, ui){
- $(ads_top).appendTo("#google_ads_top div");
- });
- }
- $('div[data-role=page]').live('pageshow', loadAd);
- </script>
And there you have it, a website that gets a new ad on every pageview, and selects the ad on the kind of device you have.
There are multiple ways to base ads on the kind of device, but I needed a JavaScript solution because I just heavy cache on the pages. PHP selecting won’t work.
]]>I tried for a couple of hours until I was tired of “thinking the JS way” and went for the easy(and ugly) solution called iframes. I added the following code and it worked perfectly:
- <iframe scrolling="auto" frameborder="0" style="width:100%; min-height: 300px;" src="/ad.html" sandbox="allow-same-origin allow-forms allow-scripts" allowtransparency="true">
In the ad.html you add the advertisement javascript.
iUI fails with advertisements because it doesn’t support document.write, and all ad platforms I know use it. document.write will only work on the homepage, dynamically loaded pages will fail with document.write and will become a white page with only the ad.
]]>http://alpha.jeroen.pro/static/background.jpg
http://beta.jeroen.pro/static/background.jpg
Code:
- <?php
- function select_server($servers, $default)
- {
- $server = $default;
- $gotServer = false;
- while($gotServer == false && count($servers) > 0)
- {
- $randomkey = array_rand($servers);
- $server = $servers[$randomkey];
- $port = 80;
- $status = apc_fetch("server_test_".$server, &$fetchstatus);
- if($fetchstatus == false)
- {
- if($fp=@fsockopen($server,$port,$ERROR_NO,$ERROR_STR,1))
- {
- fclose($fp);
- $status = "online";
- }
- else
- {
- $status = "offline";
- }
- apc_store("server_test_".$server, $status, 10);
- }
- if($status != "offline")
- {
- $gotServer = true;
- $server = $servers[$randomkey];
- }
- else
- {
- unset($servers[$randomkey]);
- unset($status);
- unset($fetchstatus);
- $server = $default;
- }
- }
- return $server;
- }
- ?>
Remember: the code uses APC to store the server status for 10 seconds, you could remove the APC part, but that would cause extra load on the servers.
The code loops through the server list(which was made random), and tries every server until it found one that is online. If none is online, it’s going to the default server.
Usage:
]]>
- <?php
- $servers = array('alpha.jeroen.pro', 'beta.jeroen.pro');
- $default = "jeroen.pro";
- $server = select_server($servers, $default);
- echo '<img src="http://'.$server.'/static/background.jpg" />';
- ?>
In this case it was about OpenVPN, the status of the server, per client, more specifically. After doing some searching on the internet I figured that OpenVPN isn’t used much, or that only pro’s use it and they write their own code anyway.
The only thing I found was a very basic(and non-working) PHP page from 2005, and a simple PHP script(also from 2005) that parses the logfile and shows the current status. I decided to base my script on that.
Before we start coding, make sure your OpenVPN server configuration contains: “status openvpn-status.log”. Now let’s start coding. First I made a table in the database.
DB Scheme:
- CREATE TABLE IF NOT EXISTS `stats` (
- `CommonName` text NOT NULL,
- `RealAddress` text NOT NULL,
- `BytesReceived` text NOT NULL,
- `BytesSent` text NOT NULL,
- `Since` text NOT NULL,
- `VirtualAddress` text NOT NULL,
- `LastRef` text NOT NULL,
- `updated` bigint(20) NOT NULL
- ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Sorry for my dirty type choosing, this script was made in a hurry.
Then I made a cron that saves the stats:
Cron.php
- <?
- mysql_connect('localhost', 'openvpn', 'openvpn');
- mysql_select_db('openvpn');
- function parseLog ($log) {
- $handle = fopen($log, "r");
- $uid = 0;
- while (!feof($handle)) {
- $buffer = fgets($handle, 4096);
- unset($match);
- if (ereg("^Updated,(.+)", $buffer, $match)) {
- $status['updated'] = $match[1];
- }
- if (preg_match("/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)$/", $buffer, $match)) {
- if ($match[1] <> "Common Name") {
- $cn = $match[1];
- $userlookup[$match[2]] = $uid;
- $status['users'][$uid]['CommonName'] = $match[1];
- $status['users'][$uid]['RealAddress'] = $match[2];
- $status['users'][$uid]['BytesReceived'] = $match[3];
- $status['users'][$uid]['BytesSent'] = $match[4];
- $status['users'][$uid]['Since'] = $match[5];
- $uid++;
- }
- }
- if (preg_match("/^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)$/", $buffer, $match)) {
- if ($match[1] <> "Virtual Address") {
- $address = $match[3];
- $uid = $userlookup[$address];
- $status['users'][$uid]['VirtualAddress'] = $match[1];
- $status['users'][$uid]['LastRef'] = $match[4];
- }
- }
- }
- fclose($handle);
- return($status);
- }
- function sizeformat($bytesize){
- $i=0;
- while(abs($bytesize) >= 1024){
- $bytesize=$bytesize/1024;
- $i++;
- if($i==4) break;
- }
- $units = array("Bytes","KB","MB","GB","TB");
- $newsize=round($bytesize,2);
- return("$newsize $units[$i]");
- }
- $stats = parseLog("/etc/openvpn/openvpn-status.log");
- foreach($stats['users'] as $user)
- {
- if($user['CommonName'] != "UNDEF")
- {
- $result = mysql_query("UPDATE stats SET updated = '".time()."', VirtualAddress = '".$user['VirtualAddress']."', BytesSent='".$user['BytesSent']."', BytesReceived='".$user['BytesReceived']."', LastRef='".$user['LastRef']."' WHERE CommonName='".$user['CommonName']."' AND Since='".$user['Since']."'") or die(mysql_error());
- echo mysql_affected_rows();
- if (mysql_affected_rows()==0) {
- $result = mysql_query("insert into stats (CommonName, RealAddress, BytesReceived, BytesSent, Since, VirtualAddress, LastRef) values ('".$user['CommonName']."', '".$user['RealAddress']."', '".$user['BytesReceived']."', '".$user['BytesSent']."', '".$user['Since']."', '".$user['VirtualAddress']."', '".$user['LastRef']."')");
- }
- }
- }
- ?>
You have to edit the mysql details and the log location.
Here we insert the stats in the db, if the session start time and the client name is the same, it updates. If not, it inserts. We filter out UNDEF, UNDEF sometimes appears in the log, my guess is when the client isn’t fully connected yet.
Then I made a cron that saves the stats every minute:
Cron:
- * * * * * cd [cron location]; php cron.php
Replace [location] with the absolute folder to the cron, like /home/openvpn
I run the script every minute to prevent stats loss, but you could also do this less.
Stats.php:
- <?php
- function parseLog ($log) {
- $handle = fopen($log, "r");
- $uid = 0;
- while (!feof($handle)) {
- $buffer = fgets($handle, 4096);
- unset($match);
- if (ereg("^Updated,(.+)", $buffer, $match)) {
- $status['updated'] = $match[1];
- }
- if (preg_match("/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)$/", $buffer, $match)) {
- if ($match[1] <> "Common Name") {
- $cn = $match[1];
- $userlookup[$match[2]] = $uid;
- $status['users'][$uid]['CommonName'] = $match[1];
- $status['users'][$uid]['RealAddress'] = $match[2];
- $status['users'][$uid]['BytesReceived'] = sizeformat($match[3]);
- $status['users'][$uid]['BytesSent'] = sizeformat($match[4]);
- $status['users'][$uid]['Since'] = $match[5];
- $uid++;
- }
- }
- if (preg_match("/^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)$/", $buffer, $match)) {
- if ($match[1] <> "Virtual Address") {
- $address = $match[3];
- $uid = $userlookup[$address];
- $status['users'][$uid]['VirtualAddress'] = $match[1];
- $status['users'][$uid]['LastRef'] = $match[4];
- }
- }
- }
- fclose($handle);
- return($status);
- }
- function sizeformat($bytesize){
- $i=0;
- while(abs($bytesize) >= 1024){
- $bytesize=$bytesize/1024;
- $i++;
- if($i==4) break;
- }
- $units = array("Bytes","KB","MB","GB","TB");
- $newsize=round($bytesize,2);
- return("$newsize $units[$i]");
- }
- $stats = parseLog("/etc/openvpn/openvpn-status.log");
- echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><body><center>';
- echo '<h3>logged in users</h3><br>
- <table>
- <tr style="font-weight: bold;" bgcolor="#888888">
- <td>Common Name</td>
- <td>Real Address</td>
- <td>Virtual Address</td>
- <td>Logged In At</td>
- <td>Bytes Sent</td>
- <td>Bytes Received</td>
- <td>Last Activity</td>
- </tr>
- ';
- foreach($stats['users'] as $user)
- {
- echo '<tr bgcolor="#eeeeee">
- <td>'.$user['CommonName'].'</td>
- <td>'.$user['RealAddress'].'</td>
- <td>'.$user['VirtualAddress'].'</td>
- <td>'.$user['Since'].'</td>
- <td>'.$user['BytesReceived'].'</td>
- <td>'.$user['BytesSent'].'</td>
- <td>'.$user['LastRef'].'</td>
- </tr>';
- }
- echo '
- </table>
- <br>
- <center>Live status Last Updated: <b>'.$stats['updated'].'
- </b>
- ';
- mysql_connect('localhost', 'openvpn', 'openvpn');
- mysql_select_db('openvpn');
- echo '<h3>bandwidth totals - all time</h3><br>
- <table>
- <tr style="font-weight: bold;" bgcolor="#888888">
- <td>Common Name</td>
- <td>Bytes Sent</td>
- <td>Bytes Received</td>
- </tr>
- ';
- $result = mysql_query("SELECT sum(BytesSent) as 'totalsend', sum(BytesReceived) as 'totalreceived' FROM stats") or die(mysql_error());
- while ($row = mysql_fetch_assoc($result)) {
- echo '<tr bgcolor="#eeeeee">
- <td>Total</td>
- <td>'.sizeformat($row['totalreceived']).'</td>
- <td>'.sizeformat($row['totalsend']).'</td>
- </tr>';
- }
- unset($result);
- $result = mysql_query("SELECT CommonName, sum(BytesSent) as 'totalsend', sum(BytesReceived) as 'totalreceived' FROM stats GROUP BY CommonName ORDER BY CommonName ASC") or die(mysql_error());
- while ($row = mysql_fetch_assoc($result)) {
- echo '<tr bgcolor="#eeeeee">
- <td>'.$row['CommonName'].'</td>
- <td>'.sizeformat($row['totalreceived']).'</td>
- <td>'.sizeformat($row['totalsend']).'</td>
- </tr>';
- }
- echo '
- </table>
- ';
- unset($result);
- echo '<h3>bandwidth totals - Today</h3><br>
- <table>
- <tr style="font-weight: bold;" bgcolor="#888888">
- <td>Common Name</td>
- <td>Bytes Sent</td>
- <td>Bytes Received</td>
- </tr>
- ';
- $result = mysql_query("SELECT sum(BytesSent) as 'totalsend', sum(BytesReceived) as 'totalreceived' FROM stats WHERE LastRef LIKE '%".date("M")." ".date("j")."%".date("Y")."%'") or die(mysql_error());
- while ($row = mysql_fetch_assoc($result)) {
- echo '<tr bgcolor="#eeeeee">
- <td>Total</td>
- <td>'.sizeformat($row['totalreceived']).'</td>
- <td>'.sizeformat($row['totalsend']).'</td>
- </tr>';
- }
- unset($result);
- $result = mysql_query("SELECT CommonName, sum(BytesSent) as 'totalsend', sum(BytesReceived) as 'totalreceived' FROM stats WHERE LastRef LIKE '%".date("M")." ".date("j")."%".date("Y")."%' GROUP BY CommonName ") or die(mysql_error());
- while ($row = mysql_fetch_assoc($result)) {
- echo '<tr bgcolor="#eeeeee">
- <td>'.$row['CommonName'].'</td>
- <td>'.sizeformat($row['totalreceived']).'</td>
- <td>'.sizeformat($row['totalsend']).'</td>
- </tr>';
- }
- echo '
- </table>
- ';
- unset($result);
- echo '<h3>bandwidth totals - last 7 days</h3><br>
- <table>
- <tr style="font-weight: bold;" bgcolor="#888888">
- <td>Common Name</td>
- <td>Bytes Sent</td>
- <td>Bytes Received</td>
- </tr>
- ';
- $like = "LastRef LIKE '%".date("M")." ".date("j")."%".date("Y")."%'";
- for ($i=0; $i<7; $i++)
- {
- $like .= " OR LastRef LIKE '%".date("M",strtotime("-".($i+1)." day"))." ".date("j",strtotime("-".($i+1)." day"))."%".date("Y",strtotime("-".($i+1)." day"))."%'";
- }
- $result = mysql_query("SELECT sum(BytesSent) as 'totalsend', sum(BytesReceived) as 'totalreceived' FROM stats WHERE ".$like."") or die(mysql_error());
- while ($row = mysql_fetch_assoc($result)) {
- echo '<tr bgcolor="#eeeeee">
- <td>Total</td>
- <td>'.sizeformat($row['totalreceived']).'</td>
- <td>'.sizeformat($row['totalsend']).'</td>
- </tr>';
- }
- unset($result);
- $result = mysql_query("SELECT CommonName, sum(BytesSent) as 'totalsend', sum(BytesReceived) as 'totalreceived' FROM stats WHERE ".$like." GROUP BY CommonName ") or die(mysql_error());
- while ($row = mysql_fetch_assoc($result)) {
- echo '<tr bgcolor="#eeeeee">
- <td>'.$row['CommonName'].'</td>
- <td>'.sizeformat($row['totalreceived']).'</td>
- <td>'.sizeformat($row['totalsend']).'</td>
- </tr>';
- }
- echo '
- </table>
- ';
- unset($result);
- echo '<h3>bandwidth totals - This month</h3><br>
- <table>
- <tr style="font-weight: bold;" bgcolor="#888888">
- <td>Common Name</td>
- <td>Bytes Sent</td>
- <td>Bytes Received</td>
- </tr>
- ';
- $result = mysql_query("SELECT sum(BytesSent) as 'totalsend', sum(BytesReceived) as 'totalreceived' FROM stats WHERE LastRef LIKE '%".date("M")."%".date("Y")."%'") or die(mysql_error());
- while ($row = mysql_fetch_assoc($result)) {
- echo '<tr bgcolor="#eeeeee">
- <td>Total</td>
- <td>'.sizeformat($row['totalreceived']).'</td>
- <td>'.sizeformat($row['totalsend']).'</td>
- </tr>';
- }
- unset($result);
- $result = mysql_query("SELECT CommonName, sum(BytesSent) as 'totalsend', sum(BytesReceived) as 'totalreceived' FROM stats WHERE LastRef LIKE '%".date("M")."%".date("Y")."%' GROUP BY CommonName ") or die(mysql_error());
- while ($row = mysql_fetch_assoc($result)) {
- echo '<tr bgcolor="#eeeeee">
- <td>'.$row['CommonName'].'</td>
- <td>'.sizeformat($row['totalreceived']).'</td>
- <td>'.sizeformat($row['totalsend']).'</td>
- </tr>';
- }
- echo '
- </table>
- ';
- unset($result);
- echo '<h3>bandwidth totals - This year</h3><br>
- <table>
- <tr style="font-weight: bold;" bgcolor="#888888">
- <td>Common Name</td>
- <td>Bytes Sent</td>
- <td>Bytes Received</td>
- </tr>
- ';
- $result = mysql_query("SELECT sum(BytesSent) as 'totalsend', sum(BytesReceived) as 'totalreceived' FROM stats WHERE LastRef LIKE '%".date("Y")."%'") or die(mysql_error());
- while ($row = mysql_fetch_assoc($result)) {
- echo '<tr bgcolor="#eeeeee">
- <td>Total</td>
- <td>'.sizeformat($row['totalreceived']).'</td>
- <td>'.sizeformat($row['totalsend']).'</td>
- </tr>';
- }
- unset($result);
- $result = mysql_query("SELECT CommonName, sum(BytesSent) as 'totalsend', sum(BytesReceived) as 'totalreceived' FROM stats WHERE LastRef LIKE '%".date("Y")."%' GROUP BY CommonName ") or die(mysql_error());
- while ($row = mysql_fetch_assoc($result)) {
- echo '<tr bgcolor="#eeeeee">
- <td>'.$row['CommonName'].'</td>
- <td>'.sizeformat($row['totalreceived']).'</td>
- <td>'.sizeformat($row['totalsend']).'</td>
- </tr>';
- }
- echo '
- </table>
- ';
- echo '</center></body></html>';
- ?>
Edit the database details and log location here too, and you’re done. I advise to protect the folder with a .htaccess+.htpasswd or some simple php login.
Sorry for my dirty code, but hey, it works.
]]>