diff options
Diffstat (limited to 'modules-available/remoteaccess/api.inc.php')
-rw-r--r-- | modules-available/remoteaccess/api.inc.php | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/modules-available/remoteaccess/api.inc.php b/modules-available/remoteaccess/api.inc.php index 2e1e4bf9..c558d126 100644 --- a/modules-available/remoteaccess/api.inc.php +++ b/modules-available/remoteaccess/api.inc.php @@ -5,27 +5,47 @@ if (substr($ip, 0, 7) === '::ffff:') $ip = substr($ip, 7); $password = Request::post('password', false, 'string'); if ($password !== false) { - $c = Database::queryFirst("SELECT machineuuid FROM machine WHERE clientip = :ip", ['ip' => $ip]); + $c = Database::queryFirst("SELECT machineuuid FROM machine + WHERE clientip = :ip + ORDER BY lastseen DESC + LIMIT 1", ['ip' => $ip]); if ($c !== false) { - Database::exec("INSERT INTO remoteaccess_machine (machineuuid, password) - VALUES (:uuid, :passwd) - ON DUPLICATE KEY UPDATE password = VALUES(password)", ['uuid' => $c['machineuuid'], 'passwd' => $password]); + $vncport = Request::post('vncport', 5900, 'int'); + Database::exec("INSERT INTO remoteaccess_machine (machineuuid, password, vncport) + VALUES (:uuid, :passwd, :vncport) + ON DUPLICATE KEY UPDATE + password = VALUES(password), vncport = VALUES(vncport)", + ['uuid' => $c['machineuuid'], 'passwd' => $password, 'vncport' => $vncport]); } exit; } $range = IpUtil::parseCidr(Property::get(RemoteAccess::PROP_ALLOWED_VNC_NET)); -if ($range === false) { +if ($range === null) { die('No allowed IP defined'); } $iplong = ip2long($ip); -if (PHP_INT_SIZE === 4) { - $iplong = sprintf('%u', $iplong); -} if ($iplong < $range['start'] || $iplong > $range['end']) { die('Access denied'); } +$headers = getallheaders(); +$version = false; +if (!empty($headers['Bwlp-Plugin-Build-Revision'])) { + $version = substr($headers['Bwlp-Plugin-Build-Revision'], 0, 6); + if (!empty($headers['Bwlp-Plugin-Build-Timestamp'])) { + $ts = $headers['Bwlp-Plugin-Build-Timestamp']; + if (is_numeric($ts)) { + if ($ts > 9999999999) { + $ts = round($ts / 1000); + } + $ts = date('d.m.Y H:i', $ts); + } + $version .= ' (' . $ts . ')'; + } +} +Property::set(RemoteAccess::PROP_PLUGIN_VERSION, $version, 2880); + Header('Content-Type: application/json'); $remoteLocations = RemoteAccess::getEnabledLocations(); @@ -35,7 +55,7 @@ if (empty($remoteLocations)) { } else { // TODO fail-counter for WOL, so we can ignore machines that apparently can't be woken up // -> Reset counter in our ~poweron hook, but only if the time roughly matches a WOL attempt (within ~5 minutes) - $rows = Database::queryAll("SELECT m.clientip, m.locationid, m.state, ram.password, ram.woltime FROM machine m + $rows = Database::queryAll("SELECT m.clientip, m.locationid, m.state, ram.password, ram.vncport, ram.woltime FROM machine m LEFT JOIN remoteaccess_machine ram ON (ram.machineuuid = m.machineuuid AND (ram.password IS NOT NULL OR m.state <> 'IDLE')) LEFT JOIN runmode r ON (r.machineuuid = m.machineuuid) WHERE m.locationid IN (:locs) @@ -48,6 +68,7 @@ if (empty($remoteLocations)) { $row['wol_in_progress'] = true; } settype($row['locationid'], 'int'); + settype($row['vncport'], 'int'); unset($row['woltime']); } } |