-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
1,124 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
/.idea | ||
/.vscode | ||
/.vagrant | ||
/database/database.sqlite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,29 @@ | ||
<p align="center"> | ||
<img title="Laravel Zero" height="100" src="https://raw.githubusercontent.com/laravel-zero/docs/master/images/logo/laravel-zero-readme.png" /> | ||
</p> | ||
# doddns | ||
|
||
<p align="center"> | ||
<a href="https://travis-ci.org/laravel-zero/framework"><img src="https://img.shields.io/travis/laravel-zero/framework/stable.svg" alt="Build Status"></img></a> | ||
<a href="https://scrutinizer-ci.com/g/laravel-zero/framework"><img src="https://img.shields.io/scrutinizer/g/laravel-zero/framework.svg" alt="Quality Score"></img></a> | ||
<a href="https://packagist.org/packages/laravel-zero/framework"><img src="https://poser.pugx.org/laravel-zero/framework/d/total.svg" alt="Total Downloads"></a> | ||
<a href="https://packagist.org/packages/laravel-zero/framework"><img src="https://poser.pugx.org/laravel-zero/framework/v/stable.svg" alt="Latest Stable Version"></a> | ||
<a href="https://packagist.org/packages/laravel-zero/framework"><img src="https://poser.pugx.org/laravel-zero/framework/license.svg" alt="License"></a> | ||
</p> | ||
A small PHP thigny to use one's domain added to Digital Ocean as a dynamic dns service make with [Laravel Zero](https://github.com/laravel-zero/laravel-zero). | ||
|
||
<h4> <center>This is a <bold>community project</bold> and not an official Laravel one </center></h4> | ||
## What is needed | ||
|
||
Laravel Zero was created by, and is maintained by [Nuno Maduro](https://github.com/nunomaduro), and is a micro-framework that provides an elegant starting point for your console application. It is an **unofficial** and customized version of Laravel optimized for building command-line applications. | ||
- A Digital Ocean [Personal Access Token](https://www.digitalocean.com/docs/api/create-personal-access-token/). | ||
- Some domains added to your account. | ||
- A `cname` or `A` records added to a domain for us to update. | ||
|
||
- Built on top of the [Laravel](https://laravel.com) components. | ||
- Optional installation of Laravel [Eloquent](http://laravel-zero.com/#/?id=database), Laravel [Logging](http://laravel-zero.com/#/?id=log) and many others. | ||
- Supports interactive [menus](http://laravel-zero.com/#/?id=interactive-menus) and [desktop notifications](http://laravel-zero.com/#/?id=desktop-notifications) on Linux, Windows & MacOS. | ||
- Ships with a [Scheduler](http://laravel-zero.com/#/?id=scheduler) and a [Standalone Compiler](http://laravel-zero.com/#/?id=build-a-standalone-application). | ||
- Integration with [Collision](https://github.com/nunomaduro/collision) - Beautiful error reporting | ||
## How to use | ||
|
||
------ | ||
Depending on your mood, you can either [download the compiled version](https://github.com/jpmurray/doddns/raw/master/builds/doddns) or [build it yourself](https://laravel-zero.com/#/usage?id=building-a-standalone-application), then add it to your `$PATH` and run the setup command... And you're good to go! | ||
|
||
## Documentation | ||
### Cron | ||
If you want doddns to autoupdate with your current IP address, you should add an ntry to your cron tab like so: `* * * * * php /path-to-doddns/doddns schedule:run >> /dev/null 2>&1`. | ||
|
||
For full documentation, visit [laravel-zero.com](http://laravel-zero.com/). | ||
After that, doddns will try to update every hours by itself. | ||
|
||
## Support the development | ||
**Do you like this project? Support it by donating** | ||
### Available commands | ||
|
||
- PayPal: [Donate](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=66BYDWAT92N6L) | ||
- Patreon: [Donate](https://www.patreon.com/nunomaduro) | ||
You can then use the `doddns` command to see a list of possible actions: | ||
|
||
## License | ||
|
||
Laravel Zero is an open-source software licensed under the [MIT license](https://github.com/laravel-zero/laravel-zero/blob/stable/LICENSE.md). | ||
- `doddns setup`: will create local database and asks for DO personal acces token. | ||
- `doddns set-token {token}`: will set your DO personal access token, overwriting any existing value. | ||
- `doddns records:list`: list any added record that doddns tries to update. | ||
- `doddns records:add`: add a record to update to the database from exiting DO domains. | ||
- `doddns records:remove`: removes a record from doddns' database. | ||
- `doddns records:update`: updates records in database with actual IP. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
namespace App\Commands; | ||
|
||
use App\Helpers\DigitalOceanHelper; | ||
use App\Helpers\SettingsHelper; | ||
use Illuminate\Console\Scheduling\Schedule; | ||
use Illuminate\Support\Facades\DB; | ||
use LaravelZero\Framework\Commands\Command; | ||
|
||
class AddRecord extends Command | ||
{ | ||
/** | ||
* The signature of the command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'records:add'; | ||
|
||
/** | ||
* The description of the command. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Set which records to update.'; | ||
|
||
protected $settings; | ||
protected $token; | ||
|
||
private $digitalocean; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return mixed | ||
*/ | ||
public function handle() | ||
{ | ||
$this->settings = new SettingsHelper(); | ||
|
||
if ($this->settings->error !== null) { | ||
$this->error($this->settings->error); | ||
return; | ||
} | ||
|
||
$this->digitalocean = new DigitalOceanHelper($this->settings->getToken()); | ||
|
||
$domains = collect($this->digitalocean->domain->getAll())->mapWithKeys(function ($values) { | ||
return [$values->name => $values->name]; | ||
})->toArray(); | ||
|
||
$selected_domain = $this->menu("Which domain?", $domains)->open(); | ||
|
||
if ($selected_domain === null) { | ||
$this->info("Nothing selected. Exiting."); | ||
return; | ||
} | ||
|
||
$records = collect($this->digitalocean->domainRecord->getAll($selected_domain))->filter(function ($record) { | ||
return $record->type == "CNAME" || $record->type == "A"; | ||
}); | ||
|
||
$records_for_menu = $records->mapWithKeys(function ($values, $key) { | ||
return [$key => "{$values->name} ({$values->type}): {$values->data}"]; | ||
})->toArray(); | ||
|
||
$selected_record = $this->menu("Which record?", $records_for_menu)->open(); | ||
|
||
if ($selected_record === null) { | ||
$this->info("Nothing selected. Exiting."); | ||
return; | ||
} | ||
|
||
DB::table('records')->insert( | ||
['domain' => $selected_domain, | ||
'record_id' => $records[$selected_record]->id, | ||
'record_name' => $records[$selected_record]->name, | ||
'record_type' => $records[$selected_record]->type] | ||
); | ||
|
||
$this->info("Record {$records[$selected_record]->name} for domain {$selected_domain} will be updated on the next cycle."); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace App\Commands; | ||
|
||
use Illuminate\Console\Scheduling\Schedule; | ||
use Illuminate\Support\Facades\DB; | ||
use LaravelZero\Framework\Commands\Command; | ||
|
||
class ListRecords extends Command | ||
{ | ||
/** | ||
* The signature of the command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'records:list'; | ||
|
||
/** | ||
* The description of the command. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Display a list of records we update each cycles.'; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return mixed | ||
*/ | ||
public function handle() | ||
{ | ||
$records = DB::table('records')->get(); | ||
|
||
$records->each(function ($record, $key) { | ||
$this->line(""); | ||
$this->info("[{$key}] ({$record->record_type}) {$record->record_name} of {$record->domain}"); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace App\Commands; | ||
|
||
use Illuminate\Console\Scheduling\Schedule; | ||
use Illuminate\Support\Facades\DB; | ||
use LaravelZero\Framework\Commands\Command; | ||
|
||
class RemoveRecord extends Command | ||
{ | ||
/** | ||
* The signature of the command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'records:remove'; | ||
|
||
/** | ||
* The description of the command. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Remove a record from the update cycle.'; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return mixed | ||
*/ | ||
public function handle() | ||
{ | ||
$records = DB::table('records')->get(); | ||
$records_for_menu = collect($records)->mapWithKeys(function ($record) { | ||
return [$record->id => "({$record->record_type}) {$record->record_name} of {$record->domain}"]; | ||
})->toArray(); | ||
|
||
$record_to_remove = $this->menu("Which record to delete?", $records_for_menu)->open(); | ||
|
||
if ($record_to_remove === null) { | ||
$this->info("Nothing selected. Exiting."); | ||
return; | ||
} | ||
|
||
DB::table('records')->where('id', '=', $record_to_remove)->delete(); | ||
|
||
$this->info("Removed!"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
namespace App\Commands; | ||
|
||
use App\Helpers\SettingsHelper; | ||
use Illuminate\Console\Scheduling\Schedule; | ||
use Illuminate\Support\Facades\Artisan; | ||
use Illuminate\Support\Facades\DB; | ||
use LaravelZero\Framework\Commands\Command; | ||
use Storage; | ||
|
||
class Setup extends Command | ||
{ | ||
/** | ||
* The signature of the command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'setup'; | ||
|
||
/** | ||
* The description of the command. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Well... It sets things up.'; | ||
|
||
private $settings; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return mixed | ||
*/ | ||
public function handle() | ||
{ | ||
if ($this->confirm("This will destroy any existing doddns configuration. Is that ok?")) { | ||
$this->task("Creating local database", function () { | ||
if (!is_dir($_SERVER['HOME'].'/.doddns/')) { | ||
mkdir($_SERVER['HOME'].'/.doddns/', 0700); | ||
$this->info("Created .doddns directory in user's home."); | ||
} | ||
|
||
file_put_contents(config('database.connections.sqlite.database'), ""); | ||
$this->info("Created or overwrited any actual databse"); | ||
|
||
Artisan::call('migrate', ['--force' => true]); | ||
|
||
$this->info("Migrated tables"); | ||
|
||
return true; | ||
}); | ||
} | ||
|
||
$this->settings = new SettingsHelper(); | ||
|
||
$token = $this->ask("What is your Digital Ocean peronal access token?"); | ||
|
||
if ($this->settings->error !== null) { | ||
$this->insertToken($token); | ||
} else { | ||
$this->updateToken($token); | ||
} | ||
|
||
$this->info("All done! We're good to go!"); | ||
} | ||
|
||
private function updateToken($token) | ||
{ | ||
if ($this->confirm('Do you wish to overwrite existing saved token?')) { | ||
DB::table('settings')->update( | ||
['token' => $token] | ||
); | ||
} | ||
|
||
$this->info("Token updated!"); | ||
} | ||
|
||
private function insertToken($token) | ||
{ | ||
DB::table('settings')->insert( | ||
['token' => $token] | ||
); | ||
|
||
$this->info("Token added!"); | ||
} | ||
} |
Oops, something went wrong.