Skip to content
Permalink
Browse files

v0.3

upload cookies file in settings form
add delete user button
  • Loading branch information...
Anisan committed Apr 12, 2019
1 parent d45c5ab commit 5e08d324a848daa1ef333b858e6a941aca0bb571
Showing with 89 additions and 17 deletions.
  1. +59 −12 modules/google_location/google_location.class.php
  2. +30 −5 templates/google_location/action_admin.html
@@ -129,6 +129,9 @@ function log($message) {
function admin(&$out) {
$this->getConfig();
$directory_cookies=ROOT."cms/cached/google_location/";
if (!file_exists($directory_cookies)) {
mkdir($directory_cookies, 0777, true);}
$out['COOKIE_FILE']=$this->config['COOKIE_FILE'];
$out['TIMEOUT_UPDATE']=$this->config['TIMEOUT_UPDATE'];
$out['LAST_UPDATE']=$this->config['LAST_UPDATE'];
@@ -144,6 +147,23 @@ function admin(&$out) {
$this->redirect("?");
return;
}
if($this->view_mode == 'user_delete') {
$this->delete_user($this->id);
}
if ($this->view_mode=='upload_cookie') {
global $file;
global $file_name;
copy($file, $directory_cookies.$file_name);
$this->redirect("?");
return;
}
if($this->view_mode == 'delete_cookie') {
global $name;
$this->debug('delete cookie '.$name);
unlink($directory_cookies.$name);
}
if ($this->view_mode=='update_location') {
$this->updateLocation();
$this->redirect("?");
@@ -163,7 +183,28 @@ function admin(&$out) {
$locations = SQLSelect("select * from google_locations");
$out['LOCATIONS'] = $locations;
$cookies_files = [];//array_diff(scandir($directory_cookies), array('..', '.'));
if($handle = opendir($directory_cookies)){
while(false !== ($file = readdir($handle))) {
if($file != "." && $file != "..") {
$cookies_files[] = array("NAME" => $file, "DATE"=>date("F d Y H:i:s", filectime($directory_cookies.$file)), "SIZE"=>filesize($directory_cookies.$file));
}
}
closedir( $handle );
}
if ($cookies_files)
{
$this->debug($cookies_files);
$out['COOKIES_FILES'] = $cookies_files;
}
}
function delete_user($id) {
$rec = SQLSelectOne("SELECT * FROM google_locations WHERE ID='$id'");
SQLExec("DELETE FROM google_locations WHERE ID='" . $rec['ID'] . "'");
}
/**
* FrontEnd
*
@@ -184,7 +225,14 @@ function processSubscription($event, $details='') {
}
}
public function updateLocation() {
$locations = $this->getLocation();
$locations = [];
$directory_cookies=ROOT."cms/cached/google_location/";
$cookies = array_diff(scandir($directory_cookies), array('..', '.'));
foreach ($cookies as $cookie)
{
$locations = array_merge($locations,$this->getLocation($directory_cookies.$cookie));
}
$this->debug($locations);
foreach ($locations as $location) {
$rec = SQLSelectOne("select * from google_locations where ID_USER='".$location["id"]."'");
if ($rec['ID']) {
@@ -223,20 +271,21 @@ public function sendToGps($location)
$contents = getURLBackground($req,0);
}
public function getLocation() {
public function getLocation($cookie_file) {
try {
$result = $this->getLocationData();
$result = $this->getLocationData($cookie_file);
} catch (Exception $e) {
//$this->google_connect();
//$result = $this->google_callLocationUrl();
$this->log($e);
return;
return [];
}
$return = array();
$path_parts = pathinfo($cookie_file);
$return[] = array(
'id' => 'self_account',
'name' => 'Google account',
'fullname' => 'Google account',
'id' => crc32($cookie_file),
'name' => $path_parts['filename'],
'fullname' => $path_parts['filename'],
'image' => '',
'address' => $result[9][1][4],
'timestamp' => $result[9][1][2],
@@ -264,12 +313,11 @@ public function getLocation() {
return $return;
}
public function getLocationData() {
$this->getConfig();
public function getLocationData($cookie_file) {
$url = 'https://www.google.com/maps/preview/locationsharing/read?authuser=0&hl='.SETTINGS_SITE_LANGUAGE.'&gl='.SETTINGS_SITE_LANGUAGE.'&pb=';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $this->config['COOKIE_FILE']);
curl_setopt($ch, CURLOPT_COOKIEFILE, $this->config['COOKIE_FILE']);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
curl_setopt($ch, CURLOPT_HEADER, 1);
@@ -283,7 +331,6 @@ public function getLocationData() {
if (empty($info['http_code']) || $info['http_code'] != 200) {
throw new Exception('Error connection : '. $info['http_code'] . ' => ' . json_encode($headers));
}
$this->debug($result);
$result = substr($response, $info['header_size'] + 4);
if (!$this->is_json($result)) {
throw new Exception('Not valid json result : ' . $result);
@@ -7,17 +7,35 @@
</div>
<div class="collapse" id='api_settings'>&nbsp;
&nbsp;
<form action="?" method="post" enctype="multipart/form-data" name="frmEdit" class="form-horizontal">
<fieldset>
<form method="POST" action="?" enctype="multipart/form-data" class="form-horizontal">
<div class="form-group">
<label class="col-lg-4 control-label">Upload cookie file:</label>
<div class="col-lg-3"><input class="form-control" type="file" name="file" class="input"></div>
<input type="submit" name="submit" value="Add" class="btn btn-default">
</div>
<input type="hidden" name="view_mode" value="upload_cookie">
</form>
<form action="?" method="post" enctype="multipart/form-data" name="frmEdit" class="form-horizontal">
<div class="form-group">
<label class="col-lg-4 control-label">Cookie path
</label>
<div class="col-lg-6"><input class="form-control" type="text" name="cookie_file" value="<#COOKIE_FILE#>" class="input"></div>
<label class="col-lg-4 control-label">Cookies:</label>
<div class="col-lg-3">
[#if COOKIES_FILES#]
[#begin COOKIES_FILES#]
<div class="row">
<label class="col-lg-9">[#NAME#] ([#SIZE#]b)</label>
<a class="btn btn-default" href="?view_mode=delete_cookie&name=[#NAME#]" onClick="return confirm('<#LANG_ARE_YOU_SURE#>')"><i class="glyphicon glyphicon-remove"></i></a>
</div>
[#end COOKIES_FILES#]
[#else COOKIES_FILES#]
<div class="alert alert-danger"><#LANG_NO_RECORDS_FOUND#></div>
[#endif COOKIES_FILES#]
</div>
</div>
<div class="form-group">
<label class="col-lg-4 control-label">Timeout update (min)
</label>
<div class="col-lg-6"><input class="form-control" type="text" name="timeout_update" value="<#TIMEOUT_UPDATE#>" class="input"></div>
<div class="col-lg-3"><input class="form-control" type="text" name="timeout_update" value="<#TIMEOUT_UPDATE#>" class="input"></div>
</div>
<div class="form-group">
<label class="control-label">Debug</label>
@@ -45,6 +63,7 @@
<td scope="col"><b>Last update</b></td>
<td scope="col"><b>Battery</b></td>
<td scope="col"><b>Send to GPS module</b></td>
<th>&nbsp;</th>
</tr>
</thead>
<tbody>
@@ -65,6 +84,12 @@
<a class="btn btn-danger" href="?view_mode=send_switch&id=[#ID_USER#]" >Off</a>
[#endif SENDTOGPS#]
</td>
<td width="1%" nowrap>
[#if "<#ACTION#>"=="admin"#]
<a href="?view_mode=user_delete&id=[#ID#]" onClick="return confirm('<#LANG_ARE_YOU_SURE#>')" class="btn btn-default btn-sm" title="<#LANG_DELETE#>"><i class="glyphicon glyphicon-remove"></i></a>
[#endif ACTION#]
</td>

</tr>
[#end LOCATIONS#]
</tbody>

0 comments on commit 5e08d32

Please sign in to comment.
You can’t perform that action at this time.