tmpl = new Template('/openprovider/'); $this->auth = new Auth(); $this->user = $this->auth->getLoggedInUser(); if ($this->user && $this->user->role & (Roles::ADMIN)) { $this->op = new Openprovider(); $this->op->login(); } $this->tmpl->assign('user', $this->user); $this->tmpl->assign('curPage', 'openprovider'); $this->tmpl->assign('custCss', false); $this->tmpl->assign('menu', $this->getMenu()); $this->tmpl->assign('description', $this->description); $this->tmpl->addCss('openprovider'); $this->tmpl->addCss('table'); } public function index(array $params): void { try { $this->pagetit .= 'ホーム'; $this->tmpl->assign('pagetit', $this->pagetit); if (!$this->user || !($this->user->role & Roles::ADMIN)) goto noaccess; $data = $this->op->getReseller(['with_statistics' => true]); $domain = $this->op->listDomains(['order_by.renewal_date' => 'asc', 'status' => 'ACT']); $this->tmpl->assign('data', $data->data); $this->tmpl->assign('domain', $domain->data); $this->tmpl->render('index'); exit(); noaccess: $this->tmpl->render('nopermission'); } catch (\Exception $e) { throw new \Exception($e->getMessage()); } } public function opListInvoices(array $params): void { try { $this->pagetit .= '請求書一覧'; $this->tmpl->assign('pagetit', $this->pagetit); if (!$this->user || !($this->user->role & Roles::ADMIN)) goto noaccess; $data = $this->op->listInvoices(); $this->tmpl->assign('data', $data->data); $this->tmpl->render('listinvoices'); exit(); noaccess: $this->tmpl->render('nopermission'); } catch (\Exception $e) { throw new \Exception($e->getMessage()); } } public function opListPayments(array $params): void { try { $this->pagetit .= '請求書一覧'; $this->tmpl->assign('pagetit', $this->pagetit); if (!$this->user || !($this->user->role & Roles::ADMIN)) goto noaccess; $data = $this->op->listPayments(); $this->tmpl->assign('data', $data->data); $this->tmpl->render('listpayments'); exit(); noaccess: $this->tmpl->render('nopermission'); } catch (\Exception $e) { throw new \Exception($e->getMessage()); } } public function opListTransactions(array $params): void { try { $this->pagetit .= '請求書一覧'; $this->tmpl->assign('pagetit', $this->pagetit); if (!$this->user || !($this->user->role & Roles::ADMIN)) goto noaccess; $data = $this->op->listTransactions(); $this->tmpl->assign('data', $data->data); $this->tmpl->render('listtransactions'); exit(); noaccess: $this->tmpl->render('nopermission'); } catch (\Exception $e) { throw new \Exception($e->getMessage()); } } public function opListCustomers(array $params): void { try { $this->pagetit .= '顧客様検索'; $this->tmpl->assign('pagetit', $this->pagetit); if (!$this->user || !($this->user->role & Roles::ADMIN)) goto noaccess; $data = $this->op->listCustomers(); $this->tmpl->assign('data', $data->data); $this->tmpl->render('listcustomers'); exit(); noaccess: $this->tmpl->render('nopermission'); } catch (\Exception $e) { throw new \Exception($e->getMessage()); } } public function opCreateCustomer(array $params): void { try { $payload = [ 'additional_data' => [ 'company_registration_number' => $_POST['company_registration_number'] ?? '', 'company_url' => $_POST['company_url'] ?? '', 'birth_date' => (isset($_POST['birth_year']) && $_POST['birth_year'] !== '') && (isset($_POST['birth_month']) && $_POST['birth_month'] !== '') && (isset($_POST['birth_day']) && $_POST['birth_day'] !== '') ? $_POST['birth_year'].'-'.$_POST['birth_month'].'-'.$_POST['birth_day'] : '', 'trading_name' => $_POST['company_name'] ?? '', ], 'address' => [ 'city' => $_POST['address_city'] ?? '', 'country' => $_POST['address_country'] ?? 'JP', 'number' => $_POST['address_number'] ?? '', 'state' => $_POST['address_state'] ?? '', 'street' => $_POST['address_street'] ?? '', 'zipcode' => $_POST['address_zipcode'] ?? '', ], 'birth' => [ 'year' => $_POST['birth_year'] ?? '', 'month' => $_POST['birth_month'] ?? '', 'day' => $_POST['birth_day'] ?? '', ], 'comments' => $_POST['comments'] ?? '', 'company_name' => $_POST['company_name'] ?? '', 'email' => $_POST['email'] ?? '', 'fax' => [ 'area_code' => $_POST['fax_area_code'] ?? '', 'country_code' => $_POST['fax_country_code'] ?? '', 'subscriber_number' => $_POST['fax_subscriber_number'] ?? '', ], 'locale' => 'ja_JP', 'name' => [ 'first_name' => $_POST['first_name'] ?? '', 'full_name' => (isset($_POST['first_name']) && $_POST['first_name'] !== '') && (isset($_POST['last_name']) && $_POST['last_name'] !== '') ? $_POST['first_name'].' '.$_POST['last_name'] : '', 'last_name' => $_POST['last_name'] ?? '', ], 'phone' => [ 'area_code' => $_POST['phone_area_code'] ?? '', 'country_code' => $_POST['phone_country_code'] ?? '', 'subscriber_number' => $_POST['phone_subscriber_number'] ?? '', ], ]; $this->pagetit .= '顧客様の新規作成'; $this->tmpl->assign('pagetit', $this->pagetit); $err = []; if (!$this->user || !($this->user->role & Roles::ADMIN)) goto noaccess; if (!empty($_POST)) { if (NULL === $_POST['last_name'] || $_POST['last_name'] === '' || NULL === $_POST['first_name'] || $_POST['first_name'] === '') $err[] = '姓名をご入力下さい。'; if (NULL === $_POST['phone_country_code'] || $_POST['phone_country_code'] === '' || NULL === $_POST['phone_area_code'] || $_POST['phone_area_code'] === '' || NULL === $_POST['phone_subscriber_number'] || $_POST['phone_subscriber_number'] === '') $err[] = '電話番号をご入力下さい。'; if (NULL === $_POST['email'] || $_POST['email'] === '') $err[] = 'メールアドレスをご入力下さい。'; if (NULL === $_POST['address_zipcode'] || $_POST['address_zipcode'] === '') $err[] = '郵便番号をご入力下さい。'; if (NULL === $_POST['address_state'] || $_POST['address_state'] === '') $err[] = '都道府県をご入力下さい。'; if (NULL === $_POST['address_city'] || $_POST['address_city'] === '') $err[] = '市区町村をご入力下さい。'; if (NULL === $_POST['address_street'] || $_POST['address_street'] === '') $err[] = '町名をご入力下さい。'; if (NULL === $_POST['address_number'] || $_POST['address_number'] === '') $err[] = '番地をご入力下さい。'; if (!empty($err)) goto render; if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) $err[] = 'メールアドレスは不正です。'; if (!str_starts_with($_POST['phone_country_code'], '+')) $err[] = '電話番号の国コードは「+」ご始まり下さい。'; if ($_POST['fax_country_code'] !== '' && !str_starts_with($_POST['fax_country_code'], '+')) $err[] = 'FAXの国コードは「+」ご始まり下さい。'; if ((!filter_var($_POST['phone_area_code'], FILTER_VALIDATE_INT)) || (!filter_var($_POST['phone_subscriber_number'], FILTER_VALIDATE_INT))) $err[] = '電話番号は数字をご入力下さい。'; if (($_POST['fax_area_code'] !== '' || $_POST['fax_subscriber_number'] !== '') && (!filter_var($_POST['fax_area_code'], FILTER_VALIDATE_INT) || !filter_var($_POST['fax_subscriber_number'], FILTER_VALIDATE_INT))) $err[] = 'FAXは数字をご入力下さい。'; if (!empty($err)) goto render; $data = $this->op->createCustomer($payload, true); header("Location: /openprovider/getcustomer/{$data->data['data']['handle']}"); exit(); } render: $this->tmpl->assign('err', $err); $this->tmpl->assign('data', $payload); $this->tmpl->render('createcustomer'); exit(); noaccess: $this->tmpl->render('nopermission'); } catch (\Exception $e) { throw new \Exception($e->getMessage()); } } public function opGetCustomer(array $params): void { try { $handle = ''; if (isset($params['handle'])) $handle = $params['handle']; if (!$this->isValidHandle($handle)) { header('Location: /openprovider/listcustomers'); exit(); } $this->pagetit .= "顧客様「{$handle}」の表示"; $this->tmpl->assign('pagetit', $this->pagetit); if (!$this->user || !($this->user->role & Roles::ADMIN)) goto noaccess; $data = $this->op->getCustomer($handle, true); $this->tmpl->assign('data', $data->data); $this->tmpl->render('getcustomer'); exit(); noaccess: $this->tmpl->render('nopermission'); } catch (\Exception $e) { throw new \Exception($e->getMessage()); } } public function opDeleteCustomer(array $params): void { try { $handle = ''; if (isset($params['handle'])) $handle = $params['handle']; if (!$this->isValidHandle($handle)) { header('Location: /openprovider/listcustomers'); exit(); } assert_not_null($handle); $this->pagetit .= "顧客様「{$handle}」の表示"; $this->tmpl->assign('pagetit', $this->pagetit); if (!$this->user || !($this->user->role & Roles::ADMIN)) goto noaccess; if (empty($_POST)) goto render_confirm; if (isset($_POST['delete_reject'])) { header("Location: /openprovider/getcustomer/{$handle}"); exit(); } else if (isset($_POST['delete_confirm'])) { $this->op->deleteCustomer($handle); } header('Location: /openprovider/listcustomers'); exit(); render_confirm: $this->tmpl->assign('handle', $handle); $this->tmpl->render('deletecustomer'); exit(); noaccess: $this->tmpl->render('nopermission'); } catch (\Exception $e) { throw new \Exception($e->getMessage()); } } public function opListTlds(array $params): void { try { $this->pagetit .= 'TLD一覧'; $this->tmpl->assign('pagetit', $this->pagetit); if (!$this->user || !($this->user->role & Roles::ADMIN)) goto noaccess; $data = $this->op->listTlds(); $this->tmpl->assign('data', $data->data); $this->tmpl->render('listtlds'); exit(); noaccess: $this->tmpl->render('nopermission'); } catch (\Exception $e) { throw new \Exception($e->getMessage()); } } public function opGetTld(array $params): void { try { $tld = ''; if (isset($params['tld'])) $tld = $params['tld']; if (!preg_match('/^[A-Za-z0-9-]{1,63}$/', $tld)) { header('Location: /'); exit(); } $this->pagetit .= "{$tld}の表示"; $this->tmpl->assign('pagetit', $this->pagetit); if (!$this->user || !($this->user->role & Roles::ADMIN)) goto noaccess; $data = $this->op->getTld($tld); $this->tmpl->assign('data', $data->data); $this->tmpl->render('gettld'); exit(); noaccess: $this->tmpl->render('nopermission'); } catch (\Exception $e) { throw new \Exception($e->getMessage()); } } public function opListDomains(array $params): void { try { $this->pagetit .= 'ドメイン確認'; $this->tmpl->assign('pagetit', $this->pagetit); if (!$this->user || !($this->user->role & Roles::ADMIN)) goto noaccess; $data = $this->op->listDomains($domains, true); $this->tmpl->assign('data', $data->data); $this->tmpl->render('checkdomain'); exit(); noaccess: $this->tmpl->render('nopermission'); } catch (\Exception $e) { throw new \Exception($e->getMessage()); } } public function opCheckDomainAvailable(array $params): void { try { $domains = isset($_GET['domains']) ? explode("\n", $_GET['domains']) : []; $saved = ''; $this->pagetit .= 'ドメイン確認'; $this->tmpl->assign('pagetit', $this->pagetit); if (!$this->user || !($this->user->role & Roles::ADMIN)) goto noaccess; if (!empty($domains)) { $data = $this->op->checkDomainAvailable($domains, true); $this->tmpl->assign('data', $data->data); $saved = $_GET['domains']; } $this->tmpl->assign('saved', $saved); $this->tmpl->render('checkdomain'); exit(); noaccess: $this->tmpl->render('nopermission'); } catch (\Exception $e) { throw new \Exception($e->getMessage()); } } public function opGetDomainPrices(array $params): void { try { $domainname = $_GET['domain_name'] ?? ''; $domainext = $_GET['domain_extension'] ?? ''; $this->pagetit .= 'ドメイン値段一覧'; $this->tmpl->assign('pagetit', $this->pagetit); if (!$this->user || !($this->user->role & Roles::ADMIN)) goto noaccess; $data = $this->op->getDomainPrices(['domain.name' => $domainname, 'domain.extension' => $domainext]); $this->tmpl->assign('data', $data->data); $this->tmpl->render('getdomainprices'); exit(); noaccess: $this->tmpl->render('nopermission'); } catch (\Exception $e) { throw new \Exception($e->getMessage()); } } public function opListDns(array $params): void { try { $this->pagetit .= 'DNS一覧'; $this->tmpl->assign('pagetit', $this->pagetit); if (!$this->user || !($this->user->role & Roles::ADMIN)) goto noaccess; $data = $this->op->listDnsZones(); $this->tmpl->assign('data', $data->data); $this->tmpl->render('listdnszones'); exit(); noaccess: $this->tmpl->render('nopermission'); } catch (\Exception $e) { throw new \Exception($e->getMessage()); } } public function opGetDns(array $params): void { try { $domain = ''; if (isset($params['domain'])) $domain = $params['domain']; if (!preg_match('/^(?=.{1,253}$)(?:[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?\.)+[A-Za-z0-9-]{2,63}$/', $domain)) { header('Location: /'); exit(); } $this->pagetit .= "{$domain}のDNS管理"; $this->tmpl->assign('pagetit', $this->pagetit); if (!$this->user || !($this->user->role & Roles::ADMIN)) goto noaccess; $data = ['rec' => $this->op->listZoneRecords($domain), 'zone' => $this->op->getDnsZone($domain)]; $this->tmpl->assign('data', $data->data); $this->tmpl->render('getdns'); exit(); noaccess: $this->tmpl->render('nopermission'); } catch (\Exception $e) { throw new \Exception($e->getMessage()); } } ////////// /** * 顧客ハンドルの形式を確認する(例:AB123456-XX) * URLの値はAPIのパスとキャッシュのファイル名にそのまま入るので、先に確認する * * @param string $handle 顧客ハンドル * @return bool 正しい形式ならtrue */ private function isValidHandle(string $handle): bool { return preg_match('/^[A-Za-z0-9-]{1,64}$/', $handle) === 1; } }