-
Notifications
You must be signed in to change notification settings - Fork 0
/
dashboard.php
341 lines (324 loc) · 10.4 KB
/
dashboard.php
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
<?php
/*
* ybot.php - a plurk bot use php-plurk-api
*
* Copyright (C) 2012 Wei-Chen Lai <abev66@gmail.com>
* 2012 Zheng-Yen Hong
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
session_start();
if($_SESSION['_ybot_type']=='b' || !isset($_SESSION['_ybot_uid'])):
header('Location: login.php');
else:
require('db_port.php');
$db_port = db_init($_SESSION[_ybot_uid]);
include('command_flags.inc');
?>
<!DOCTYPE html>
<html>
<head>
<title>ybot - Dashboard</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel='stylesheet' href='style.css' type='text/css'>
<style type='text/css'>
<!--
.controlpanel {
background: #FFF;
border-radius: 5px;
display: block;
margin: 1em auto;
padding: 16px;
max-width: 460px;
text-align: center;
vertical-align: middle;
box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.2);
-moz-transition: opacity 0.3s;
-webkit-transition: opacity 0.3s;
-o-transition: opacity 0.3s;
opacity: 0.7;
}
.controlpanel h3 {
margin-top: 0;
}
h3 {
margin: 12px auto;
font-weight: bold;
font-size: 133%;
font-weight: normal;
text-align:center;
}
.plurk_box {
background: #FFF;
opacity: 0.7;
border-radius: 5px;
display: block;
margin: 1em auto;
padding: 0.7em 2.5em;
max-width: 580px;
vertical-align: middle;
box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.2);
-moz-transition: opacity 0.3s;
-webkit-transition: opacity 0.3s;
-o-transition: opacity 0.3s;
}
.plurk_box p, .plurk_box h3 {
text-align: center;
}
.plurk_box:hover, .controlpanel:hover {
opacity: 1;
}
#send-btn {
width: 81px;
height: 38px;
background-image: url('images/plurkbuttom.png');
background-position: center center;
background-repeat: no-repeat;
text-indent: -9999px;
border-radius: 5px;
margin: 0 auto 0;
border: 0;
}
.setval {
background: #FFF;
opacity: 0.7;
border-radius: 5px;
display: block;
margin: 2em auto;
padding: 2em 2.5em;
max-width: 580px;
text-align: center;
vertical-align: middle;
box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.2);
-moz-transition: opacity 0.3s;
-webkit-transition: opacity 0.3s;
-o-transition: opacity 0.3s;
}
.setval h3 {
margin-top: 0;
}
.setval:hover {
opacity: 1;
}
-->
</style>
</head>
<body>
<div class='container'>
<?php include('header.inc'); ?>
<?php include('navbar.inc'); ?>
<?php
$socket = socket_create(AF_UNIX, SOCK_DGRAM, 0);
$randomd=(string)rand();
$socketname="sockets/socket_ybot-client".$randomd;
socket_bind($socket, $socketname);
socket_set_block($socket);
chmod($socketname, 0777);
$msg=json_encode(array( 'command' => CMD_GET_PAUSE_STATUS ));
$bytes_sent = socket_sendto($socket, $msg, strlen($msg), 0, 'sockets/ybot-socket' );
if($bytes_sent){
$bfr='';
$bytes_received = @socket_recv($socket, $bfr, 65536, 0);
if($bfr == FB_RUNNING)
echo "<div class='notice-green'>Status: Running</div>";
else if($bfr == FB_PAUSED)
echo "<div class='notice-green'>Status: Pause</div>";
else
echo "<div class='notice-red'>Status: Unexpect response.</div>";
$botstatus = $bfr;
$msg=json_encode(array( 'command' => CMD_VERSION ));
$bytes_sent = socket_sendto($socket, $msg, strlen($msg), 0, 'sockets/ybot-socket' );
if($bytes_sent){
$bfr='';
$bytes_received = @socket_recv($socket, $bfr, 65536, 0);
if(!empty($bfr) && $bfr != FB_ERROR_INVALID_COMMAND && $bfr != FB_ERROR){
$ver_info = json_decode($bfr);
}
}
} else {
echo "<div class='notice-red'>Couldn't connect to bot.</div>";
$botstatus = 'dead';
}
if( isset( $_POST['ps']) ) {
$msg=json_encode(array( 'command' => CMD_PAUSE ));
$bytes_sent = socket_sendto($socket, $msg, strlen($msg), 0, 'sockets/ybot-socket' );
if($bytes_sent){
$bfr='';
$bytes_received = @socket_recv($socket, $bfr, 65536, 0);
if($bfr==FB_OK)
header("Location: dashboard.php");
}
} else if ( isset( $_POST['co']) ){
$msg=json_encode(array( 'command' => CMD_CONTINUE ));
$bytes_sent = socket_sendto($socket, $msg, strlen($msg), 0, 'sockets/ybot-socket' );
if($bytes_sent){
$bfr='';
$bytes_received = @socket_recv($socket, $bfr, 65536, 0);
if($bfr==FB_OK)
header("Location: dashboard.php");
}
} else if ( isset( $_POST['rs']) ) {
$msg=json_encode(array( 'command' => CMD_RELOAD_SETTINGS ));
$bytes_sent = socket_sendto($socket, $msg, strlen($msg), 0, 'sockets/ybot-socket' );
if ($bytes_sent)
echo "<div class='notice-green'>Command Sent.</div>";
else
echo "<div class='notice-red'>Command not sent</div>";
} else if ( isset( $_POST['rt']) ) {
$msg=json_encode(array( 'command' => CMD_RELOAD_TABLE ));
$bytes_sent = socket_sendto($socket, $msg, strlen($msg), 0, 'sockets/ybot-socket' );
if ($bytes_sent)
echo "<div class='notice-green'>Command Sent.</div>";
else
echo "<div class='notice-red'>Command not sent</div>";
} else if ( isset( $_POST['rl']) ) {
$msg=json_encode(array( 'command' => CMD_RELOGIN));
$bytes_sent = socket_sendto($socket, $msg, strlen($msg), 0, 'sockets/ybot-socket' );
if ($bytes_sent)
echo "<div class='notice-green'>Command Sent.</div>";
else
echo "<div class='notice-red'>Command not sent</div>";
} else if ( isset($_POST['nplurk']) ) {
include('plurk_lang_flags.inc');
$no_comments = ($_POST['no_comments'] == 1)? 1 : 0 ;
$msg=json_encode(array("command" => CMD_SEND_PLURK, "content" => $_POST['plurk'], "lang" => PLURK_LANG_CHINESE_TRADITIONAL, "qualifier" => $_POST['qualifier'], "no_comments" => $no_comments ));
$bytes_sent = socket_sendto($socket, $msg, strlen($msg), 0, 'sockets/ybot-socket' );
if ($bytes_sent)
echo "<div class='notice-green'>Sent</div>";
else
echo "<div class='notice-red'>Not Sent</div>";
}
socket_set_nonblock($socket);
socket_close($socket);
unlink($socketname);
?>
<?php if(isset($_POST['update'])): ?>
<div class="notice-green">Update:
<?php
foreach($_POST['newsets'] as $key => $value) {
if( $value != $_POST['oldsets'][$key] ){
echo $key.' ';
update_setting($db_port, $key, $value);
}
}
?>
</div>
<? endif; ?>
<?php if($botstatus != 'dead'): ?>
<!-- Control Panel -->
<div class='controlpanel'>
<h3>Control Panel</h3>
<form action='' method='POST'>
<?php if($botstatus == FB_RUNNING): ?>
<input type='submit' name='ps' value='Pause' />
<?php else:?>
<input type='submit' name='co' value='Continue' />
<?php endif;?>
<input type='submit' name='rs' value='Reload Setting' />
<input type='submit' name='rt' value='Reload Table' />
<input type='submit' name='rl' value='Relogin' />
</form>
<?php if(isset($ver_info)):?>
<table>
<tr><th colspan='2'>Bot Info</th></tr>
<?php foreach( $ver_info as $key => $value):?>
<tr><td><?php echo $key; ?></td><td><?php echo $value; ?></td></tr>
<?php endforeach;?>
</table>
<?php endif;?>
</div>
<div class='plurk_box'>
<h3>Send a Plurk</h3>
<form action='' method='POST'>
<p>
<select name='qualifier'>
<option value=":">:(自由發揮)</option>
<option value='says' selected='selected'>說</option>
<option value='likes' >喜歡</option>
<option value='shares' >分享</option>
<option value='gives' >給</option>
<option value='hates' >討厭</option>
<option value='wants' >想要</option>
<option value='has' >已經</option>
<option value='will' >打算</option>
<option value='asks' >問</option>
<option value='wishs' >期待</option>
<option value='was' >曾經</option>
<option value='feels' >覺得</option>
<option value='thinks' >想</option>
<option value='is' >正在</option>
<option value='hopes' >希望</option>
<option value='needs' >需要</option>
<option value='wonders' >好奇</option>
</select>
<input type='text' name='plurk' maxlength='140' size='35' />
<div style="text-align: right;"><input type='checkbox' name='no_comments' value='1' />No comments</div>
</p>
<p>
<input type='submit' id='send-btn' name='nplurk' value='Plurk' />
</p>
</form>
</div>
<?php endif;?>
<!-- Setting Values -->
<div class='setval'>
<h3>Settings</h3>
<form action='' method='POST'>
<table>
<thead>
<tr>
<th>Setting</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<?php
$settings=dump_settings($db_port);
foreach( $settings as $key => $value ){
echo "<tr>\n";
echo "<td>$key</td>\n";
echo '<td>';
if($key == 'RESPONSE_MODE'){
foreach(array('MENTION','ANYWAY','DISABLED') as $set)
echo "<input type='radio' name='newsets[$key]' value='$set' ".(($set == strtoupper($value))?'checked':'')." />$set";
} else if($key == 'PLURK_PASSWORD') {
echo "<input type='password' name='newsets[$key]' value='' />";
} else if(strtolower($value) == 'true' || strtolower($value) == 'false') {
if(strtolower($value)=='true'){
echo "<input type='radio' name='newsets[$key]' value='true' checked /> On";
echo "<input type='radio' name='newsets[$key]' value='false' /> Off";
} else {
echo "<input type='radio' name='newsets[$key]' value='true' /> On";
echo "<input type='radio' name='newsets[$key]' value='false' checked /> Off";
}
} else
echo "<input type='text' name='newsets[$key]' value='$value' />";
if($key != 'PLURK_PASSWORD')
echo "<input type='hidden' name='oldsets[$key]' value='$value' />";
echo '</td>';
echo "\n</tr>\n";
}
?>
</table>
<input type='submit' name='update' value='Save' />
<input type='reset' value='Cancel' />
</form>
</div>
</div>
</body>
</html>
<?php
db_close($db_port);
endif; ?>