Skip to content

Instantly share code, notes, and snippets.

@palemoky
Created July 9, 2020 15:12
Show Gist options
  • Save palemoky/cceb5765305e257bb4e1628a3be055d3 to your computer and use it in GitHub Desktop.
Save palemoky/cceb5765305e257bb4e1628a3be055d3 to your computer and use it in GitHub Desktop.
Synology login page automatically replaces bing wallpaper
<?php
// 获取图片信息
$img_info = file_get_contents('https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&pid=hp&FORM=BEHPTB&video=1');
// 请求失败时,使用「Server 酱」将错误信息推送至绑定的微信
if (false === $img_info) {
file_get_contents('https://sc.ftqq.com/xxx.send?text=' . urlencode('Get bing wallpaper error!'));
}
$img_obj = json_decode($img_info)->images[0];
//获取图片地址
$img_url = 'https://cn.bing.com'.$img_obj->url;
// 获取图片名
$url_params = parse_url($img_url)['query'];
parse_str($url_params, $result);
$filename = $result['id'];
// 下载图片并保存
$img_rsc = file_get_contents($img_url);
file_put_contents('/path/to/bing_wallpaper/' . $filename, $img_rsc);
// 将图片复制到目标位置
copy('/path/to/bing_wallpaper/' . $filename, '/usr/syno/etc/login_background.jpg');
copy('/path/to/bing_wallpaper/' . $filename, '/usr/syno/etc/login_background_hd.jpg');
// 获取图片描述信息
list($msg, $title) = explode('(', rtrim($img_obj->copyright, ')'));
// 修改欢迎信息
shell_exec('sed -i "/login_welcome_title/c login_welcome_title=\"' . $title . '\"" /etc/synoinfo.conf');
shell_exec('sed -i "/login_welcome_msg/c login_welcome_msg=\"' . $msg . '\"" /etc/synoinfo.conf');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment