Skip to content

Commit

Permalink
FIX #919 check for Easy-Wi updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ulrichblock committed Oct 3, 2016
1 parent ec05408 commit 55ec11a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 9 deletions.
35 changes: 34 additions & 1 deletion reboot.php
Expand Up @@ -70,9 +70,43 @@
$currentDays = date('t');
$currentHour = date('G');
}

$now = date('Y-m-d', strtotime('now'));
$sprache = getlanguagefile('gserver', 'uk', 0);

echo "Fetch Easy-Wi version\r\n";

licenceRequest();

$developerVersion = (isset($rSA['developer']) and $rSA['developer'] == 'Y') ? ' developer' : '';

$query = $sql->prepare("SELECT `version` FROM `easywi_version` ORDER BY `id` DESC LIMIT 1");
$query->execute();
$installedEasyWiVersion = $query->fetchColumn();

if (version_compare($rSA['version'], $installedEasyWiVersion) == 1) {

echo "New Easy-Wi{$developerVersion} version available: {$rSA['version']}\r\n";

if (date('G') == 5) {

$updateMail = "A new Easy-Wi{$developerVersion} version is available. The version is {$rSA['version']}.\r\nYou can download it at https://github.com/easy-wi/developer/releases/tag/{$rSA['version']}";

$query = $sql->prepare("SELECT `id`,`cname`,`mail` FROM `userdata` WHERE `accounttype`='a' AND `active`='Y'");
$query->execute();
while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
if (sendmail('easy-wi-update', $row['id'], $updateMail, 'Y')) {
echo "Update notification send to user {$row['cname']} ({$row['mail']})\r\n";
} else {
echo "Sending update notification to user {$row['cname']} ({$row['mail']}) failed\r\n";
}
}
}

} else {
echo "You are running the latest Easy-Wi{$developerVersion} version: {$installedEasyWiVersion}.\r\n";
}

echo "Fetch version for Teamspeak 3 Server\r\n";

$query = $sql->prepare("UPDATE `voice_masterserver` SET `latest_version`=? WHERE `bitversion`=?");
Expand Down Expand Up @@ -435,7 +469,6 @@
}

usleep(500000);

}
}

Expand Down
2 changes: 1 addition & 1 deletion stuff/admin/versioncheck.php
Expand Up @@ -280,7 +280,7 @@ function rmr($dir) {

$table = array();

$release = '<div class="right"><a href="https://github.com/easy-wi/developer/releases/tag/'.$ewVersions['version'] . '" target="_blank">' . $vcsprache->releaseNotes . '</a></div>';
$release = '<div class="right"><a href="https://github.com/easy-wi/developer/releases/tag/' . $ewVersions['version'] . '" target="_blank">' . $vcsprache->releaseNotes . '</a></div>';
$column = ($user_language == 'de') ? 'de' : 'en';

$query = $sql->prepare("SELECT `version`,`$column` FROM `easywi_version` ORDER BY `id` DESC");
Expand Down
24 changes: 17 additions & 7 deletions stuff/methods/functions.php
Expand Up @@ -683,12 +683,18 @@ function sendmail($template, $userid, $server, $shorten, $connectInfo = array())
$email_lastlogin = $row['lastlogin'];
}

if (!isset($resellerid) or !isset($email_country)) {
if ($template != 'contact' and $template != 'easy-wi-update' and (!isset($resellerid) or !isset($email_country))) {
return false;
}

$dataTemplate = array();
$email_urlhost = (isset($ui->server['HTTPS'])) ? 'https://' . $ui->server['HTTP_HOST'] . '/login.php' : 'http://' . $ui->server['HTTP_HOST'] . '/login.php';

// Will not be set in case of console execution
if (isset($ui->server['HTTP_HOST'])) {
$email_urlhost = (isset($ui->server['HTTPS'])) ? 'https://' . $ui->server['HTTP_HOST'] . '/login.php' : 'http://' . $ui->server['HTTP_HOST'] . '/login.php';
} else {
$email_urlhost = $rSA['paneldomain'] . '/login.php';
}

$password = $shorten;

Expand Down Expand Up @@ -726,7 +732,7 @@ function sendmail($template, $userid, $server, $shorten, $connectInfo = array())
} else if (isset($dataTemplate['subject'])) {
//Topic/Subject
$topic = $dataTemplate['subject'];
} else {
} else if ($template != 'contact' and $template != 'easy-wi-update') {
return false;
}

Expand Down Expand Up @@ -762,6 +768,10 @@ function sendmail($template, $userid, $server, $shorten, $connectInfo = array())
$mailBody = $server;
$usermail = $resellermail;

} else if ($template == 'easy-wi-update') {
$startMail = true;
$topic = 'An Easy-Wi update has been released';
$mailBody = $server;
} else {

if ($resellerid == $userid) {
Expand Down Expand Up @@ -1221,16 +1231,16 @@ function licenceRequest($return = false) {

$developer = (isset($rSA['developer'])) ? $rSA['developer'] : 'N';

$apiResponse = webhostRequest('api.github.com', $ui->server['HTTP_HOST'], '/repos/easy-wi/developer/' . (($developer == 'Y') ? 'tags' : 'releases/latest'), null, 443);
$apiResponse = webhostRequest('api.github.com', isset($ui->server['HTTP_HOST']) ? $ui->server['HTTP_HOST'] : $rSA['paneldomain'], '/repos/easy-wi/developer/' . (($developer == 'Y') ? 'tags' : 'releases/latest'), null, 443);
$json = @json_decode($apiResponse);

if (($developer == 'N' and is_object($json) and property_exists($json, 'tag_name') or ($developer == 'Y' and is_array($json) and isset($json[0]) and is_object($json[0]) and property_exists($json[0], 'name')))) {

$varsion = ($developer == 'Y') ? $json[0]->name : $json->tag_name;
$apiResponse = array('v' => $varsion);
$version = ($developer == 'Y') ? $json[0]->name : $json->tag_name;
$apiResponse = array('v' => $version);

$query = $sql->prepare("UPDATE `settings` SET `version`=? WHERE `resellerid`=0 LIMIT 1");
$query->execute(array($varsion));
$query->execute(array($version));
}

return ($return == true) ? $apiResponse : false;
Expand Down

0 comments on commit 55ec11a

Please sign in to comment.