我目前正在开发一个用PHP进行系统更改的项目(例如,更改Nginx /重启服务的配置文件).
PHP脚本在localhost上运行.在我看来,最好的(读取:最安全)方式是使用SSH建立连接.我考虑以下选项之一:
选项1:在php会话中存储用户名/密码并提示输入sudo
使用带有用户名/密码的phpseclib,将这些值保存在php会话中,并为每个命令提示sudo.
选项2:使用root登录
在登录脚本中使用phpseclib和root用户名和密码.在这种情况下,您不必向用户询问sudo.(不是真正安全的解决方案)
<?php
include('Net/SSH2.php');
$ssh = new Net_SSH2('www.domain.tld');
if (!$ssh->login('root', 'root-password')) {
exit('Login Failed');
}
?>
Run Code Online (Sandbox Code Playgroud)
选项3:使用从文件中读取的公钥进行身份验证
使用带有公钥的PHP SSHlib进行身份验证,并将pubkey放在www root之外.
<?php
$connection = ssh2_connect('shell.example.com', 22, array('hostkey' => 'ssh-rsa'));
if (ssh2_auth_pubkey_file($connection, 'username', '/home/username/.ssh/id_rsa.pub', '/home/username/.ssh/id_rsa', 'secret')) {
echo "Public Key Authentication Successful\n";
} else {
die('Public Key Authentication Failed');
}
?>
Run Code Online (Sandbox Code Playgroud)
方案4:?
我有一个关于如何使用Chrome扩展程序更改网页的问题.
在阅读了一些信息后,我认为问题是如何操纵DOM.假设我使用Chrome打开www.stackoverflow并想要替换以下代码行:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
Run Code Online (Sandbox Code Playgroud)
并替换为:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.2.min.js"></script>
Run Code Online (Sandbox Code Playgroud)
我的问题不是,如果它是一个聪明的事情,但如何做到这一点?
我尝试通过Linq在我的ASP MVC应用程序中添加前导零:
int length = 4;
IEnumerable<object> query = [...]
select new
{
Seq = a.Seq.ToString("D" + length),
}).OrderBy(a =>a.Seq).ToList();
Run Code Online (Sandbox Code Playgroud)
..但我收到以下错误:
Additional information: LINQ to Entities does not recognize the method 'System.String ToString(System.String)' method, and this method cannot be translated into a store expression.
Run Code Online (Sandbox Code Playgroud)
这样做的正确方法是什么?
我尝试在我的Controller中使用以下方法将实体框架对象作为Json返回:
public JsonResult EventList() {
var results = from s in db.Events
select new
{
OrderID = s.EventID,
OrderTitle =s.EventType,
OrderDate = s.Title
};
return Json(results);
}
Run Code Online (Sandbox Code Playgroud)
进入页面/ events/EventList /时,我收到服务器错误500.此外,Jquery get请求不返回任何数据.以Json格式返回结果的正确方法是什么?
更新:
这似乎有效.但我需要数据库的结果.
public ActionResult EventList() {
Event test = new Event
{
EventID = 1,
Title = "test",
Description = "test"
};
return Json(new { event = test }, JsonRequestBehavior.AllowGet);
}
Run Code Online (Sandbox Code Playgroud) 我做了几次测试并阅读了很多Neo4J用于基于图形搜索的案例.我相信灵活的架构和实时搜索和检索的功能.但我也意识到它不是为了便于全文搜索而存储文档.对我而言,该产品的潜力通过数据关系实现商业价值.
该产品与我的案例匹配99%:我工作的公司的"内部谷歌",除了文档的全文搜索(Word,PDF等).这不是一个硬性要求,但是很高兴.不过,我应该放弃具体的Neo4J功能并购买像Elastic Search这样的产品,还是Neo4J我们正在寻找的产品?
我正在使用以下函数将_blank添加到我网站上的所有链接.
function targetBlank($text) {
$return = str_replace('<a', '<a target="_blank"', $text);
return $return;
}
Run Code Online (Sandbox Code Playgroud)
我正在寻找一种解决方案,只在外部链接(不在我的域上)而不是所有链接上应用此功能.
我尝试在LINQ中创建以下SQL查询以在我的ASP MVC项目中使用:
SELECT State, (Count(a.State)* 100 / (Select Count(*) From myTable))
FROM myTable a
GROUP BY a.State
Run Code Online (Sandbox Code Playgroud)
到目前为止我所拥有的:
var data = db.myTable.GroupBy(fu => fu.State)
.Select(g => new { Label = g.Key, Value = g.Key * 100 / g.Count() })
.ToList();
Run Code Online (Sandbox Code Playgroud)
计算不正确.必须让LINQ产生与SQL相同的结果?
我正在尝试从Sharepoint库中检索所有项目CSOM并创建它的列表。我确信它与代码的顺序有关。问题是如何?
ListItemCollection collListItem = oList.GetItems(camlQuery);
var newList = new List<Item>();
var items = oList.GetItems(camlQuery);
context.Load(collListItem);
context.ExecuteQuery();
foreach (var col in items)
{
newList.Add(new Item()
{
ID = Convert.ToInt32(col["ID"]),
});
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
集合尚未初始化。尚未请求或尚未执行请求。可能需要明确要求
我正在开发一个HTML5移动应用程序.该应用程序仅使用包含登录表单的1个html文件.在提交javascript时,将用户名和密码发布到服务器上的php脚本,该脚本返回'true'或'false'.
当身份验证返回true时,应用程序将更改html5页面并将用户名和密码存储在html5本地存储中.
由于这是敏感数据,我的问题是如何以安全的方式存储这些值?
function handleLogin() {
var form = $("#loginForm");
var u = $("#username", form).val();
var p = $("#password", form).val();
if(u != '' && p!= '') {
$.post("http://www.mywebsite.com/login.php", {username:u,password:p}, function(res) {
if(res == true) {
//store
window.localStorage["username"] = u;
window.localStorage["password"] = p;
$.mobile.changePage("index-2.html");
} else {
/// error message
}
$("#submitButton").removeAttr("disabled");
},"json");
}
return false; }
Run Code Online (Sandbox Code Playgroud) 我正在使用以下代码从SQL Server获取结果:
string content = "Test value"
try {
SqlDataReader myReader = null;
SqlCommand myCommand = new SqlCommand("select name from Persons",
myConnection);
myReader = myCommand.ExecuteReader();
while(myReader.Read())
{
Console.WriteLine("- " + myReader["name"].ToString());
}
} catch (Exception e) {
Console.WriteLine(e.ToString());
}
Run Code Online (Sandbox Code Playgroud)
我想要的是在4个结果之后在while循环中插入字符串"Content"的值,例如:
c# ×4
php ×3
asp.net-mvc ×2
javascript ×2
jquery ×2
linq ×2
sql ×2
csom ×1
dom ×1
graph ×1
html5 ×1
json ×1
linux ×1
neo4j ×1
search ×1
sharepoint ×1
sql-server ×1
ssh ×1
str-replace ×1
uri ×1