WIP
This commit is contained in:
@@ -2,12 +2,12 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\SiteDnsRequest;
|
||||
use App\Models\Site;
|
||||
use Illuminate\Support\Arr;
|
||||
use App\Models\UserProvider;
|
||||
use App\Services\Cloudflare;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Requests\SiteDnsRequest;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class SiteDnsController extends Controller
|
||||
{
|
||||
@@ -27,17 +27,34 @@ class SiteDnsController extends Controller
|
||||
|
||||
$dns = $this->getDnsInstance($site);
|
||||
|
||||
$state = Arr::only($request->validated(), ['name', 'content']);
|
||||
|
||||
$dns->addRecord(
|
||||
$request->input('name'),
|
||||
$request->input('address'),
|
||||
name: $state['name'],
|
||||
content: $state['content'],
|
||||
);
|
||||
|
||||
return redirect()->route('sites.dns.index', $id)->with('success', __('DNS record has been created'));
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
public function update($id, $recordId, SiteDnsRequest $request): RedirectResponse
|
||||
{
|
||||
//
|
||||
$site = auth()->user()->sites()->findOrFail($id);
|
||||
|
||||
$state = $request->validated();
|
||||
|
||||
$dns = $this->getDnsInstance($site);
|
||||
|
||||
$success = $dns->updateRecord($recordId, [
|
||||
'name' => $state['name'],
|
||||
'content' => $state['content'],
|
||||
]);
|
||||
|
||||
if (is_bool($success) && ! $success) {
|
||||
return redirect()->route('sites.dns.index', $id)->with('error', __('Error updating DNS record'));
|
||||
}
|
||||
|
||||
return redirect()->route('sites.dns.index', $id)->with('success', __('DNS record saved'));
|
||||
}
|
||||
|
||||
public function records($id)
|
||||
|
||||
@@ -28,10 +28,10 @@ class SiteDnsRequest extends FormRequest
|
||||
'required',
|
||||
'string',
|
||||
],
|
||||
'address' => [
|
||||
'content' => [
|
||||
'required',
|
||||
'ipv4'
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,14 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Cloudflare\API\Adapter\Guzzle;
|
||||
use Cloudflare\API\Auth\APIKey;
|
||||
use Cloudflare\API\Endpoints\DNS;
|
||||
use Cloudflare\API\Endpoints\User;
|
||||
use Cloudflare\API\Endpoints\Zones;
|
||||
use GuzzleHttp\Exception\ClientException;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Cloudflare
|
||||
{
|
||||
@@ -12,13 +18,13 @@ class Cloudflare
|
||||
|
||||
public function __construct($email, $key)
|
||||
{
|
||||
$key = new \Cloudflare\API\Auth\APIKey($email, $key);
|
||||
$this->adapter = new \Cloudflare\API\Adapter\Guzzle($key);
|
||||
$key = new APIKey($email, $key);
|
||||
$this->adapter = new Guzzle($key);
|
||||
}
|
||||
|
||||
public function domains($match = '')
|
||||
{
|
||||
$zones = new \Cloudflare\API\Endpoints\Zones($this->adapter);
|
||||
$zones = new Zones($this->adapter);
|
||||
|
||||
return collect(object_get($zones->listZones($match), 'result'));
|
||||
}
|
||||
@@ -32,7 +38,7 @@ class Cloudflare
|
||||
|
||||
public function listRecords($page = 1, $perPage = 50, $order = '', $direction = '', $type = '', $name = '', $content = '', $match = 'all')
|
||||
{
|
||||
$dns = new \Cloudflare\API\Endpoints\DNS($this->adapter);
|
||||
$dns = new DNS($this->adapter);
|
||||
|
||||
if (!$dns || !$this->zoneId) {
|
||||
return null;
|
||||
@@ -65,7 +71,7 @@ class Cloudflare
|
||||
$content = $_SERVER['SERVER_ADDR'];
|
||||
}
|
||||
|
||||
$dns = new \Cloudflare\API\Endpoints\DNS($this->adapter);
|
||||
$dns = new DNS($this->adapter);
|
||||
|
||||
try {
|
||||
return $dns->addRecord($this->zoneId, $type, $name, $content, $ttl, $proxied, $priority);
|
||||
@@ -76,7 +82,7 @@ class Cloudflare
|
||||
|
||||
public function getRecordByValues($name, $type)
|
||||
{
|
||||
$dns = new \Cloudflare\API\Endpoints\DNS($this->adapter);
|
||||
$dns = new DNS($this->adapter);
|
||||
|
||||
try {
|
||||
return $dns->getRecordID($this->zoneId, $type, $name);
|
||||
@@ -87,7 +93,7 @@ class Cloudflare
|
||||
|
||||
public function deleteRecord($id)
|
||||
{
|
||||
$dns = new \Cloudflare\API\Endpoints\DNS($this->adapter);
|
||||
$dns = new DNS($this->adapter);
|
||||
|
||||
try {
|
||||
return $dns->deleteRecord($this->zoneId, $id);
|
||||
@@ -98,15 +104,15 @@ class Cloudflare
|
||||
|
||||
public function updateRecord($id, array $data = [])
|
||||
{
|
||||
$dns = new \Cloudflare\API\Endpoints\DNS($this->adapter);
|
||||
$dns = new DNS($this->adapter);
|
||||
|
||||
try {
|
||||
$record = $dns->getRecordDetails($this->zoneId, $id);
|
||||
|
||||
return $dns->updateRecordDetails($this->zoneId, $id, [
|
||||
'type' => object_get($record, 'type'),
|
||||
'name' => array_get($data, 'name'),
|
||||
'content' => array_get($data, 'content'),
|
||||
'name' => Arr::get($data, 'name'),
|
||||
'content' => Arr::get($data, 'content'),
|
||||
]);
|
||||
} catch (ClientException $e) {
|
||||
return false;
|
||||
@@ -115,7 +121,7 @@ class Cloudflare
|
||||
|
||||
public function toggleProxy($id)
|
||||
{
|
||||
$dns = new \Cloudflare\API\Endpoints\DNS($this->adapter);
|
||||
$dns = new DNS($this->adapter);
|
||||
|
||||
try {
|
||||
$record = $dns->getRecordDetails($this->zoneId, $id);
|
||||
@@ -133,7 +139,7 @@ class Cloudflare
|
||||
|
||||
public function user()
|
||||
{
|
||||
$user = new \Cloudflare\API\Endpoints\User($this->adapter);
|
||||
$user = new User($this->adapter);
|
||||
|
||||
return $user->getUserDetails();
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<template #form>
|
||||
<form class="space-y-4" @submit.prevent="submit">
|
||||
<FormInput :disabled="sending" :label="__('Name')" :errors="$page.props.errors.name" v-model="form.name"/>
|
||||
<FormInput :disabled="sending" :label="__('IPv4 address')" :errors="$page.props.errors.address" v-model="form.address"/>
|
||||
<FormInput :disabled="sending" :label="__('IPv4 address')" :errors="$page.props.errors.content" v-model="form.content"/>
|
||||
|
||||
<FormActions>
|
||||
<Button>{{ __('Save') }}</Button>
|
||||
@@ -56,10 +56,16 @@
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
<TableRow v-for="record in records" :key="record.id">
|
||||
<TableData>{{ record.name }}</TableData>
|
||||
<TableData>{{ record.display_content }}</TableData>
|
||||
<TableRow v-for="(record, index) in records" :key="record.id" class="px-2">
|
||||
<TableData>
|
||||
<Input :value="record.name" type="text" :id="index + 'x'" onkeyup="window.Vue.set(this.records, index, this.value)" />
|
||||
<p v-text="records[index].name" />
|
||||
</TableData>
|
||||
<TableData>
|
||||
<Input v-model="records[index].content" type="text" id="TODO" />
|
||||
</TableData>
|
||||
<TableData>
|
||||
<Button @click="save(record, index)" variant="primary" size="sm">Save</Button>
|
||||
<Button @click="confirmDelete(record)" variant="danger" size="sm">Delete</Button>
|
||||
</TableData>
|
||||
</TableRow>
|
||||
@@ -78,37 +84,38 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import TopBar from './components/TopBar'
|
||||
import Container from '@/components/Container'
|
||||
import Content from '@/components/Content'
|
||||
import Page from '@/components/Page'
|
||||
import PageHeader from '@/components/PageHeader'
|
||||
import PageHeaderTitle from '@/components/PageHeaderTitle'
|
||||
import PageBody from '@/components/PageBody'
|
||||
import Button from '@/components/Button'
|
||||
import List from '@/components/List'
|
||||
import ListItem from '@/components/ListItem'
|
||||
import StatusBubble from '@/components/StatusBubble'
|
||||
import NotificationBadge from '@/components/NotificationBadge'
|
||||
import MainLayout from '@/Layouts/MainLayout'
|
||||
import SettingsLayout from '@/components/layouts/SettingsLayout'
|
||||
import SettingsSegment from '@/components/SettingsSegment'
|
||||
import FormInput from '@/components/forms/FormInput'
|
||||
import Form from '@/components/Form'
|
||||
import Pagination from '@/components/Pagination'
|
||||
import FormActions from '@/components/FormActions'
|
||||
import {useConfirm} from '@/hooks/confirm'
|
||||
import {useNotification} from '@/hooks/notification'
|
||||
import Tabs from './Tabs'
|
||||
import Table from '@/components/Table'
|
||||
import TableHead from '@/components/TableHead'
|
||||
import TableHeader from '@/components/TableHeader'
|
||||
import TableRow from '@/components/TableRow'
|
||||
import TableBody from '@/components/TableBody'
|
||||
import TableData from '@/components/TableData'
|
||||
import EmptyImage from '@/components/EmptyImage'
|
||||
import TopBar from './components/TopBar'
|
||||
import Container from '@/components/Container'
|
||||
import Content from '@/components/Content'
|
||||
import Page from '@/components/Page'
|
||||
import PageHeader from '@/components/PageHeader'
|
||||
import PageHeaderTitle from '@/components/PageHeaderTitle'
|
||||
import PageBody from '@/components/PageBody'
|
||||
import Button from '@/components/Button'
|
||||
import List from '@/components/List'
|
||||
import ListItem from '@/components/ListItem'
|
||||
import StatusBubble from '@/components/StatusBubble'
|
||||
import NotificationBadge from '@/components/NotificationBadge'
|
||||
import MainLayout from '@/Layouts/MainLayout'
|
||||
import SettingsLayout from '@/components/layouts/SettingsLayout'
|
||||
import SettingsSegment from '@/components/SettingsSegment'
|
||||
import FormInput from '@/components/forms/FormInput'
|
||||
import Form from '@/components/Form'
|
||||
import Pagination from '@/components/Pagination'
|
||||
import FormActions from '@/components/FormActions'
|
||||
import {useConfirm} from '@/hooks/confirm'
|
||||
import {useNotification} from '@/hooks/notification'
|
||||
import Tabs from './Tabs'
|
||||
import Table from '@/components/Table'
|
||||
import TableHead from '@/components/TableHead'
|
||||
import TableHeader from '@/components/TableHeader'
|
||||
import TableRow from '@/components/TableRow'
|
||||
import TableBody from '@/components/TableBody'
|
||||
import TableData from '@/components/TableData'
|
||||
import EmptyImage from '@/components/EmptyImage'
|
||||
import Input from "../../components/Input";
|
||||
|
||||
export default {
|
||||
export default {
|
||||
metaInfo() {
|
||||
return {
|
||||
title: `${this.__('DNS')} - ${this.site.domain}`,
|
||||
@@ -118,6 +125,7 @@
|
||||
layout: MainLayout,
|
||||
|
||||
components: {
|
||||
Input,
|
||||
TopBar,
|
||||
Container,
|
||||
Content,
|
||||
@@ -153,9 +161,11 @@
|
||||
|
||||
records: [],
|
||||
|
||||
recordUpdateValidationMessages: {},
|
||||
|
||||
form: {
|
||||
name: null,
|
||||
address: null,
|
||||
content: null,
|
||||
},
|
||||
|
||||
breadcrumbs: [
|
||||
@@ -200,13 +210,17 @@
|
||||
|
||||
this.form = {
|
||||
name: null,
|
||||
address: null,
|
||||
content: null,
|
||||
};
|
||||
}
|
||||
})
|
||||
|
||||
},
|
||||
|
||||
updateRecordName(event, index) {
|
||||
alert(event.target.value, index);
|
||||
},
|
||||
|
||||
getRecords() {
|
||||
this.loading = true;
|
||||
|
||||
@@ -214,12 +228,22 @@
|
||||
.then(response => {
|
||||
this.loading = false;
|
||||
this.records = response.data
|
||||
})
|
||||
g})
|
||||
.catch(error => {
|
||||
this.loading = false;
|
||||
})
|
||||
},
|
||||
|
||||
save(record) {
|
||||
this.$inertia.put(this.route('sites.dns.update', [this.site.id, record.id]), {
|
||||
name: record.name,
|
||||
content: record.content,
|
||||
}, {
|
||||
preserveScroll: true,
|
||||
onStart: () => this.sending = true,
|
||||
});
|
||||
},
|
||||
|
||||
confirmDelete(record) {
|
||||
useConfirm({
|
||||
title: this.__('Are you sure?'),
|
||||
|
||||
@@ -81,6 +81,8 @@
|
||||
"Create site": "Site toevoegen",
|
||||
"DNS settings": "DNS instellingen",
|
||||
"DNS settings for aliases": "DNS instellingen voor aliasen",
|
||||
"DNS record saved": "DNS record opgeslagen",
|
||||
"Error updating DNS record": "Fout met updaten DNS record",
|
||||
"View site": "Bekijk website",
|
||||
"Start installation": "Start installatie",
|
||||
"Install WordPress": "Installeer WordPress",
|
||||
|
||||
@@ -29,7 +29,8 @@ Route::group(['middleware' => ['auth', 'auth.blocked']], function () {
|
||||
|
||||
// Site routes
|
||||
Route::group(['prefix' => 'sites', 'as' => 'sites.'], function () {
|
||||
Route::get('/', 'SiteController@index')->name('index');
|
||||
Route::get('/', 'SiteControl
|
||||
ler@index')->name('index');
|
||||
Route::get('{site}', 'SiteController@show')->name('show');
|
||||
Route::delete('{site}', 'SiteController@destroy')->name('delete');
|
||||
Route::post('/', 'SiteController@store')->name('store');
|
||||
@@ -87,6 +88,7 @@ Route::group(['middleware' => ['auth', 'auth.blocked']], function () {
|
||||
Route::get('records', 'SiteDnsController@records')->name('records');
|
||||
Route::post('/', 'SiteDnsController@store')->name('store');
|
||||
Route::delete('{record}', 'SiteDnsController@destroy')->name('delete');
|
||||
Route::put('{record}', 'SiteDnsController@update')->name('update');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user