admanage validate starttime&end_time and announce check peer

This commit is contained in:
xiaomlove
2022-02-01 16:05:44 +08:00
parent 8d6d9d8c15
commit ed7d51739a
6 changed files with 48 additions and 36 deletions
+6 -4
View File
@@ -291,10 +291,12 @@ function get_setting($name = null)
$result = sql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
$value = $row['value'];
$arr = json_decode($value, true);
if (is_array($arr)) {
$value = $arr;
}
if (!is_null($value)) {
$arr = json_decode($value, true);
if (is_array($arr)) {
$value = $arr;
}
}
arr_set($settings, $row['name'], $value);
}
}
+2 -2
View File
@@ -71,8 +71,8 @@ $lang_admanage = array
'text_forum_post_page_note' => "显示在论坛主题详情页面的帖子间。建议广告尺寸为600x160。可同时显示多个广告。",
'text_popup_note' => "在所有页面谈促。极具侵扰性,请慎用。建议广告尺寸为468x90。",
'text_name_note' => "给广告命名,便于识别。",
'text_start_time_note' => "时间格式为'年年年年-月月-日日 时时:分分:秒秒',如'2007-12-24 21:00:00'。广告起始生效的时间。<br />如留空则广告将马上生效。",
'text_end_time_note' => "时间格式为'年年年年-月月-日日 时时:分分:秒秒',如'2008-01-24 21:00:00'。广告结束的时间。<br />如留空则广告永不结束,直到添加了新的广告。",
'text_start_time_note' => "时间格式为'年年年年-月月-日日 时时:分分:秒秒',如'2007-12-24 21:00:00'。广告起始生效的时间。",
'text_end_time_note' => "时间格式为'年年年年-月月-日日 时时:分分:秒秒',如'2008-01-24 21:00:00'。广告结束的时间。",
'text_order_note' => "广告的显示优先级。数值'0'具有最高的优先级。<br />当某个广告位置具有多个有效广告:如果该位置只允许一个广告,将显示优先级最高的广告;如果该位置允许多个广告,将按照优先级从高到低顺序显示多个广告。如多个广告具有相同的优先级,最近添加的广告将具有高优先权。",
'text_enabled_note' => "只有启用的广告才会显示。",
'text_type_note' => "选择广告的展现方式。",
+2 -2
View File
@@ -71,8 +71,8 @@ $lang_admanage = array
'text_forum_post_page_note' => "察看在論壇主題詳情頁面的帖子間。建議廣告大小為600x160。可同時察看多個廣告。",
'text_popup_note' => "在所有頁面談促。極具侵擾性,請慎用。建議廣告大小為468x90。",
'text_name_note' => "給廣告命名,便于識別。",
'text_start_time_note' => "時間格式為'年年年年-月月-日日 時時:分分:秒秒',如'2007-12-24 21:00:00'。廣告起始生效的時間。<br />如留空則廣告將馬上生效。",
'text_end_time_note' => "時間格式為'年年年年-月月-日日 時時:分分:秒秒',如'2008-01-24 21:00:00'。廣告結束的時間。<br />如留空則廣告永不結束,直到添加了新的廣告。",
'text_start_time_note' => "時間格式為'年年年年-月月-日日 時時:分分:秒秒',如'2007-12-24 21:00:00'。廣告起始生效的時間。",
'text_end_time_note' => "時間格式為'年年年年-月月-日日 時時:分分:秒秒',如'2008-01-24 21:00:00'。廣告結束的時間。",
'text_order_note' => "廣告的察看優先級。數值'0'具有最高的優先級。<br />當某個廣告位置具有多個有效廣告:如果該位置只允許一個廣告,將察看優先級最高的廣告;如果該位置允許多個廣告,將按照優先級從高到低順序察看多個廣告。如多個廣告具有相同的優先級,最近添加的廣告將具有高優先權。",
'text_enabled_note' => "只有啟用的廣告才會察看。",
'text_type_note' => "選取廣告的展現方式。",
+2 -2
View File
@@ -71,8 +71,8 @@ $lang_admanage = array
'text_forum_post_page_note' => "Show between forum posts on forum topic detail page. Recommended size is 600 * 160. Several ads will show together.",
'text_popup_note' => "Popup on every page. Very disturbing, use with caution. Recommended size is 468 * 90",
'text_name_note' => "Just a name to call the ad.",
'text_start_time_note' => "In format of YYYY-MM-DD hh:mm:ss, e.g. '2007-12-24 21:00:00'. The time since when the ad becomes available. <br />If blank, the ad becomes available immediately.",
'text_end_time_note' => "In format of YYYY-MM-DD hh:mm:ss, e.g. '2008-01-24 21:00:00'. The time until when the ad is available. <br />If blank, the ad will never become unavailable unless new ads are added. ",
'text_start_time_note' => "In format of YYYY-MM-DD hh:mm:ss, e.g. '2007-12-24 21:00:00'. The time since when the ad becomes available.",
'text_end_time_note' => "In format of YYYY-MM-DD hh:mm:ss, e.g. '2008-01-24 21:00:00'. The time until when the ad is available.",
'text_order_note' => "The priority of ads. Value '0' gets the top priority. <br />When several ads are available for a position, the one with the highest priority will show if the position allows only one ad, and those with higher priorities will show on top if the position allows several ads. When several available ads have the same priority value, the most recently added one has the highest priority. ",
'text_enabled_note' => "Only enabled ads will show. ",
'text_type_note' => "Choose the display method of ads. ",
+3 -3
View File
@@ -126,8 +126,8 @@ function print_ad_editor($position, $row = "")
<table border="1" cellspacing="0" cellpadding="10" width="100%">
<?php
tr($lang_admanage['row_name']."<font color=\"red\">*</font>", "<input type=\"text\" name=\"ad[name]\" value=\"".htmlspecialchars($name)."\" style=\"width: 300px\" /> " . $lang_admanage['text_name_note'], 1);
tr($lang_admanage['row_start_time'], "<input type=\"text\" name=\"ad[starttime]\" value=\"".$starttime."\" style=\"width: 300px\" /> " . $lang_admanage['text_start_time_note'], 1);
tr($lang_admanage['row_end_time'], "<input type=\"text\" name=\"ad[endtime]\" value=\"".$endtime."\" style=\"width: 300px\" /> ".$lang_admanage['text_end_time_note'], 1);
tr($lang_admanage['row_start_time']."<font color=\"red\">*</font>", "<input type=\"text\" name=\"ad[starttime]\" value=\"".$starttime."\" style=\"width: 300px\" /> " . $lang_admanage['text_start_time_note'], 1);
tr($lang_admanage['row_end_time']."<font color=\"red\">*</font>", "<input type=\"text\" name=\"ad[endtime]\" value=\"".$endtime."\" style=\"width: 300px\" /> ".$lang_admanage['text_end_time_note'], 1);
tr($lang_admanage['row_order'], "<input type=\"text\" name=\"ad[displayorder]\" value=\"".$displayorder."\" style=\"width: 100px\" /> ".$lang_admanage['text_order_note'], 1);
tr($lang_admanage['row_enabled']."<font color=\"red\">*</font>", "<input type=\"radio\" name=\"ad[enabled]\"".($enabled ? " checked=\"checked\"" : "")." value=\"1\" />".$lang_admanage['text_yes']."<input type=\"radio\" name=\"ad[enabled]\"".($enabled ? "" : " checked=\"checked\"")." value=\"0\" />".$lang_admanage['text_no']."<br />".$lang_admanage['text_enabled_note'], 1);
tr($lang_admanage['row_type']."<font color=\"red\">*</font>", "<select name=\"ad[type]\" onchange=\"var key, types; types=new Array('image','text','bbcodes','xhtml','flash'); for(key in types){var obj=$('type_'+types[key]); obj.style.display=types[key]==this.options[this.selectedIndex].value?'':'none';}\"><option value=\"image\"".($type == 'image' ? " selected=\"selected\"" : "").">".$lang_admanage['text_image']."</option><option value=\"text\"".($type == 'text' ? " selected=\"selected\"" : "").">".$lang_admanage['text_text']."</option><option value=\"bbcodes\"".($type == 'bbcodes' ? " selected=\"selected\"" : "").">".$lang_admanage['text_bbcodes']."</option>".(get_user_class() >= $allowxhtmlclass ? "<option value=\"xhtml\"".($type == 'xhtml' ? " selected=\"selected\"" : "").">".$lang_admanage['text_xhtml']."</option>" : "")."<option value=\"flash\"".($type == 'flash' ? " selected=\"selected\"" : "").">".$lang_admanage['text_flash']."</option></select> ".$lang_admanage['text_type_note'], 1);
@@ -280,7 +280,7 @@ elseif ($action == 'submit')
$displayorder = intval($_POST['ad']['displayorder'] ?? 0);
$enabled = intval($_POST['ad']['enabled'] ?? 0);
$type = $_POST['ad']['type'];
if (!$name || !$type)
if (!$name || !$type || !$starttime || !$endtime)
{
stderr($lang_admanage['std_error'], $lang_admanage['std_missing_form_data']);
}
+33 -23
View File
@@ -424,32 +424,42 @@ elseif(isset($self))
}
else
{
if (strlen($ip) > 15) {
$sockres = @pfsockopen("tcp://[".$ip."]",$port,$errno,$errstr,1);
if ($event != 'stopped') {
$isPeerExistResultSet = sql_query("select id from peers where $selfwhere limit 1");
if ($isPeerExistResultSet && !mysqli_fetch_assoc($isPeerExistResultSet)) {
if (strlen($ip) > 15) {
$sockres = @pfsockopen("tcp://[".$ip."]",$port,$errno,$errstr,1);
} else {
$sockres = @pfsockopen($ip, $port, $errno, $errstr, 1);
}
if (!$sockres)
{
$connectable = "no";
}
else
{
$connectable = "yes";
@fclose($sockres);
}
sql_query("INSERT INTO peers (torrent, userid, peer_id, ip, port, connectable, uploaded, downloaded, to_go, started, last_action, seeder, agent, downloadoffset, uploadoffset, passkey) VALUES ($torrentid, $userid, ".sqlesc($peer_id).", ".sqlesc($ip).", $port, '$connectable', $uploaded, $downloaded, $left, $dt, $dt, '$seeder', ".sqlesc($agent).", $downloaded, $uploaded, ".sqlesc($passkey).")") or err("PL Err 2");
if (mysql_affected_rows())
{
$updateset[] = ($seeder == "yes" ? "seeders = seeders + 1" : "leechers = leechers + 1");
$check = @mysql_fetch_row(@sql_query("SELECT COUNT(*) FROM snatched WHERE torrentid = $torrentid AND userid = $userid"));
if (!$check['0'])
sql_query("INSERT INTO snatched (torrentid, userid, ip, port, uploaded, downloaded, to_go, startdat, last_action) VALUES ($torrentid, $userid, ".sqlesc($ip).", $port, $uploaded, $downloaded, $left, $dt, $dt)") or err("SL Err 4");
else
sql_query("UPDATE snatched SET to_go = $left, last_action = ".$dt ." WHERE torrentid = $torrentid AND userid = $userid") or err("SL Err 3.1");
}
} else {
do_log("[INSERT PEER] peer already exists for $selfwhere.");
}
} else {
$sockres = @pfsockopen($ip, $port, $errno, $errstr, 1);
do_log("[INSERT PEER] event = 'stopped', ignore.");
}
if (!$sockres)
{
$connectable = "no";
}
else
{
$connectable = "yes";
@fclose($sockres);
}
sql_query("INSERT INTO peers (torrent, userid, peer_id, ip, port, connectable, uploaded, downloaded, to_go, started, last_action, seeder, agent, downloadoffset, uploadoffset, passkey) VALUES ($torrentid, $userid, ".sqlesc($peer_id).", ".sqlesc($ip).", $port, '$connectable', $uploaded, $downloaded, $left, $dt, $dt, '$seeder', ".sqlesc($agent).", $downloaded, $uploaded, ".sqlesc($passkey).")") or err("PL Err 2");
if (mysql_affected_rows())
{
$updateset[] = ($seeder == "yes" ? "seeders = seeders + 1" : "leechers = leechers + 1");
$check = @mysql_fetch_row(@sql_query("SELECT COUNT(*) FROM snatched WHERE torrentid = $torrentid AND userid = $userid"));
if (!$check['0'])
sql_query("INSERT INTO snatched (torrentid, userid, ip, port, uploaded, downloaded, to_go, startdat, last_action) VALUES ($torrentid, $userid, ".sqlesc($ip).", $port, $uploaded, $downloaded, $left, $dt, $dt)") or err("SL Err 4");
else
sql_query("UPDATE snatched SET to_go = $left, last_action = ".$dt ." WHERE torrentid = $torrentid AND userid = $userid") or err("SL Err 3.1");
}
}
if (count($updateset)) // Update only when there is change in peer counts