Skip to content

Commit 991caca

Browse files
committed
Adding in chat admin features
1 parent 8045555 commit 991caca

File tree

4 files changed

+232
-0
lines changed

4 files changed

+232
-0
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<?php
2+
3+
class Core_Chat_AdminController extends BaseController {
4+
5+
public function getIndex()
6+
{
7+
LeftTab::
8+
addPanel()
9+
->setTitle('Chat Server')
10+
->setBasePath('chat/admin')
11+
->addTab('Controls', 'controls')
12+
->addTab('Config', 'config')
13+
->buildPanel()
14+
->make();
15+
}
16+
17+
public function getConfig()
18+
{
19+
$chatConfig = json_decode(File::get(app_path('config/packages/syntax/chat/chatConfig.json')));
20+
21+
$this->setViewData('chatConfig', $chatConfig);
22+
}
23+
24+
public function postConfig()
25+
{
26+
$this->skipView();
27+
28+
$input = e_array(Input::all());
29+
30+
if ($input != null) {
31+
unset($input['_token']);
32+
33+
$input['debug'] = $input['debug'] == 1 ? true : false;
34+
$input['connectionMessage'] = $input['connectionMessage'] == 1 ? true : false;
35+
36+
$config = json_encode($input, JSON_NUMERIC_CHECK);
37+
38+
File::put(app_path('config/packages/syntax/chat/chatConfig.json'), $config);
39+
40+
// Restart the server to have it take effect
41+
$this->getRestartServer();
42+
}
43+
44+
return $this->redirect('/chat/admin#config', 'Chat config updated.');
45+
}
46+
47+
public function getControls()
48+
{
49+
$rootDirectory = Config::get('remote.connections.default.root');
50+
51+
// Get the status of the server
52+
$chatPID = trim(File::get($rootDirectory .'/vendor/syntax/chat/src/node/ChatPID'));
53+
54+
switch ($chatPID) {
55+
case 'STOPPED':
56+
$status = 'Halted';
57+
break;
58+
case "":
59+
$status = 'Restarting...';
60+
break;
61+
case is_numeric($chatPID):
62+
$status = 'Running';
63+
break;
64+
default:
65+
$running = null;
66+
67+
$commands = [
68+
'cd '. $rootDirectory .'/vendor/syntax/chat/src/node',
69+
'ps -p`cat ChatPID` -o "%p %a" --no-header'
70+
];
71+
72+
SSH::into('default')->run($commands, function($line) use (&$running) {
73+
$running = $line.PHP_EOL;
74+
});
75+
76+
$status = trim(str_replace('stdin: is not a tty', '', $running));
77+
break;
78+
}
79+
80+
// Get the configuration
81+
$chatConfig = json_decode(File::get(app_path('config/packages/syntax/chat/chatConfig.json')));
82+
83+
$this->setViewData('status', $status);
84+
$this->setViewData('chatConfig', $chatConfig);
85+
}
86+
87+
public function getStartServer()
88+
{
89+
$rootDirectory = Config::get('remote.connections.default.root');
90+
91+
$commands = [
92+
'cd '. $rootDirectory .'/vendor/syntax/chat/src/node',
93+
'bash 1chat_master &'
94+
];
95+
96+
SSH::into('default')->run($commands);
97+
98+
return $this->redirect('back', 'Chat server started.');
99+
}
100+
101+
public function getStopServer()
102+
{
103+
$rootDirectory = Config::get('remote.connections.default.root');
104+
105+
$commands = [
106+
'cd '. $rootDirectory .'/vendor/syntax/chat/src/node',
107+
'echo STOP > ChatPID'
108+
];
109+
110+
SSH::into('default')->run($commands);
111+
112+
return $this->redirect('back', 'Chat server halted.');
113+
}
114+
115+
public function getRestartServer()
116+
{
117+
$rootDirectory = Config::get('remote.connections.default.root');
118+
119+
$commands = [
120+
'cd '. $rootDirectory .'/vendor/syntax/chat/src/node',
121+
'echo "" > ChatPID'
122+
];
123+
124+
SSH::into('default')->run($commands);
125+
126+
return $this->redirect('back', 'Chat server restarted.');
127+
}
128+
}

