Skip to content

Commit

Permalink
Merge pull request #6 from Westie/modern-rewrite
Browse files Browse the repository at this point in the history
Modern rewrite
  • Loading branch information
Westie authored Mar 7, 2021
2 parents 5a4c114 + 7252460 commit 65654ec
Show file tree
Hide file tree
Showing 405 changed files with 3,707 additions and 89,101 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.DS_Store
app/configuration.php
app/databases/phpuush.db
app/uploads/
app/vendor/
82 changes: 20 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,82 +2,40 @@

So, you're probably confused as to what this is. Well, it's a proxy for puush. The developers for puush decided to be all stupid and refused to implement useless features like SFTP and FTP.

So, my absolutely brilliant friend [jannispl](https://github.com/jannispl) decided to write a new [proxy](https://github.com/jannispl/puushproxy) for puush in node.js. This, as far as we know, was the first alternative implementation of puush.
So, my absolutely brilliant friend [@jannispl](https://github.com/jannispl) decided to write a new [proxy](https://github.com/jannispl/puushproxy) for puush in node.js. This, as far as we know, was the first alternative implementation of puush.

However, I wanted to experiment in the joys that is hiphop-php. So, I made this! It was designed on Apache, tested on nginx and compiled with hiphop-php.
Almost half a decade on, I thought I would improve it to make it better.

I think I'm one of the only people in the world apart from Facebook using hiphop-php in a product environment, as it may seem.
## How do I migrate to the new version?

# Oh. Okay. What do I do next?
### Preamble

Well, many things. You could pick your nose and eat it - or you could follow some installation cues and get the damned thing working.
Firstly, [install composer](https://getcomposer.org/doc/00-intro.md#installation-linux-unix-macos).

## Create the database
There are three files and folders you'll need to find:

At the moment, only SQLite is supported, however it's my intention to add mySQL and/or another (no)SQL to make those hipsters all happy and shit.
- `configuration.php`
- `databases/phpuush.db` (or whatever your database file is)
- `uploads/` (or whatever your upload folder is)

Go into the `databases/` directory and **copy** `phpuush.db-dist` to something like `phpuush.db` or something.
You can either copy or move - but make sure that you have a backup of this stuff first.

## More configuration
Now you figure out where those files and folders are, you'll need to create a separate installation of phpuush.

Here's a sample `configuration.php` file:
If you are lazy like me, and want everything in one folder so when you're developing whilst drunk you can simply run `git pull` and things are magically fixed, just clone the repo using git.

$aGlobalConfiguration = array
(
"databases" => array
(
"sql" => __DIR__."/databases/phpuush.db",
"mime" => __DIR__."/databases/mime.types",
),
"files" => array
(
"upload" => __DIR__."/uploads/",
"domain" => "http://your.domain.tld",
),
);
If you are security conscious (like some of my friends) then you can download master as a compressed archive, extract it to somewhere, move certain folders around then edit the `APP_DIR` constant within `index.php` but you shouldn't even need to do this, if you properly re-configure everything.

You'll need to edit only two things, one being the SQLite DB file (look up!) and the other being the domain. The domain is obviously the one that you *have* to change.
**Make backups!**

## Setting up webservers
### Moving files to new homes

Oh, so you actually want this thing to be live, eh? Well, what you need to do is set up whatever webserver you have to either accept connections on another port that is not `80` or listen for `puush.me` - whatever floats your boat. There are a million ways to set it up.
- `configuration.php` **must** be relocated to `app/configuration.php`. You may notice that the format of the configuration has changed - there is no need to change this as the configuration itself is backwards compatible.

I'll add examples when I can be bothered.
- `databases/phpuush.db` can be located anywhere that PHP has write access, however for the purposes of this example, move it to `app/databases/phpuush-demo.db`. You need to update the `database.sql` property with the absolute path to this file within the config.

## Setting up your client on Windows - r85
- `uploads/` can be located anywhere that PHP has write access, however for the purposes of this example, move it to `app/uploads`. You need to update the `files.upload` property with the absolute path to this folder within the config.

You just edit `%AppData%\puush\puush.ini` to resemble something like this:
Then, you'll need to run `composer install`

ProxyServer = someproxy
ProxyPort = someport

And then restart puush.

## Setting up your client on OS X - r62

Only attempt this if you're experienced with how to hexedit binaries and such. You will need to create a SSL certificate (self signed is fine) though.

### Choosing the domain to point to

Thankfully I managed to negate the need for a SSL certificate. This has just made the task from extremely hard to relatively easy.

First thing you have to do is add this to the `/private/etc/hosts` file:

<address> phpuushed

Then, you replace your puush binary with the one in the repo. You can find this in
`setup/binaries/OS X/puush` - you need to replace the binary in
`puush.app/Contents/MacOS/puush` with the one on this repo.

The only change is that I've changed `https://puush.me/` to `http://phpuushed/`.

## Using the client

You will need to register by going to:

`http://someproxy:someport/page/register`

Don't want to allow anyone else to register? Just rename `controllers/page/register.php` or whatever you want.

Know of any improvements? Hit me!
Please make sure that your phpuush.db file is not accessible to the outside world. The best thing to do is to make it so that *every* request to that folder is handled by `index.php`. If you can download your `phpuush.db` or `composer.json` through your browser you've configured it incorrectly.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
31 changes: 31 additions & 0 deletions app/setup/httpdconf/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# config for nginx
# give your thanks to Westie!

server
{
set $puush "/path/to/phpuush";

listen 80;
server_name "your.domain.here" "puu.sh" "puush.me" "phpuushed";

client_max_body_size 512M;

root $puush;

location ~ \.php$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $puush$fastcgi_script_name;
}

location ~ /app {
deny all;
return 404;
}

location / {
rewrite ^.*$ /index.php last;
}
}
74 changes: 74 additions & 0 deletions app/src/Configuration/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace App\Configuration;

class Configuration
{
private $data;

/**
* Constructor
*/
public function __construct()
{
if (file_exists(APP_DIR . 'configuration.php')) {
$this->data = $this->readLegacyConfigurationFile();
}
}

/**
* Read a legacy config file
*/
private function readLegacyConfigurationFile(): array
{
$data = (function() {
$returnedValue = require APP_DIR . 'configuration.php';

if (is_array($returnedValue)) {
return $returnedValue;
}

if (isset($aGlobalConfiguration) && is_array($aGlobalConfiguration)) {
return $aGlobalConfiguration;
}

return null;
})();

if (!empty($data['databases']['sql']) && file_exists($data['databases']['sql'])) {
$data['databases']['sql'] = [
'driver' => 'Pdo_Sqlite',
'database' => $data['databases']['sql'],
];
}

return $data;
}

/**
* Get a value
*/
public function get($path)
{
$paths = explode('.', $path);
$root = $this->data;

foreach ($paths as $path) {
if (isset($root[$path])) {
$root = $root[$path];
} else {
$root = null;
}
}

return $root;
}

/**
* Return config
*/
public function toArray(): array
{
return $this->data;
}
}
Loading

0 comments on commit 65654ec

Please sign in to comment.