示例#1
0
 /**
  * Update the specified DNS Record of Zone in storage.
  *
  * @param Zone $zone
  * @param DnsRecord $dns
  * @param DnsRequest $request
  * @return Response
  */
 public function updateDns(Zone $zone, DnsRecord $dns, DnsRequest $request)
 {
     try {
         $datas = $request->except(['_token']);
         if ('@' === $datas['name']) {
             $datas['name'] = $zone->name;
         } else {
             if (strpos($request->name, '.') !== false) {
                 return back()->withInput()->withErrors([trans('admin.error.unknown_error')]);
             }
         }
         $cfDns = Cloudflare::updateDnsRecord($zone, $dns->cf_id, $datas);
         $updateDns = $request->except(['_token']);
         $updateDns['name'] = $datas['name'];
         $this->dnsRepository->update($updateDns, $dns->id);
         $dnsName = $this->dnsRepository->findByNameAndZone($dns->name, $zone);
         if (count($dnsName) > 1) {
             // if dnsName > 1 and exists in blacklist domain then delete
             $isBlacklisted = $this->blacklistRepository->findOneByNameAndZone($dns->name, $zone);
             if ($isBlacklisted) {
                 $this->blacklistRepository->delete($isBlacklisted->id);
             }
         }
         return redirect($this->route('zone.edit', ['zone' => $zone->id]))->with('success', $this->returnMessage('update', 'dns'));
     } catch (CloudflareException $e) {
         return back()->withInput()->withErrors([$e->getCode() . ' - ' . trans($e->getMessage())]);
     } catch (\Exceptions $e) {
         return back()->withInput()->withErrors([trans('admin.error.unknown_error')]);
     }
 }
 /**
  * Update the specified DNS Record for Domain in storage.
  * @param string $domainName
  * @param DnsRequest $request
  * @param int $id
  * @return Response
  */
 public function postUpdateDns($domainName, DnsRequest $request, $id)
 {
     // validate domain name
     $domain = Domain::isDomainValid($domainName);
     if (false === $domain) {
         abort(404);
     }
     // validate dns
     $dns = $this->dnsRepository->isValidDns($domain, $id);
     if (is_null($dns)) {
         abort(404);
     }
     try {
         $datas = $request->except(['_token', '_method']);
         if ('@' === $datas['name']) {
             $datas['name'] = $domainName;
         } else {
             $datas['name'] .= '.' . $domainName;
         }
         $cfDns = Cloudflare::updateDnsRecord($domain->zone, $dns->cf_id, $datas);
         $dnsUpdate = $request->except(['_token', '_method']);
         $dnsUpdate['name'] = $datas['name'];
         $this->dnsRepository->update($dnsUpdate, $id);
         return redirect(route('user.domain.manage', ['domainName' => $domainName]))->with('success', trans('front.dns.success_update'));
     } catch (CloudflareException $e) {
         return back()->withErrors([$e->getCode() . ' - ' . trans($e->getMessage())]);
     } catch (\Exceptions $e) {
         return back()->withErrors([trans('front.error.please_contact_admin')]);
     }
 }