src/node/1chat_master

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
#node chat management
3+
#wrote by Michael "Like A Boss!" Cox 3/9/2014
4+
#comments or questions, feel free to go fuck yourself.
5+
6+
#functions
7+
8+
function Start_Serv {
9+
node chat.js &>/dev/null &
10+
}
11+
12+
13+
while [ 1 ]
14+
do
15+
eval STATEofPID=`cat ./ChatPID`
16+
17+
#echo $STATEofPID
18+
19+
if [ -n "$STATEofPID" ] ; then
20+
if [ "$STATEofPID" != "STOP" ] ;then
21+
if [ "$STATEofPID" != "STOPPED" ] ; then
22+
eval SoP=$(ps -p`echo $STATEofPID` -o "%p %a"|awk '{if(NR==2 && /node/&& $3 ~ /chat.js/){print $1}} END {{if(NR<2)print "NADDA"}}')
23+
if [ "$SoP" == "NADDA" ] ; then
24+
#echo "Pid listed not found."
25+
echo "" > ./ChatPID
26+
fi
27+
fi
28+
fi
29+
if [ "$STATEofPID" == "STOP" ] && [ -n "$LP" ] ; then
30+
kill -9 $LP
31+
echo "STOPPED" > ./ChatPID
32+
fi
33+
fi
34+
35+
if [ -z "$STATEofPID" ] ; then
36+
#echo "STATEofPID was empty"
37+
Start_Serv
38+
echo $! > ./ChatPID
39+
LP=$!
40+
fi
41+
42+
sleep 5
43+
done

src/views/chat/admin/config.blade.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{{ bForm::open() }}
2+
<div class="panel panel-default">
3+
<div class="panel-heading">Modify chat configuration</div>
4+
<div class="panel-body">
5+
{{ bForm::select('debug', array('Debug Off', 'Debug On'), $chatConfig->debug, array(), 'Debug') }}
6+
{{ bForm::text('port', $chatConfig->port, array(), 'Port') }}
7+
{{ bForm::text('backLog', $chatConfig->backLog, array(), 'Back Log') }}
8+
{{ bForm::text('backFill', $chatConfig->backFill, array(), 'Back Fill') }}
9+
{{ bForm::text('apiEndPoint', $chatConfig->apiEndPoint, array(), 'API End Point') }}
10+
{{ bForm::select('connectionMessage', array('Connection Message Off', 'Connection Message On'), $chatConfig->connectionMessage, array(), 'Connection Message') }}
11+
{{ bForm::submit('Update Config') }}
12+
</div>
13+
</div>
14+
{{ bForm::close() }}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<div class="row">
2+
<div class="col-md-7">
3+
<div class="panel panel-default">
4+
<div class="panel-heading">Chat Configuration</div>
5+
<div class="panel-body">
6+
<dl class="dl-horizontal">
7+
<dt>Status</dt>
8+
@if ($status == 'Running')
9+
<dd class="text-success">{{ $status }}</dd>
10+
@elseif ($status == 'Restarting...')
11+
<dd class="text-warning">{{ $status }}</dd>
12+
@elseif ($status == 'Halted')
13+
<dd class="text-danger">{{ $status }}</dd>
14+
@else
15+
<dd class="text-disabled">{{ $status }}</dd>
16+
@endif
17+
<dt>Debug</dt>
18+
<dd>{{ $chatConfig->debug == 1 ? 'true' : 'false' }}</dd>
19+
<dt>Port</dt>
20+
<dd>{{ $chatConfig->port }}</dd>
21+
<dt>Back Log</dt>
22+
<dd>{{ $chatConfig->backLog }}</dd>
23+
<dt>No of chats to back fill</dt>
24+
<dd>{{ $chatConfig->backFill }}</dd>
25+
<dt>API End Point</dt>
26+
<dd>{{ $chatConfig->apiEndPoint }}</dd>
27+
<dt>Connection Message</dt>
28+
<dd>{{ $chatConfig->connectionMessage == 1 ? 'true' : 'false' }}</dd>
29+
</dl>
30+
</div>
31+
</div>
32+
<div class="panel panel-default">
33+
<div class="panel-heading">Controls</div>
34+
<div class="panel-body">
35+
<div class="btn-group text-center">
36+
@if ($status)
37+
<button class="btn btn-primary" disabled="disabled">Start</button>
38+
{{ HTML::link('/chat/admin/stop-server', 'Stop', array('class' => 'btn btn-danger')) }}
39+
@else
40+
{{ HTML::link('/chat/admin/start-server', 'Start', array('class' => 'btn btn-primary')) }}
41+
<button class="btn btn-danger" disabled="disabled">Stop</button>
42+
@endif
43+
</div>
44+
</div>
45+
</div>
46+
</div>
47+
</div>

0 commit comments

Comments
 (0)