Explorar el Código

新增托管账户域名的同步和本地缓存机制

Jackson Dou hace 2 años
padre
commit
3df3d25422

+ 1 - 1
src/admin/accounts.php

@@ -4,7 +4,7 @@ require_once __DIR__ . '/application.php';
 
 
 $action = get('action', 'list');
 $action = get('action', 'list');
 
 
-if (!in_array($action, array('list', 'add', 'edit', 'view', 'goftp', 'login'))) {
+if (!in_array($action, array('list', 'add', 'edit', 'view', 'goftp', 'login', 'sync'))) {
     $action = 'list';
     $action = 'list';
 }
 }
 
 

+ 1 - 1
src/admin/controllers/accounts/goftp.php

@@ -2,7 +2,7 @@
 
 
 require_once __DIR__ . '/../../application.php';
 require_once __DIR__ . '/../../application.php';
 
 
-$account_id = get('id');
+$account_id = get('account_id');
 
 
 if (empty($account_id)) {
 if (empty($account_id)) {
     redirect('admin/accounts');
     redirect('admin/accounts');

+ 50 - 0
src/admin/controllers/accounts/sync.php

@@ -0,0 +1,50 @@
+<?php
+
+require_once __DIR__ . '/../../application.php';
+
+$account_id = get('account_id', 0);
+
+if (empty($account_id)) {
+    redirect('clientarea/accounts');
+}
+
+$AccountInfo = $DB->find('account', '*', array('account_id' => $account_id), null, 1);
+
+if (empty($AccountInfo)) {
+    setMessage('not found', 'danger');
+    redirect('clientarea/accounts');
+}
+
+// TODO: Change to an asynchronous request
+require_once ROOT . '/modules/autoload.php';
+
+use \InfinityFree\MofhClient\Client;
+
+if ($AccountInfo['account_status'] == 1) {
+    $AccountApi = $DB->find('account_api', '*', array('api_key' => $AccountInfo['account_api_key']), null, 1);
+    $AccountApiConfig = array(
+        'apiUsername' => $AccountApi['api_username'],
+        'apiPassword' => $AccountApi['api_password'],
+        // 'apiUrl' => 'https://panel.myownfreehost.net/xml-api/',
+        'plan' => $AccountApi['api_package'],
+    );
+    $client = Client::create($AccountApiConfig);
+    $request = $client->getUserDomains(array('username' => $AccountInfo['account_username']));
+    $response = $request->send();
+    $DomainList = $response->getDomains();
+} else {
+    // inactive
+    $DomainList = array();
+}
+if (count($DomainList) > 0) {
+    foreach($DomainList as &$item) {
+        $item = '("' . $item . '",' .$account_id . ')';
+    }
+    // 清理
+    $result = $DB->delete('account_domain', array('domain_account_id' => $account_id));
+    // 同步到本地
+    // $result = $DB->insert('account_domain', $DomainList);
+    $sql = "INSERT INTO `hosting_account_domain` (domain_name,domain_account_id) VALUES " . implode(',', $DomainList);
+    $result = $DB->query($sql);
+}
+redirect('admin/accounts', '', array('action' => 'view', 'account_id' => $account_id));

+ 2 - 0
src/admin/controllers/accounts/view.php

@@ -19,3 +19,5 @@ if (empty($AccountInfo)) {
 
 
 $PageInfo['title'] = 'View Account (#' . $account_id . ')';
 $PageInfo['title'] = 'View Account (#' . $account_id . ')';
 $AccountApi = $DB->find('account_api', '*', array('api_key' => $AccountInfo['account_api_key']), null, 1);
 $AccountApi = $DB->find('account_api', '*', array('api_key' => $AccountInfo['account_api_key']), null, 1);
+
+$AccountDomainList = $DB->findAll('account_domain', '*', array('domain_account_id' => $account_id));

+ 0 - 0
src/admin/views/accounts/sync.php


+ 24 - 2
src/admin/views/accounts/view.php

@@ -1,7 +1,7 @@
 <div class="content-wrapper">
 <div class="content-wrapper">
 <div class="container-fluid">
 <div class="container-fluid">
-    <div class="card">
-        <div class="card-header d-flex justify-content-between align-items-center">
+    <div class="card pt-0">
+        <div class="card-header d-flex justify-content-between align-items-center pt-15 px-5">
             <h5 class="m-0">Viewing Account (# <?php echo $account_id; ?>)</h5>
             <h5 class="m-0">Viewing Account (# <?php echo $account_id; ?>)</h5>
             <a href="accounts.php" class="btn btn-sm btn-danger">
             <a href="accounts.php" class="btn btn-sm btn-danger">
                 <i class="fa fa-backward"></i> <?php echo $lang->I18N('Return'); ?>
                 <i class="fa fa-backward"></i> <?php echo $lang->I18N('Return'); ?>
@@ -141,5 +141,27 @@
             </div>
             </div>
         </div>
         </div>
     </div>
     </div>
+
+    <div class="card py-0">
+        <div class="d-flex justify-content-between align-items-center pt-15">
+            <h5 class="m-0">Account Domains</h5>
+            <a href="accounts.php?action=sync&type=domain&account_id=<?php echo $account_id; ?>" class="btn btn-sm btn-danger">
+                <i class="fa fa-sync"></i> <?php echo $lang->I18N('Sync'); ?>
+            </a>
+        </div>
+        <hr />
+        <div class="mb-10 px-10">
+        <?php if (count($AccountDomainList) > 0): ?>
+        <?php foreach ($AccountDomainList as $domain): ?>
+            <div class='d-flex justify-content-between align-items-center m-5'>
+                <span><a href="http://<?php echo $domain['domain_name']; ?>" target="_blank" ref="noreferrer noopener"><?php echo $domain['domain_name']; ?></a></span>
+                <span><a href="accounts.php?action=goftp&account_id=<?php echo $account_id; ?>&domain=<?php echo $domain['domain_name']; ?>" class='btn btn-sm btn-square btn-secondary' target='_blank'><i class='fa fa-file-import'></i></a></span>
+            </div>
+        <?php endforeach;?>
+        <?php else: ?>
+            <p class='text-center'>No Domain Found</p>
+        <?php endif;?>
+        </div>
+    </div>
 </div>
 </div>
 </div>
 </div>

+ 2 - 11
src/clientarea/controllers/accounts/view.php

@@ -19,11 +19,6 @@ if (empty($AccountInfo)) {
     redirect('clientarea/accounts');
     redirect('clientarea/accounts');
 }
 }
 
 
-// TODO: Change to an asynchronous request
-require_once ROOT . '/modules/autoload.php';
-
-use \InfinityFree\MofhClient\Client;
-
 $PageInfo['title'] = 'View Account (#' . $account_id . ')';
 $PageInfo['title'] = 'View Account (#' . $account_id . ')';
 
 
 $AccountApi = $DB->find('account_api', '*', array('api_key' => $AccountInfo['account_api_key']), null, 1);
 $AccountApi = $DB->find('account_api', '*', array('api_key' => $AccountInfo['account_api_key']), null, 1);
@@ -42,14 +37,10 @@ if ($AccountInfo['account_status'] == 1) {
         'mysql_host' => $AccountApi['api_server_sql_domain'],
         'mysql_host' => $AccountApi['api_server_sql_domain'],
         'mysql_port' => 3306,
         'mysql_port' => 3306,
     ));
     ));
-
-    $client = Client::create($AccountApiConfig);
-    $request = $client->getUserDomains(array('username' => $AccountInfo['account_username']));
-    $response = $request->send();
-    $DomainList = $response->getDomains();
+    $AccountDomainList = $DB->findAll('account_domain', '*', array('domain_account_id' => $account_id));
 } else {
 } else {
     // inactive
     // inactive
-    $DomainList = array();
+    $AccountDomainList = array();
     $data = array_merge(array(), $AccountApi, $AccountInfo, array(
     $data = array_merge(array(), $AccountApi, $AccountInfo, array(
         'user_ip' => get_client_ip(),
         'user_ip' => get_client_ip(),
         'account_username' => '-',
         'account_username' => '-',

+ 4 - 4
src/clientarea/views/accounts/view.php

@@ -129,11 +129,11 @@
         </div>
         </div>
         <hr />
         <hr />
         <div class="mb-10 px-10">
         <div class="mb-10 px-10">
-        <?php if (count($DomainList) > 0): ?>
-        <?php foreach ($DomainList as $domain): ?>
+        <?php if (count($AccountDomainList) > 0): ?>
+        <?php foreach ($AccountDomainList as $domain): ?>
             <div class='d-flex justify-content-between align-items-center m-5'>
             <div class='d-flex justify-content-between align-items-center m-5'>
-                <span><a href="http://<?php echo $domain; ?>" target="_blank" ref="noreferrer noopener"><?php echo $domain; ?></a></span>
-                <span><a href="accounts.php?action=goftp&account_id=<?php echo $account_id; ?>&domain=<?php echo $domain; ?>" class='btn btn-sm btn-square btn-secondary' target='_blank'><i class='fa fa-file-import'></i></a></span>
+                <span><a href="http://<?php echo $domain['domain_name']; ?>" target="_blank" ref="noreferrer noopener"><?php echo $domain['domain_name']; ?></a></span>
+                <span><a href="accounts.php?action=goftp&account_id=<?php echo $account_id; ?>&domain=<?php echo $domain['domain_name']; ?>" class='btn btn-sm btn-square btn-secondary' target='_blank'><i class='fa fa-file-import'></i></a></span>
             </div>
             </div>
         <?php endforeach;?>
         <?php endforeach;?>
         <?php else: ?>
         <?php else: ?>

+ 9 - 0
src/install/function/Database.php

@@ -10,6 +10,7 @@ $sql = mysqli_query($connect, 'CREATE TABLE IF NOT EXISTS `uiisc_account` (
   `account_sql` VARCHAR(8) NOT NULL,
   `account_sql` VARCHAR(8) NOT NULL,
   `account_status` INT(1) NOT NULL,
   `account_status` INT(1) NOT NULL,
   `account_date` VARCHAR(20) NOT NULL,
   `account_date` VARCHAR(20) NOT NULL,
+  `account_signup_ip` varchar(20) DEFAULT NULL COMMENT "注册IP",
   PRIMARY KEY (`account_id`)
   PRIMARY KEY (`account_id`)
 ) ENGINE=MyISAM AUTO_INCREMENT=1000 DEFAULT CHARSET=utf8mb4;');
 ) ENGINE=MyISAM AUTO_INCREMENT=1000 DEFAULT CHARSET=utf8mb4;');
 
 
@@ -43,6 +44,13 @@ $sql = mysqli_query($connect, 'CREATE TABLE IF NOT EXISTS `uiisc_account_callbac
   PRIMARY KEY (`callback_id`)
   PRIMARY KEY (`callback_id`)
 ) ENGINE=MyISAM AUTO_INCREMENT=1000 DEFAULT CHARSET=utf8mb4;');
 ) ENGINE=MyISAM AUTO_INCREMENT=1000 DEFAULT CHARSET=utf8mb4;');
 
 
+$sql = mysqli_query($connect, 'CREATE TABLE IF NOT EXISTS `uiisc_account_domain` (
+  `domain_id` int(11) NOT NULL AUTO_INCREMENT COMMENT "主机账号ID",
+  `domain_name` varchar(255) NOT NULL COMMENT "域名",
+  `domain_account_id` int(11) NOT NULL COMMENT "托管账号ID",
+  PRIMARY KEY (`domain_id`)
+) ENGINE=MyISAM AUTO_INCREMENT=1071 DEFAULT CHARSET=utf8mb4;');
+
 $sql = mysqli_query($connect, 'CREATE TABLE IF NOT EXISTS `uiisc_config` (
 $sql = mysqli_query($connect, 'CREATE TABLE IF NOT EXISTS `uiisc_config` (
   `site_id` INT(11) unsigned NOT NULL AUTO_INCREMENT,
   `site_id` INT(11) unsigned NOT NULL AUTO_INCREMENT,
   `site_key` varchar(20) NOT NULL,
   `site_key` varchar(20) NOT NULL,
@@ -86,6 +94,7 @@ $sql = mysqli_query($connect, 'CREATE TABLE IF NOT EXISTS `uiisc_clients` (
   `client_status` INT(1) NOT NULL,
   `client_status` INT(1) NOT NULL,
   `client_company` VARCHAR(50) NOT NULL,
   `client_company` VARCHAR(50) NOT NULL,
   `client_password` VARCHAR(64) NOT NULL,
   `client_password` VARCHAR(64) NOT NULL,
+  `client_signup_ip` varchar(20) DEFAULT NULL COMMENT "注册IP",
   PRIMARY KEY (`client_id`)
   PRIMARY KEY (`client_id`)
 ) ENGINE=MyISAM AUTO_INCREMENT=1000 DEFAULT CHARSET=utf8mb4;');
 ) ENGINE=MyISAM AUTO_INCREMENT=1000 DEFAULT CHARSET=utf8mb4;');