File size: 6,379 Bytes
e09a4d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<!DOCTYPE html>
<html>
<head>
    <title>代理管理界面</title>
    <style>

        body {

            font-family: Arial, sans-serif;

            max-width: 1200px;

            margin: 0 auto;

            padding: 20px;

        }

        .container {

            display: flex;

            gap: 20px;

        }

        .section {

            flex: 1;

            background: #f5f5f5;

            padding: 20px;

            border-radius: 8px;

        }

        table {

            width: 100%;

            border-collapse: collapse;

            margin: 10px 0;

        }

        th, td {

            padding: 8px;

            border: 1px solid #ddd;

            text-align: left;

        }

        th { background: #eee; }

        .enabled { color: green; }

        .disabled { color: red; }

        .form-group {

            margin: 10px 0;

        }

        button {

            padding: 5px 10px;

            margin: 2px;

            cursor: pointer;

        }

        .status-bar {

            background: #e0e0e0;

            padding: 10px;

            margin: 10px 0;

            border-radius: 4px;

        }

    </style>
</head>
<body>
    <h1>代理管理界面</h1>

    <div class="status-bar">
        <strong>系统状态:</strong>
        Models代理数: <span id="modelsCount">0</span> |
        Chat代理数: <span id="chatCount">0</span>
    </div>

    <div class="container">
        <div class="section">
            <h2>Models代理列表</h2>
            <table id="modelsTable">
                <tr>
                    <th>URL</th>
                    <th>权重</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
            </table>

            <h3>添加Models代理</h3>
            <div class="form-group">
                <input type="text" id="modelsUrl" placeholder="URL">
                <input type="number" id="modelsWeight" placeholder="权重" value="1">
                <button onclick="addTarget('models')">添加</button>
            </div>
        </div>

        <div class="section">
            <h2>Chat代理列表</h2>
            <table id="chatTable">
                <tr>
                    <th>URL</th>
                    <th>权重</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
            </table>

            <h3>添加Chat代理</h3>
            <div class="form-group">
                <input type="text" id="chatUrl" placeholder="URL">
                <input type="number" id="chatWeight" placeholder="权重" value="1">
                <button onclick="addTarget('chat')">添加</button>
            </div>
        </div>
    </div>

    <script>

        const password = new URLSearchParams(window.location.search).get('password');



        function updateTables() {

            fetch('/admin/api/targets?password=' + password)

                .then(response => response.json())

                .then(data => {

                    document.getElementById('modelsCount').textContent = data.models.length;

                    document.getElementById('chatCount').textContent = data.chat.length;



                    updateTable('models', data.models);

                    updateTable('chat', data.chat);

                });

        }



        function updateTable(type, targets) {

            const table = document.getElementById(type + 'Table');

            // 保留表头

            while (table.rows.length > 1) {

                table.deleteRow(1);

            }



            targets.forEach((target, index) => {

                const row = table.insertRow();

                row.innerHTML = `

                    <td>${target.url}</td>

                    <td>${target.weight}</td>

                    <td class="${target.enabled ? 'enabled' : 'disabled'}">

                        ${target.enabled ? '启用' : '禁用'}

                    </td>

                    <td>

                        <button onclick="toggleTarget('${type}', '${target.url}')">

                            ${target.enabled ? '禁用' : '启用'}

                        </button>

                        <button onclick="deleteTarget('${type}', '${target.url}')">删除</button>

                    </td>

                `;

            });

        }



        function addTarget(type) {

            const url = document.getElementById(type + 'Url').value;

            const weight = document.getElementById(type + 'Weight').value;



            fetch('/admin/api/target', {

                method: 'POST',

                headers: {

                    'Content-Type': 'application/json',

                },

                body: JSON.stringify({

                    type: type,

                    url: url,

                    weight: parseInt(weight),

                    password: password

                })

            }).then(() => {

                document.getElementById(type + 'Url').value = '';

                document.getElementById(type + 'Weight').value = '1';

                updateTables();

            });

        }



        function toggleTarget(type, url) {

            fetch('/admin/api/target/toggle', {

                method: 'POST',

                headers: {

                    'Content-Type': 'application/json',

                },

                body: JSON.stringify({

                    type: type,

                    url: url,

                    password: password

                })

            }).then(() => updateTables());

        }



        function deleteTarget(type, url) {

            if (!confirm('确定要删除这个代理地址吗?')) return;



            fetch('/admin/api/target', {

                method: 'DELETE',

                headers: {

                    'Content-Type': 'application/json',

                },

                body: JSON.stringify({

                    type: type,

                    url: url,

                    password: password

                })

            }).then(() => updateTables());

        }



        // 初始加载

        updateTables();

        // 定时刷新

        setInterval(updateTables, 5000);

    </script>
</body>
</html>