Skip to content
This repository was archived by the owner on Mar 30, 2024. It is now read-only.

Commit 3ce99c7

Browse files
committed
Last Used for Devices
1 parent c07eb6e commit 3ce99c7

File tree

7 files changed

+58
-7
lines changed

7 files changed

+58
-7
lines changed

Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ COPY --chown=www-data:www-data ./php/ /php-code/
55
COPY --chown=www-data:www-data ./start/ /start/
66
COPY ./nginx.conf /etc/nginx/more-server-conf.conf
77
COPY ./startup-before.sh /
8-
COPY ./VERSION /php-code/VERSION
8+
COPY ./VERSION /php-code/VERSION
9+
10+
RUN curl -L https://browscap.org/stream?q=Lite_PHP_BrowsCapINI -o /start/lite_php_browscap.ini \
11+
&& echo "browscap = /start/lite_php_browscap.ini" > /usr/local/etc/php/conf.d/enable_browscap.ini

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
latest
2-
0.2.6
2+
0.2.7
33
0.2
44
0

php/core/Login.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ private function apiClientLogin(string $group, string $client, string $token) :
3535
$did = $this->groupList->searchValue([$group, 'devices'], $client, 'name');
3636
if( $did !== false ){
3737
if( $this->groupList->getValue([$group, 'devices', $did, 'token']) === $token ){
38+
$this->groupList->setValue([$group, 'devices', $did, 'used'], time());
3839
$this->logUserIn($group, $client);
3940
return;
4041
}
@@ -131,7 +132,8 @@ public static function createNewGroup(JSONReader $groups, string $group, string
131132
return $groups->setValue([$group], array(
132133
"passhash" => self::genHashedPassword($password),
133134
"admin" => $admin,
134-
"devices" => array()
135+
"devices" => array(),
136+
"sessions" => array()
135137
));
136138
}
137139
}

php/core/Utilities.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ public static function deleteDirRecursive(string $dir) : bool {
8585
}
8686
return $ok && rmdir($dir);
8787
}
88+
89+
public static function getBrowserOS() : string {
90+
$b = get_browser();
91+
return $b->browser . ' ' . $b->version . ' on ' . $b->platform;
92+
}
93+
8894
}
8995

9096
?>

php/core/WebGUI.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public function deviceManage() : void {
154154
$did = $r->searchValue([$myGroup, 'devices'], $name, 'name');
155155
if( $did === false ){
156156
$token = Utilities::randomCode(50, Utilities::ID);
157-
if($r->setValue([$myGroup, 'devices', null], array( 'name' => $name, 'token' => $token))){
157+
if($r->setValue([$myGroup, 'devices', null], array( 'name' => $name, 'token' => $token, 'used' => 0))){
158158
$device->setContent('NOTEMSG','Added device "'. $name .'" with token<br>"<code>'. $token .'</code>"!');
159159
}
160160
else{
@@ -205,11 +205,22 @@ public function deviceManage() : void {
205205
foreach($r->getValue([$this->login->getGroup(), 'devices']) as $d){
206206
$dv[] = array(
207207
"NAME" => $d['name'],
208-
"DID" => $d['name']
208+
"DID" => $d['name'],
209+
"LASTUSED" => $d['used'] > 0 ? date('Y-m-d H:i', $d['used']) : 'Never'
209210
);
210211
}
211212
$device->setMultipleContent('Devices', $dv);
212213

214+
$sv = array();
215+
foreach($r->getValue([$this->login->getGroup(), 'sessions']) as $k => $d){
216+
$sv[] = array(
217+
"BROWSEROS" => $d['browseros'],
218+
"LASTUSED" => $d['used'] > 0 ? date('Y-m-d H:i', $d['used']) : 'Never',
219+
"SID" => $k
220+
);
221+
}
222+
$device->setMultipleContent('Sessions', $sv);
223+
213224
if( is_dir(API::getStorageDir($myGroup)) ){
214225
$ds = array();
215226
foreach( scandir(API::getStorageDir($myGroup)) as $d){

php/core/templates/device.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@
44
"multiples" : {
55
"Devices" : {
66
"%%NAME%%" : "Name",
7-
"%%DID%%" : "-1"
7+
"%%DID%%" : "-1",
8+
"%%LASTUSED%%" : "Unknown"
89
},
910
"Data" : {
1011
"%%NAME%%" : "Name"
12+
},
13+
"Sessions" : {
14+
"%%BROWSEROS%%" : "Unknown",
15+
"%%LASTUSED%%" : "Unknown",
16+
"%%SID%%" : "-1"
1117
}
1218
}
1319
}

php/core/templates/device_en.html

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ <h3>Active devices</h3>
77
<tr>
88
<thead class="thead-dark">
99
<th>Device</th>
10+
<th>Last used</th>
1011
<th>Regenerate token</th>
1112
<th>Delete</th>
1213
</thead>
1314
</tr>
1415
<!--MULTIPLE-Devices-BEGIN-->
1516
<tr>
1617
<td><code>%%NAME%%</code></td>
18+
<td><code>%%LASTUSED%%</code></td>
1719
<td><a href="%%SERVERURL%%/?task=devices&regenerate=%%DID%%" class="confirm confirmLink" title="Regenerate Token" content="Regenerate token for device '%%NAME%%'?"><button type="button" class="btn btn-warning">Regenerate</button></a></td>
1820
<td><a href="%%SERVERURL%%/?task=devices&delete=%%DID%%" class="confirm confirmLink" title="Delete Device" content="Delete device with name '%%NAME%%'?"><button type="button" class="btn btn-danger">Delete</button></a></td>
1921
</tr>
@@ -47,4 +49,25 @@ <h3>Available data in storage</h3>
4749
<!--MULTIPLE-Data-BEGIN-->
4850
<li class="list-group-item"><code>%%NAME%%</code></li>
4951
<!--MULTIPLE-Data-END-->
50-
</ul>
52+
</ul>
53+
54+
<h3>Web session</h3>
55+
<p>
56+
When a user ticks the box "Stay logged in" the a session will be created and shown here.
57+
</p>
58+
<table class="accounttable table table-striped table-responsive-sm">
59+
<tr>
60+
<thead class="thead-dark">
61+
<th>Device</th>
62+
<th>Last used</th>
63+
<th>Remove</th>
64+
</thead>
65+
</tr>
66+
<!--MULTIPLE-Sessions-BEGIN-->
67+
<tr>
68+
<td><code>%%BROWSEROS%%</code></td>
69+
<td><code>%%LASTUSED%%</code></td>
70+
<td><a href="%%SERVERURL%%/?task=devices&remove=%%SID%%" class="confirm confirmLink" title="Delete Device" content="Delete session on '%%BROWSEROS%%'?"><button type="button" class="btn btn-danger">Remove</button></a></td>
71+
</tr>
72+
<!--MULTIPLE-Sessions-END-->
73+
</table>

0 commit comments

Comments
 (0)