From 46d748966c3d9388e4c888ac0fb5493b1e8ebd58 Mon Sep 17 00:00:00 2001 From: Nick Earwood Date: Thu, 31 Oct 2019 11:21:51 -0500 Subject: [PATCH] v1.5 (#24) * Download button (#20) * add functioning download button. seems like some of the temperature values are mangled when importing in to tunerstudio but this at least gives the ability to read in the majority of the tune. will troubleshoot the temp issues later * blank out mariadb username and password from local docker, users can set their own as needed * add download link to browse file as well * complete items from @nearwood's code review: delete db/msqur-4.sql, revert script.config.dist, update src/browse.php to have a capital D for Download and use the floppy emoji in place of download MSQ text, drop null xml check from src/db.php.getMSQForDownload function, change content-type header to application/xml in src/download.php, use floppy emoji in download link in src/msq.php * remove duplicate DB_USER param from script.config.dist * oops: forgot to commit changes to config.php.dist switching DB_HOST and DB_USERNAME back to original settings * Move deploy prereqs to deploy script * Update README * Fix links * Update copyright --- .travis.yml | 4 ---- README.md | 44 +++++++++++++++++++++++++------------------- deploy.sh | 3 +++ src/about.php | 2 +- src/admin.php | 2 +- src/api.php | 2 +- src/browse.php | 6 +++--- src/db.php | 36 +++++++++++++++++++++++++++++++++++- src/download.php | 31 +++++++++++++++++++++++++++++++ src/index.php | 2 +- src/msq.format.php | 2 +- src/msq.php | 3 ++- src/msqur.php | 8 +++++++- src/search.php | 2 +- src/upload.php | 2 +- src/util.php | 2 +- src/view.php | 2 +- src/view/msqur.css | 2 +- src/view/msqur.js | 2 +- 19 files changed, 117 insertions(+), 40 deletions(-) create mode 100644 src/download.php diff --git a/.travis.yml b/.travis.yml index 7dd8ae4..bdcc14a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,3 @@ jobs: script: phpunit tests - stage: deploy script: bash deploy.sh - -before_install: -- mkdir -p ~\/.ssh -- openssl aes-256-cbc -K $encrypted_571de2096706_key -iv $encrypted_571de2096706_iv -in .travis/travis_ci.enc -out .travis/id_rsa -d diff --git a/README.md b/README.md index af23540..6ff1291 100644 --- a/README.md +++ b/README.md @@ -1,57 +1,63 @@ -# MSQur # +# MSQur 'Masker' I guess? Supposed to be a play on imgur. MegaSquirt MSQ file sharing and viewing site. Parses MSQ "XML" in tandem with an associated INI (config) file and displays it in a familiar format for viewing and comparing. -Try it now at: http://msqur.com/ +Try it now at: https://msqur.com/ ### Build Status: * msqur.com [![Build Status](https://travis-ci.org/nearwood/msqur.svg?branch=msqur.com)](https://travis-ci.org/nearwood/msqur) * master [![Build Status](https://travis-ci.org/nearwood/msqur.svg?branch=master)](https://travis-ci.org/nearwood/msqur) -### Installation ### +### Installation -#### Needed software #### +#### Needed software -* AMP Stack: Apache, MySQL (MariaDB), PHP +* MariaDB, PHP * PDO extension for PHP. -#### Recommended software #### +#### Recommended software * phpMyAdmin - For managing the DB -* rsync - For the deployment script -#### Development Setup #### +#### Development Setup + +> These steps could be improved 1. Clone repo to dev directory -1. Copy script.config.dist to script.config -1. Copy src/config.php.dist to src/config.php 1. Create database for msqur, and assign it a user -1. Setup parameters in each config file -1. Update DB with update scripts in sequential order -1. Run deploy script -1. Hit webserver to start using it. +1. Copy script.config.dist to script.config and modify for use (setup DB connection information) +1. Copy src/config.php.dist to src/config.php (setup DB information again) +1. Update DB with update scripts in sequential order (patse into phpMyAdmin or piped to `sqlcmd`, etc.) +1. Hit webserver to start using it (eg. `php -S`, etc.) + +### Update & Deployment Instructions -### Update & Deployment Instructions ### +> These steps are outdated * Pull updates on host. * Update any configuration files (config.php, script.config) if needed. * Run any new DB scripts. * Run deploy.sh to copy web files to web server. -### License ### +### License msqur is licensed under the GPL v3.0. A copy of this license is included in the LICENSE.md file in the source tree. -### Who do I talk to? ### +### Who do I talk to? * Nicholas Earwood * nearwood@gmail.com -* http://nearwood.net/ +* https://nearwood.dev/ + +### Credits + +[CamHenlin](https://github.com/CamHenlin) + +> This section needs to be updated -### Credits ### * Apache * PHP * MariaDB diff --git a/deploy.sh b/deploy.sh index 403f2fd..8337dd9 100755 --- a/deploy.sh +++ b/deploy.sh @@ -1,5 +1,8 @@ #. script.config +mkdir -p ~\/.ssh +openssl aes-256-cbc -K $encrypted_571de2096706_key -iv $encrypted_571de2096706_iv -in .travis/travis_ci.enc -out .travis/id_rsa -d + eval "$(ssh-agent -s)" chmod 600 .travis/id_rsa ssh-add .travis/id_rsa diff --git a/src/about.php b/src/about.php index 6c53ab6..fb15a9e 100644 --- a/src/about.php +++ b/src/about.php @@ -1,6 +1,6 @@
' . $numResults . ' results.
'; echo ''; -echo ''; +echo ''; for ($c = 0; $c < $numResults; $c++) { $aspiration = $results[$c]['induction'] == 1 ? "Turbo" : "NA"; - echo ''; + echo ''; } echo '
IDEngine MakeEngine CodeCylindersLitersCompressionAspirationFirmware/VersionUpload DateViews
IDDownloadEngine MakeEngine CodeCylindersLitersCompressionAspirationFirmware/VersionUpload DateViews
' . $results[$c]['mid'] . '' . $results[$c]['make'] . '' . $results[$c]['code'] . '' . $results[$c]['numCylinders'] . '' . $results[$c]['displacement'] . '' . $results[$c]['compression'] . ':1' . $aspiration . '' . $results[$c]['firmware'] . '/' . $results[$c]['signature'] . '' . $results[$c]['uploadDate'] . '' . $results[$c]['views'] . '
' . $results[$c]['mid'] . '💾' . $results[$c]['make'] . '' . $results[$c]['code'] . '' . $results[$c]['numCylinders'] . '' . $results[$c]['displacement'] . '' . $results[$c]['compression'] . ':1' . $aspiration . '' . $results[$c]['firmware'] . '/' . $results[$c]['signature'] . '' . $results[$c]['uploadDate'] . '' . $results[$c]['views'] . '
'; diff --git a/src/db.php b/src/db.php index eb6204b..88186f1 100644 --- a/src/db.php +++ b/src/db.php @@ -1,6 +1,6 @@ connect()) return null; + + $xml = FALSE; + + try + { + $st = $this->db->prepare("SELECT xml FROM msqs INNER JOIN metadata ON metadata.msq = msqs.id WHERE metadata.id = :id LIMIT 1"); + DB::tryBind($st, ":id", $id); + $st->execute(); + if ($st->rowCount() > 0) + { + $result = $st->fetch(PDO::FETCH_ASSOC); + $st->closeCursor(); + $xml = $result['xml']; + if (DEBUG) debug('
Cached, returning HTML.
'); + } + else + { + echo "
No result for $id
"; + echo '
Invalid MSQ err 2
'; + return null; + } + } + catch (PDOException $e) + { + $this->dbError($e); + } + + return $xml; + } + /** * @brief Get a list of MSQs * @param $bq The BrowseQuery to filter results diff --git a/src/download.php b/src/download.php new file mode 100644 index 0000000..453e1b0 --- /dev/null +++ b/src/download.php @@ -0,0 +1,31 @@ +. */ + +require "msqur.php"; + +if (isset($_GET['msq'])) { + + header('Content-Type: application/xml'); + header('Content-Disposition: attachment; filename=' . $_GET['msq'] . '.msq'); + header('Pragma: no-cache'); + + echo $msqur->getMSQForDownload($_GET['msq']); +} else { + + include "index.php"; +} +?> diff --git a/src/index.php b/src/index.php index 914a451..7fff40c 100644 --- a/src/index.php +++ b/src/index.php @@ -1,6 +1,6 @@ MS Signature: " . $msq->versionInfo['signature'] . ""; $msqHeader .= "
Tuning SW: " . $msq->bibliography['author'] . "
"; $msqHeader .= "
Date: " . $msq->bibliography['writeDate'] . "
"; + $msqHeader .= "
💾
"; $msqHeader .= ''; $sig = $msq->versionInfo['signature']; diff --git a/src/msqur.php b/src/msqur.php index 3b8d105..ae35f6e 100644 --- a/src/msqur.php +++ b/src/msqur.php @@ -1,6 +1,6 @@ db->getMSQ($id); } + public function getMSQForDownload($id) + { + + return $this->db->getMSQForDownload($id); + } + public function addMSQs($files, $engineid) { $fileList = array(); diff --git a/src/search.php b/src/search.php index 5a2cf2a..ed91f3b 100644 --- a/src/search.php +++ b/src/search.php @@ -1,6 +1,6 @@