Skip to content

Commit 960bf81

Browse files
committed
Merge branch 'release/1.0.0'
2 parents 1d0a5ed + fae68a5 commit 960bf81

22 files changed

+1124
-74
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
/.idea
33
/.vscode
44
/.vagrant
5+
/database/database.sqlite

README.md

+19-27
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,29 @@
1-
<p align="center">
2-
<img title="Laravel Zero" height="100" src="https://raw.githubusercontent.com/laravel-zero/docs/master/images/logo/laravel-zero-readme.png" />
3-
</p>
1+
# doddns
42

5-
<p align="center">
6-
<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>
7-
<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>
8-
<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>
9-
<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>
10-
<a href="https://packagist.org/packages/laravel-zero/framework"><img src="https://poser.pugx.org/laravel-zero/framework/license.svg" alt="License"></a>
11-
</p>
3+
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).
124

13-
<h4> <center>This is a <bold>community project</bold> and not an official Laravel one </center></h4>
5+
## What is needed
146

15-
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.
7+
- A Digital Ocean [Personal Access Token](https://www.digitalocean.com/docs/api/create-personal-access-token/).
8+
- Some domains added to your account.
9+
- A `cname` or `A` records added to a domain for us to update.
1610

17-
- Built on top of the [Laravel](https://laravel.com) components.
18-
- Optional installation of Laravel [Eloquent](http://laravel-zero.com/#/?id=database), Laravel [Logging](http://laravel-zero.com/#/?id=log) and many others.
19-
- Supports interactive [menus](http://laravel-zero.com/#/?id=interactive-menus) and [desktop notifications](http://laravel-zero.com/#/?id=desktop-notifications) on Linux, Windows & MacOS.
20-
- Ships with a [Scheduler](http://laravel-zero.com/#/?id=scheduler) and a [Standalone Compiler](http://laravel-zero.com/#/?id=build-a-standalone-application).
21-
- Integration with [Collision](https://github.com/nunomaduro/collision) - Beautiful error reporting
11+
## How to use
2212

23-
------
13+
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!
2414

25-
## Documentation
15+
### Cron
16+
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`.
2617

27-
For full documentation, visit [laravel-zero.com](http://laravel-zero.com/).
18+
After that, doddns will try to update every hours by itself.
2819

29-
## Support the development
30-
**Do you like this project? Support it by donating**
20+
### Available commands
3121

32-
- PayPal: [Donate](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=66BYDWAT92N6L)
33-
- Patreon: [Donate](https://www.patreon.com/nunomaduro)
22+
You can then use the `doddns` command to see a list of possible actions:
3423

35-
## License
36-
37-
Laravel Zero is an open-source software licensed under the [MIT license](https://github.com/laravel-zero/laravel-zero/blob/stable/LICENSE.md).
24+
- `doddns setup`: will create local database and asks for DO personal acces token.
25+
- `doddns set-token {token}`: will set your DO personal access token, overwriting any existing value.
26+
- `doddns records:list`: list any added record that doddns tries to update.
27+
- `doddns records:add`: add a record to update to the database from exiting DO domains.
28+
- `doddns records:remove`: removes a record from doddns' database.
29+
- `doddns records:update`: updates records in database with actual IP.

app/Commands/AddRecord.php

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
namespace App\Commands;
4+
5+
use App\Helpers\DigitalOceanHelper;
6+
use App\Helpers\SettingsHelper;
7+
use Illuminate\Console\Scheduling\Schedule;
8+
use Illuminate\Support\Facades\DB;
9+
use LaravelZero\Framework\Commands\Command;
10+
11+
class AddRecord extends Command
12+
{
13+
/**
14+
* The signature of the command.
15+
*
16+
* @var string
17+
*/
18+
protected $signature = 'records:add';
19+
20+
/**
21+
* The description of the command.
22+
*
23+
* @var string
24+
*/
25+
protected $description = 'Set which records to update.';
26+
27+
protected $settings;
28+
protected $token;
29+
30+
private $digitalocean;
31+
32+
/**
33+
* Execute the console command.
34+
*
35+
* @return mixed
36+
*/
37+
public function handle()
38+
{
39+
$this->settings = new SettingsHelper();
40+
41+
if ($this->settings->error !== null) {
42+
$this->error($this->settings->error);
43+
return;
44+
}
45+
46+
$this->digitalocean = new DigitalOceanHelper($this->settings->getToken());
47+
48+
$domains = collect($this->digitalocean->domain->getAll())->mapWithKeys(function ($values) {
49+
return [$values->name => $values->name];
50+
})->toArray();
51+
52+
$selected_domain = $this->menu("Which domain?", $domains)->open();
53+
54+
if ($selected_domain === null) {
55+
$this->info("Nothing selected. Exiting.");
56+
return;
57+
}
58+
59+
$records = collect($this->digitalocean->domainRecord->getAll($selected_domain))->filter(function ($record) {
60+
return $record->type == "CNAME" || $record->type == "A";
61+
});
62+
63+
$records_for_menu = $records->mapWithKeys(function ($values, $key) {
64+
return [$key => "{$values->name} ({$values->type}): {$values->data}"];
65+
})->toArray();
66+
67+
$selected_record = $this->menu("Which record?", $records_for_menu)->open();
68+
69+
if ($selected_record === null) {
70+
$this->info("Nothing selected. Exiting.");
71+
return;
72+
}
73+
74+
DB::table('records')->insert(
75+
['domain' => $selected_domain,
76+
'record_id' => $records[$selected_record]->id,
77+
'record_name' => $records[$selected_record]->name,
78+
'record_type' => $records[$selected_record]->type]
79+
);
80+
81+
$this->info("Record {$records[$selected_record]->name} for domain {$selected_domain} will be updated on the next cycle.");
82+
}
83+
}

app/Commands/InspiringCommand.php

-44
This file was deleted.

app/Commands/ListRecords.php

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace App\Commands;
4+
5+
use Illuminate\Console\Scheduling\Schedule;
6+
use Illuminate\Support\Facades\DB;
7+
use LaravelZero\Framework\Commands\Command;
8+
9+
class ListRecords extends Command
10+
{
11+
/**
12+
* The signature of the command.
13+
*
14+
* @var string
15+
*/
16+
protected $signature = 'records:list';
17+
18+
/**
19+
* The description of the command.
20+
*
21+
* @var string
22+
*/
23+
protected $description = 'Display a list of records we update each cycles.';
24+
25+
/**
26+
* Execute the console command.
27+
*
28+
* @return mixed
29+
*/
30+
public function handle()
31+
{
32+
$records = DB::table('records')->get();
33+
34+
$records->each(function ($record, $key) {
35+
$this->line("");
36+
$this->info("[{$key}] ({$record->record_type}) {$record->record_name} of {$record->domain}");
37+
});
38+
}
39+
}

app/Commands/RemoveRecord.php

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace App\Commands;
4+
5+
use Illuminate\Console\Scheduling\Schedule;
6+
use Illuminate\Support\Facades\DB;
7+
use LaravelZero\Framework\Commands\Command;
8+
9+
class RemoveRecord extends Command
10+
{
11+
/**
12+
* The signature of the command.
13+
*
14+
* @var string
15+
*/
16+
protected $signature = 'records:remove';
17+
18+
/**
19+
* The description of the command.
20+
*
21+
* @var string
22+
*/
23+
protected $description = 'Remove a record from the update cycle.';
24+
25+
/**
26+
* Execute the console command.
27+
*
28+
* @return mixed
29+
*/
30+
public function handle()
31+
{
32+
$records = DB::table('records')->get();
33+
$records_for_menu = collect($records)->mapWithKeys(function ($record) {
34+
return [$record->id => "({$record->record_type}) {$record->record_name} of {$record->domain}"];
35+
})->toArray();
36+
37+
$record_to_remove = $this->menu("Which record to delete?", $records_for_menu)->open();
38+
39+
if ($record_to_remove === null) {
40+
$this->info("Nothing selected. Exiting.");
41+
return;
42+
}
43+
44+
DB::table('records')->where('id', '=', $record_to_remove)->delete();
45+
46+
$this->info("Removed!");
47+
}
48+
}

app/Commands/Setup.php

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
namespace App\Commands;
4+
5+
use App\Helpers\SettingsHelper;
6+
use Illuminate\Console\Scheduling\Schedule;
7+
use Illuminate\Support\Facades\Artisan;
8+
use Illuminate\Support\Facades\DB;
9+
use LaravelZero\Framework\Commands\Command;
10+
use Storage;
11+
12+
class Setup extends Command
13+
{
14+
/**
15+
* The signature of the command.
16+
*
17+
* @var string
18+
*/
19+
protected $signature = 'setup';
20+
21+
/**
22+
* The description of the command.
23+
*
24+
* @var string
25+
*/
26+
protected $description = 'Well... It sets things up.';
27+
28+
private $settings;
29+
30+
/**
31+
* Execute the console command.
32+
*
33+
* @return mixed
34+
*/
35+
public function handle()
36+
{
37+
if ($this->confirm("This will destroy any existing doddns configuration. Is that ok?")) {
38+
$this->task("Creating local database", function () {
39+
if (!is_dir($_SERVER['HOME'].'/.doddns/')) {
40+
mkdir($_SERVER['HOME'].'/.doddns/', 0700);
41+
$this->info("Created .doddns directory in user's home.");
42+
}
43+
44+
file_put_contents(config('database.connections.sqlite.database'), "");
45+
$this->info("Created or overwrited any actual databse");
46+
47+
Artisan::call('migrate', ['--force' => true]);
48+
49+
$this->info("Migrated tables");
50+
51+
return true;
52+
});
53+
}
54+
55+
$this->settings = new SettingsHelper();
56+
57+
$token = $this->ask("What is your Digital Ocean peronal access token?");
58+
59+
if ($this->settings->error !== null) {
60+
$this->insertToken($token);
61+
} else {
62+
$this->updateToken($token);
63+
}
64+
65+
$this->info("All done! We're good to go!");
66+
}
67+
68+
private function updateToken($token)
69+
{
70+
if ($this->confirm('Do you wish to overwrite existing saved token?')) {
71+
DB::table('settings')->update(
72+
['token' => $token]
73+
);
74+
}
75+
76+
$this->info("Token updated!");
77+
}
78+
79+
private function insertToken($token)
80+
{
81+
DB::table('settings')->insert(
82+
['token' => $token]
83+
);
84+
85+
$this->info("Token added!");
86+
}
87+
}

0 commit comments

Comments
 (0)