To make the changes to PetaLinux permanent they need to be included in the build process.
Apply a slight modification to the uptime.cgi call inside uptime.js - Add a / before cgi-bin on line 73. This is now the same as the calls to peek, poke & peekstring.
steve@Desktop:~/projects/zedboard_linux$ subl os/petalinux/project-spec/meta-user/recipes-apps/website/files/uptime.js
uptime.js (partial)
var url = "cgi-bin/uptime.cgi";
- var url = "/cgi-bin/uptime.cgi";
Direct download available here :-
steve@Desktop:~/projects/zedboard_linux$ wget https://spacewire.co.uk/tutorial/shared/repos/0024/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/uptime.js -O os/petalinux/project-spec/meta-user/recipes-apps/website/files/uptime.js
Do a quick & dirty conversion of
index.cgi (shell script) into
index.php (PHP).
steve@Desktop:~/projects/zedboard_linux$ cp os/petalinux/project-spec/meta-user/recipes-apps/website/files/cgi-bin/index.cgi os/petalinux/project-spec/meta-user/recipes-apps/website/files/cgi-bin/index.php
steve@Desktop:~/projects/zedboard_linux$ subl os/petalinux/project-spec/meta-user/recipes-apps/website/files/cgi-bin/index.php
<?php
// Get information
$sys_host = exec('hostname', $retval);
$sys_time = exec('date', $retval);
$sys_load = exec('awk \'{print $1}\' /proc/loadavg', $retval);
$sys_up = exec('awk \'{print $1}\' /proc/uptime', $retval);
$cpu_model = exec('grep model /proc/cpuinfo | cut -d : -f2 | tail -1 | sed \'s/\s//\'', $retval);
$cpu_cores = exec('grep -c ^processor /proc/cpuinfo', $retval);
$mem_total = exec('free -m | awk \'NR==2{print $2}\'', $retval);
$mem_used = exec('free -m | awk \'NR==2{print $3}\'', $retval);
$mem_free = exec('free -m | awk \'NR==2{print $4}\'', $retval);
$net_mac = exec('cat /sys/class/net/eth0/address', $retval);
$net_ip_loc = exec('ip a | grep inet | grep -vw lo | grep -v inet6 | cut -d \/ -f1 | sed \'s/[^0-9\.]*//g\'', $retval);
$net_ip_ext = exec('wget -q -O- http://ipecho.net/plain', $retval);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link href="../styles.css" rel="stylesheet">
<title>Zedboard Webserver</title>
</head>
<body onload="add_register()">
<div class="section"><h2>Zedboard Webserver</h2></div>
<div class="section">
<table>
<thead>
<tr><th colspan="3">Operating System Information <button onclick="read_os_ids()">Read ID</button></th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:right">Description :</td>
<td style="text-align:left" id="oid_0">Unknown</td>
<td><img id="osid_0" style="vertical-align:middle" src="../amber.gif" title="Unknown!" alt="Missing Image!"></td>
</tr>
<tr>
<td style="text-align:right">Company :</td>
<td style="text-align:left" id="oid_1">Unknown</td>
<td><img id="osid_1" style="vertical-align:middle" src="../amber.gif" title="Unknown!" alt="Missing Image!"></td>
</tr>
<tr>
<td style="text-align:right">Author :</td>
<td style="text-align:left" id="oid_2">Unknown</td>
<td><img id="osid_2" style="vertical-align:middle" src="../amber.gif" title="Unknown!" alt="Missing Image!"></td>
</tr>
<tr>
<td style="text-align:right">Version :</td>
<td style="text-align:left" id="oid_3">Unknown</td>
<td><img id="osid_3" style="vertical-align:middle" src="../amber.gif" title="Unknown!" alt="Missing Image!"></td>
</tr>
<tr>
<td style="text-align:right">Timestamp :</td>
<td style="text-align:left" id="oid_4">Unknown</td>
<td><img id="osid_4" style="vertical-align:middle" src="../amber.gif" title="Unknown!" alt="Missing Image!"></td>
</tr>
<tr>
<td style="text-align:right">Hash :</td>
<td style="text-align:left" id="oid_5">Unknown</td>
<td><img id="osid_5" style="vertical-align:middle" src="../amber.gif" title="Unknown!" alt="Missing Image!"></td>
</tr>
</tbody>
</table>
<table>
<thead>
<tr><th colspan="3">Firmware Information <input type="submit" value="Read ID" id="read_ids" onclick="read_ids()"></th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:right">Description :</td>
<td style="text-align:left" id="id_0">Unknown</td>
<td><img id="sid_0" style="vertical-align:middle" src="../amber.gif" title="Unknown!" alt="Missing Image!"></td>
</tr>
<tr>
<td style="text-align:right">Company :</td>
<td style="text-align:left" id="id_1">Unknown</td>
<td><img id="sid_1" style="vertical-align:middle" src="../amber.gif" title="Unknown!" alt="Missing Image!"></td>
</tr>
<tr>
<td style="text-align:right">Author :</td>
<td style="text-align:left" id="id_2">Unknown</td>
<td><img id="sid_2" style="vertical-align:middle" src="../amber.gif" title="Unknown!" alt="Missing Image!"></td>
</tr>
<tr>
<td style="text-align:right">Version :</td>
<td style="text-align:left" id="id_3">Unknown</td>
<td><img id="sid_3" style="vertical-align:middle" src="../amber.gif" title="Unknown!" alt="Missing Image!"></td>
</tr>
<tr>
<td style="text-align:right">Timestamp :</td>
<td style="text-align:left" id="id_4">Unknown</td>
<td><img id="sid_4" style="vertical-align:middle" src="../amber.gif" title="Unknown!" alt="Missing Image!"></td>
</tr>
<tr>
<td style="text-align:right">Hash :</td>
<td style="text-align:left" id="id_5">Unknown</td>
<td><img id="sid_5" style="vertical-align:middle" src="../amber.gif" title="Unknown!" alt="Missing Image!"></td>
</tr>
</tbody>
</table>
</div>
<div class="section"><img src="../zedboard.png" alt="Missing Image!"></div>
<div class="section">
<table>
<tr><th colspan="2">System</th></tr>
<tr><td>Hostname</td>
<td><?php echo $sys_host ?></td>
</tr><tr><td>Time</td><td><?php echo $sys_time ?></td></tr>
<tr><td>Uptime</td><td><span id="uptime_text"><?php echo $sys_up ?></span> seconds <button onclick="get_uptime()">Refresh</button> Auto :
<select id="uptime" onchange="uptime();">
<option value="0">Off</option>
<option value="1">1s</option>
<option value="5">5s</option>
</select>
</td></tr>
</table>
<table>
<tr><th colspan="2">CPU</th></tr>
<tr><td>Model</td>
<td><?php echo $cpu_model ?></td></tr>
<tr><td>Cores</td><td><?php echo $cpu_cores ?></td></tr>
<tr><td>Load</td><td><?php echo $sys_load ?></td></tr>
</table>
<table>
<tr><th colspan="2">Memory</th></tr>
<tr><td>Total</td><td><?php echo $mem_total ?> Mb</td></tr>
<tr><td>Used</td><td><?php echo $mem_used ?> Mb</td></tr>
<tr><td>Free</td><td><?php echo $mem_free ?> Mb</td></tr>
</table>
<table>
<tr><th colspan="2">Network</th></tr>
<tr><td>MAC Address</td><td><?php echo $net_mac ?></td></tr>
<tr><td>Internal IP</td><td><?php echo $net_ip_loc ?></td></tr>
<tr><td>External IP</td><td><?php echo $net_ip_ext ?></td></tr>
</table>
</div>
<div class="section">
<table id="registers">
<tr>
<th>Address</th>
<th>Peek Value</th>
<th>Sel</th>
<th>Peek</th>
<th>Status</th>
<th>Copy</th>
<th>Poke Value</th>
<th>Sel</th>
<th>Poke</th>
<th>Status</th>
<th>Description</th>
</tr>
</table>
<br><br>
<input title="Add new row to end of address table" type="button" value="Add" onclick="add_row()">
<select title="Set type of row to add to address table" id="type">
<option value="0">Register</option>
<option value="1">Section</option>
</select>
<input title="Remove last address from table" type="button" value="Remove" onclick="rem_register()">
<input title="Peek all selected addresses in table" type="button" value="Peek All" onclick="peek_all()">
<input title="Copy all table peek values into poke values" type="button" value="Copy All" onclick="copy_all()">
<input title="Poke all selected addresses in table" type="button" value="Poke All" onclick="poke_all()">
Peek Refresh :
<select title="Set timer interval for automatic peek of table addresses" id="timer" onchange="timer()">
<option value="0">Off</option>
<option value="1">1s</option>
<option value="5">5s</option>
</select>
Number Format :
<select title="Set number format for peek and poke values" id="format" onchange="format()">
<option value="0">Hexadecimal</option>
<option value="1">Unsigned</option>
</select>
Configuration :
<button title="Create configuration file from table" onclick="create_config()">Create...</button> <a title="Right click and Save Link As... to locate and rename this file" download="config.txt" id="download" href="" style="display: none">config.txt</a>
<input title="Read configuration file into table" type="file" id="load_config">
</div>
<div class="section">Designed by Steve Haywood @ 2021</div>
<script src="../uptime.js"></script>
</body>
</html>
Direct download available here :-
steve@Desktop:~/projects/zedboard_linux$ wget https://spacewire.co.uk/tutorial/shared/repos/0024/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/cgi-bin/index.php.txt -O os/petalinux/project-spec/meta-user/recipes-apps/website/files/cgi-bin/index.php
Check out the changes.
steve@Desktop:~/projects/zedboard_linux$ git difftool v11.0:zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/cgi-bin/index.cgi os/petalinux/project-spec/meta-user/recipes-apps/website/files/cgi-bin/index.php
Modify
index.html such that it becomes an index page for accessing all the other pages.
steve@Desktop:~/projects/zedboard_linux$ subl os/petalinux/project-spec/meta-user/recipes-apps/website/files/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Zedboard webserver</title>
</head>
<body>
<h3>Index</h3>
<ul>
<li><a href="cgi-bin/test-cgi" target=_blank>cgi-bin/test-cgi</a></li>
<li><a href="cgi-bin/hello_world.php" target=_blank>cgi-bin/hello_world.php</a></li>
<li><a href="cgi-bin/sqlite_test.php" target=_blank>cgi-bin/sqlite_test.php</a></li>
<li><a href="cgi-bin/phpliteadmin.php" target=_blank>cgi-bin/phpliteadmin.php</a></li>
<li><a href="cgi-bin/index.php" target=_blank>cgi-bin/index.php</a></li>
</ul>
</body>
</html>
Direct download available here :-
steve@Desktop:~/projects/zedboard_linux$ wget https://spacewire.co.uk/tutorial/shared/repos/0024/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/index.html -O os/petalinux/project-spec/meta-user/recipes-apps/website/files/index.html
Check out the changes.
steve@Desktop:~/projects/zedboard_linux$ git difftool os/petalinux/project-spec/meta-user/recipes-apps/website/files/index.html
Modify the website BitBake recipe to install the new & modified files.
steve@Desktop:~/projects/zedboard_linux$ subl os/petalinux/project-spec/meta-user/recipes-apps/website/website.bb
#
# This file is the website recipe.
#
SUMMARY = "Simple website application"
SECTION = "PETALINUX/apps"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI = "file://index.html"
SRC_URI += "file://uptime.js"
SRC_URI += "file://zedboard.png"
SRC_URI += "file://styles.css"
SRC_URI += "file://cgi-bin/index.php"
SRC_URI += "file://cgi-bin/uptime.cgi"
SRC_URI += "file://cgi-bin/test-cgi"
SRC_URI += "file://cgi-bin/hello_world.php"
SRC_URI += "file://cgi-bin/sqlite_test.php"
SRC_URI += "file://cgi-bin/phpliteadmin.php"
SRC_URI += "file://cgi-bin/phpliteadmin.config.php"
SRC_URI += "file://amber.gif"
SRC_URI += "file://green.gif"
SRC_URI += "file://red.gif"
SRC_URI += "file://project.txt"
FILES_${PN} += "/srv/www"
S = "${WORKDIR}"
do_install() {
install -d ${D}/srv/www
install -m 0644 ${S}/index.html ${D}/srv/www/index.html
install -m 0644 ${S}/uptime.js ${D}/srv/www
install -m 0644 ${S}/zedboard.png ${D}/srv/www
install -m 0644 ${S}/styles.css ${D}/srv/www
install -m 0644 ${S}/amber.gif ${D}/srv/www
install -m 0644 ${S}/green.gif ${D}/srv/www
install -m 0644 ${S}/red.gif ${D}/srv/www
install -m 0644 ${S}/project.txt ${D}/srv/www
install -d ${D}/srv/www/cgi-bin
install -m 0777 -d ${D}/srv/www/cgi-bin/db
install -m 0644 ${S}/cgi-bin/index.php ${D}/srv/www/cgi-bin
install -m 0755 ${S}/cgi-bin/uptime.cgi ${D}/srv/www/cgi-bin
install -m 0755 ${S}/cgi-bin/test-cgi ${D}/srv/www/cgi-bin
install -m 0644 ${S}/cgi-bin/hello_world.php ${D}/srv/www/cgi-bin
install -m 0644 ${S}/cgi-bin/sqlite_test.php ${D}/srv/www/cgi-bin
install -m 0644 ${S}/cgi-bin/phpliteadmin.php ${D}/srv/www/cgi-bin
install -m 0644 ${S}/cgi-bin/phpliteadmin.config.php ${D}/srv/www/cgi-bin
}
Direct download available here :-
steve@Desktop:~/projects/zedboard_linux$ wget https://spacewire.co.uk/tutorial/shared/repos/0024/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/website.bb -O os/petalinux/project-spec/meta-user/recipes-apps/website/website.bb
Check out the changes.
steve@Desktop:~/projects/zedboard_linux$ git difftool os/petalinux/project-spec/meta-user/recipes-apps/website/website.bb
Modify the peekpokecgi BitBake recipe to add root execution permissions.
steve@Desktop:~/projects/zedboard_linux$ subl os/petalinux/project-spec/meta-user/recipes-apps/peekpokecgi/peekpokecgi.bb
#
# This is the peekpokecgi aplication recipe
#
#
SUMMARY = "peekpokecgi application"
SECTION = "PETALINUX/apps"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI = "file://peek.c \
file://poke.c \
file://peekstring.c \
file://Makefile \
"
FILES_${PN} += "/srv/www/cgi-bin"
S = "${WORKDIR}"
CFLAGS_prepend = "-I ${S}/include"
do_compile() {
oe_runmake
}
do_install() {
install -d ${D}/srv/www/cgi-bin
install -m 0755 ${S}/peek ${D}/srv/www/cgi-bin
install -m 0755 ${S}/poke ${D}/srv/www/cgi-bin
install -m 0755 ${S}/peekstring ${D}/srv/www/cgi-bin
chmod a+s ${D}/srv/www/cgi-bin/peek
chmod a+s ${D}/srv/www/cgi-bin/poke
chmod a+s ${D}/srv/www/cgi-bin/peekstring
}
Direct download available here :-
steve@Desktop:~/projects/zedboard_linux$ wget https://spacewire.co.uk/tutorial/shared/repos/0024/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/peekpokecgi/peekpokecgi.bb -O os/petalinux/project-spec/meta-user/recipes-apps/peekpokecgi/peekpokecgi.bb
Check out the changes.
steve@Desktop:~/projects/zedboard_linux$ git difftool os/petalinux/project-spec/meta-user/recipes-apps/peekpokecgi/peekpokecgi.bb
Create an Apache BitBake append to realise the changes made to httpd.conf.
steve@Desktop:~/projects/zedboard_linux$ mkdir -p os/petalinux/components/yocto/layers/meta-openembedded/meta-webserver/recipes-httpd/apache2
Note the last entry is an addition to allow Apache to read index.php pages from directories & subdirectories without specifying the page explicitly.
steve@Desktop:~/projects/zedboard_linux$ subl os/petalinux/components/yocto/layers/meta-openembedded/meta-webserver/recipes-httpd/apache2/apache2_%.bbappend
do_install_append() {
sed -i 's@^#LoadModule cgid_module /usr/libexec/apache2/modules/mod_cgid.so@LoadModule cgid_module /usr/libexec/apache2/modules/mod_cgid.so@' ${D}/${sysconfdir}/${BPN}/httpd.conf
sed -i 's@^DocumentRoot "/usr/share/apache2/default-site/htdocs"@DocumentRoot "/srv/www"@' ${D}/${sysconfdir}/${BPN}/httpd.conf
sed -i 's@^<Directory "/usr/share/apache2/default-site/htdocs">@<Directory "/srv/www">@' ${D}/${sysconfdir}/${BPN}/httpd.conf
sed -i 's@^ ScriptAlias /cgi-bin/ "/usr/libexec/apache2/modules/cgi-bin/"@ ScriptAlias /cgi-bin/ "/srv/www/cgi-bin/"@' ${D}/${sysconfdir}/${BPN}/httpd.conf
sed -i 's@^<Directory "/usr/libexec/apache2/modules/cgi-bin">@<Directory "/srv/www/cgi-bin">@' ${D}/${sysconfdir}/${BPN}/httpd.conf
sed -i 's@^ DirectoryIndex index.html@ DirectoryIndex index.html index.php@' ${D}/${sysconfdir}/${BPN}/httpd.conf
}
Direct download available here :-
steve@Desktop:~/projects/zedboard_linux$ wget https://spacewire.co.uk/tutorial/shared/repos/0024/zedboard_linux/os/petalinux/components/yocto/layers/meta-openembedded/meta-webserver/recipes-httpd/apache2/apache2_%.bbappend -O os/petalinux/components/yocto/layers/meta-openembedded/meta-webserver/recipes-httpd/apache2/apache2_%.bbappend