super_cert.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. <?php
  2. namespace app\admin;
  3. use MingYuanYun\AppStore\Client;
  4. class super_cert extends Base
  5. {
  6. public $loadingImg = "<img src=\"/static/pack/layer/theme/default/loading-2.gif\" width=\"15px\" style=\"position: relative;top: -2px;display: none;\">";
  7. public function initialize()
  8. {
  9. parent::initialize();
  10. $this->Administrator(3);
  11. if (in_array($this->action, ["index", "edit"])) {
  12. $this->header();
  13. }
  14. }
  15. public function __destruct()
  16. {
  17. if (in_array($this->action, ["index", "edit"])) {
  18. $this->footer();
  19. }
  20. }
  21. function index($map = [])
  22. {
  23. $this->search = SafeRequest("search", "get");
  24. $this->search && ($map[] = ["iss|tid|kid|username", "like", "%" . $this->search . "%"]);
  25. $this->type = SafeRequest("type", "get");
  26. is_numeric($this->type) && ($map[] = ["type", "=", $this->type]);
  27. $this->uid = SafeRequest("uid", "get");
  28. is_numeric($this->uid) && ($map[] = ["user_id", $this->uid ? "<>" : "=", 0]);
  29. $this->mapTime("create_time", true, $map);
  30. $_var_0 = SafeRequest("iss", "get");
  31. $_var_0 && ($map[] = ["iss", "=", $_var_0]);
  32. $_var_1 = SafeRequest("page", "get");
  33. $_var_2 = db("super_cert")->where($map)->order("id desc")->paginate(["page" => $_var_1]);
  34. $_var_3 = db("super_cert")->where($map)->sum("total_count");
  35. $_var_4 = db("super_cert")->where("limit_count", ">", 0)->where($map)->sum("limit_count");
  36. $_var_5 = $_var_2->items();
  37. $_var_6 = getRender($_var_2, $_var_1);
  38. $_var_7 = $_var_2->total();
  39. ?> <div class="container">
  40. <?php
  41. $this->searchForm("", "", function () {
  42. ?> <select name="uid" onchange="document.btnsearch.submit();">
  43. <option value="">全部证书</option>
  44. <option value="0" <?php echo is_numeric($this->uid) && $this->uid == "0" ? "selected=\"selected\"" : "";?>>
  45. 平台证书
  46. </option>
  47. <option value="1" <?php echo is_numeric($this->uid) && $this->uid == "1" ? "selected=\"selected\"" : "";?>>
  48. 用户证书
  49. </option>
  50. </select>
  51. <select name="type" onchange="document.btnsearch.submit();">
  52. <option value="">全部类型</option>
  53. <option value="0" <?php echo is_numeric($this->type) && $this->type == "0" ? "selected=\"selected\"" : "";?>>
  54. p8
  55. </option>
  56. <option value="1" <?php echo is_numeric($this->type) && $this->type == "1" ? "selected=\"selected\"" : "";?>>
  57. fastlane
  58. </option>
  59. </select>
  60. <?php
  61. }, function () {
  62. ?> <a href="https://appstoreconnect.apple.com/access/api" target="_blank"
  63. style="padding-left: 20px">获取P8证书</a>
  64. <?php
  65. });
  66. ?> <form name="form" method="post" action="?c=super_cert&a=allsave">
  67. <td> <a href="javascript:;" onclick="x_admin_show('添加证书','?c=super_cert&amp;a=edit')"><input type="button" value="添加证书" class="layui-btn"></a></td>
  68. <table class="layui-table">
  69. <tr>
  70. <th class="partition">证书列表</th>
  71. <th class="partition" colspan="99">
  72. <span>总计(<?php echo $_var_7;?>)</span>
  73. <span>被封号(<?php echo db("super_cert")->where("status", -1)->count();?>)</span>
  74. <span>未启用(<?php echo db("super_cert")->where("status", 0)->count();?>)</span>
  75. <span>使用中(<?php echo db("super_cert")->where("status", 1)->count();?>)</span>
  76. <span>疑封号(<?php echo db("super_cert")->where("status", 401)->count();?>)</span>
  77. <span>无权限(<?php echo db("super_cert")->where("status", 403)->count();?>)</span>
  78. </th>
  79. </tr>
  80. <tr class="header">
  81. <th>ID</th>
  82. <th>用户</th>
  83. <th>Iss</th>
  84. <th>Kid</th>
  85. <th>Tid</th>
  86. <th>P8</th>
  87. <th>P12</th>
  88. <th>P12密码</th>
  89. <th>已使用(<?php echo $_var_3;?>)</th>
  90. <th>剩余(<?php echo $_var_4;?>)</th>
  91. <th>类型</th>
  92. <th>添加时间</th>
  93. <th>到期时间</th>
  94. <th>备注</th>
  95. <th>状态</th>
  96. <th colspan="5">操作</th>
  97. </tr>
  98. <?php
  99. if ($_var_7 == 0) {
  100. ?><tr> <td colspan="22" style="margin:auto;text-align:center" >暂无数据</td></tr><?php
  101. } else {
  102. foreach ($_var_5 as $_var_8) {
  103. $_var_9 = $_var_8["user_id"] < 1 ? "公用" : db("user")->where("in_userid", $_var_8["user_id"])->value("in_username");
  104. $_var_10 = db("ios_device")->where("cert_iss", $_var_8["iss"])->group("udid")->count();
  105. ?><tr class="hover">
  106. <td class="td25"><input class="checkbox" type="checkbox" name="in_id[]" id="in_id" value="<?php echo $_var_8["id"];?>"><?php echo $_var_8["id"];?></td>
  107. <td class="td29"><?php echo $_var_9;?></td>
  108. <td class="td29"><?php echo $_var_8["iss"];?></td>
  109. <td class="td29"><?php echo $_var_8["kid"];?></td>
  110. <td class="td29"><?php echo $_var_8["tid"];?></td>
  111. <td><a href="/download/cert/<?php echo bees_encrypt($_var_8["id"] . ".8." . time());?>">下载</a></td>
  112. <td><a href="/download/cert/<?php echo bees_encrypt($_var_8["id"] . ".12." . time());?>">下载</a></td>
  113. <td><?php echo $_var_8["p12_pwd"];?></td>
  114. <td class="td29"><?php echo $_var_8["total_count"];?></td>
  115. <td class="td29"><?php echo $_var_8["limit_count"];?></td>
  116. <td class="td29"><?php echo $_var_8["type"] ? "fastlane" : "p8";?></td>
  117. <td class="td29"><?php echo date("Y-m-d", $_var_8["create_time"]);?></td>
  118. <td class="td29"><?php echo date("Y-m-d", $_var_8["expirationDate"]);?></td>
  119. <td class="td29"><?php echo $_var_8["mark"];?></td>
  120. <td><div class="parentboard"><?php echo ["-1" => lightnum("被封号"), "0" => lightnum("未启用"), "1" => "使用中", "401" => lightnum("疑封号"), "403" => lightnum("无权限")][$_var_8["status"]];?> [<?php echo $_var_8["status"];?>] </div></td>
  121. <td>
  122. <?php echo $_var_10 ? "<a href=\"?c=ios_device&a=index&iss=" . $_var_8["iss"] . "\">查看设备(" . $_var_10 . ")</a>" : "";?><?php
  123. if ($_var_8["status"]) {
  124. ?><a href="javascript:;" class="act status_off<?php echo $_var_8["id"];?>" onclick="doAction('change_status',{id:<?php echo $_var_8["id"];?>,status:0},this)">停用<?php echo $this->loadingImg;?></a><?php
  125. } else {
  126. ?><a href="javascript:;" class="act status_on<?php echo $_var_8["id"];?>" onclick="doAction('change_status',{id:<?php echo $_var_8["id"];?>,status:1},this)">启用<?php echo $this->loadingImg;?></a><?php
  127. }
  128. ?><?php echo $_var_8["type"] ? "\r\n <a href=\"javascript:;\" class=\"act checkLogin" . $_var_8["id"] . "\" onclick=\"doAction('checkLogin',{id:" . $_var_8["id"] . "},this)\">登录校验" . $this->loadingImg . "</a>\r\n " : "";?>
  129. <a href="javascript:;" class="act update<?php echo $_var_8["id"];?>" onclick="doAction('update',{id:<?php echo $_var_8["id"];?>},this)">更新<?php echo $this->loadingImg;?></a>
  130. <a href="javascript:;" onclick="x_admin_show('编辑','?c=super_cert&a=edit&id=<?php echo $_var_8["id"];?>')" class="act">编辑</a>
  131. <a href="javascript:;" class="act del<?php echo $_var_8["id"];?>" onclick="doAction('del',{id:<?php echo $_var_8["id"];?>},this)">删除<?php echo $this->loadingImg;?></a>
  132. </td>
  133. </tr><?php
  134. }
  135. }
  136. ?></table><?php echo $_var_6;?> <table class="tb tb2">
  137. <tr>
  138. <td>
  139. <input type="checkbox" id="chkall" class="checkbox" onclick="CheckAll(this.form);"/>
  140. <label for="chkall">全选</label> &nbsp;&nbsp;
  141. <select id="in_allsave" name="in_allsave" onchange="all_save(this.form);">
  142. <option value="update">更新证书</option>
  143. <option value="status_on">启用证书</option>
  144. <option value="status_off">禁用证书</option>
  145. <option value="del">删除证书</option>
  146. </select> &nbsp;&nbsp;
  147. <input type="button" name="allsave" class="layui-btn" value="批量操作"
  148. onclick="doActionAll(this.form)"/>
  149. </td>
  150. </tr>
  151. </table>
  152. </form>
  153. </div>
  154. <script type="text/javascript" src="/xinadmin/js/xadmin.js"></script>
  155. <script>
  156. function doActionAll(form) {
  157. var checked = false;
  158. $('input[name="in_id[]"]:checked').each(function () {
  159. var val = $(this).val();
  160. var action = $('#in_allsave').val();
  161. $('a.' + action + val).trigger('click');
  162. checked = true;
  163. console.log(val, action, checked);
  164. });
  165. if (!checked) layer.msg('请选择要更新的证书');
  166. }
  167. function doAction(action, data, ts) {
  168. $(ts).find('img').show();
  169. if (action != 'del' || confirm('此操作不能恢复,确认删除吗?'))
  170. $.post('?c=super_cert&a=' + action, data, function (ret) {
  171. $(ts).find('img').hide();
  172. if (ret.msg) layer.msg(ret.msg, {time: 1500}, function () {
  173. if (ret.code == 200) {
  174. window.location.reload();
  175. }
  176. });
  177. }, 'json');
  178. }
  179. </script>
  180. <?php
  181. }
  182. function edit()
  183. {
  184. $_var_11 = SafeRequest("id", "get");
  185. $_var_12 = $_var_11 ? "编辑" : "新增";
  186. $_var_13 = db("super_cert")->where("id", $_var_11)->find();
  187. ?><div class="container"><?php
  188. $this->nav3();
  189. ?><table class="tb tb2">
  190. <form action="" method="post" name="form">
  191. <input type="hidden" name="id" value="<?php echo $_var_11;?>"/>
  192. <input type="hidden" name="hash" value="<?php echo $_COOKIE["in_adminpassword"];?>" />
  193. <tr><th colspan="15" class="partition"><?php echo $_var_12;?>目录</th></tr>
  194. <tr><td colspan="2" class="td27">iss:</td></tr>
  195. <tr><td class="vtop rowform">
  196. <input type="text" class="txt" name="iss" value="<?php echo $_var_13["iss"];?>" placeholder="必须">
  197. </td>
  198. </tr>
  199. <tr><td colspan="2" class="td27">kid:</td></tr>
  200. <tr><td class="vtop rowform">
  201. <input type="text" class="txt" name="kid" value="<?php echo $_var_13["kid"];?>" placeholder="p8模式必须">
  202. </td>
  203. </tr>
  204. <tr><td colspan="2" class="td27">p8文件上传:</td></tr>
  205. <tr><td class="vtop rowform">
  206. <input type="file" class="txt" name="p8">
  207. </td>
  208. </tr>
  209. <tr><td colspan="2" class="td27">模式:</td></tr>
  210. <tr><td class="vtop rowform">
  211. <select name="type"><?php
  212. foreach (["p8"] as $_var_14 => $_var_15) {
  213. ?><option value="<?php echo $_var_14;?>" <?php echo $_var_13["type"] == $_var_14 ? "selected" : "";?>><?php echo $_var_15;?></option><?php
  214. }
  215. ?></select>
  216. </td>
  217. </tr>
  218. <tr><td colspan="2" class="td27">备注:</td></tr>
  219. <tr><td class="vtop rowform">
  220. <textarea rows="6" name="mark" class="tarea"><?php echo $_var_13["mark"];?></textarea>
  221. </td>
  222. </tr>
  223. <tr><td colspan="15">
  224. <div class="fixsel">
  225. <button type="button" class="btn" id="submit" >提交<?php echo $this->loadingImg;?></button>
  226. </div>
  227. </td></tr>
  228. </form>
  229. </table>
  230. </div>
  231. <script>
  232. $("#submit").click(function () {
  233. $(this).find('img').show();
  234. var data = new FormData($('form')[0]);
  235. console.log(data);
  236. $.ajax({
  237. url: '?c=super_cert&a=save',
  238. data: data,
  239. type: 'POST',
  240. processData: false,
  241. contentType: false,
  242. dataType: "json",
  243. success: function (ret) {
  244. $(this).find('img').hide();
  245. if (ret.msg) alert(ret.msg);
  246. if (ret.code == 200) {
  247. window.location.href = '?c=super_cert&a=index';
  248. }
  249. }
  250. })
  251. });
  252. </script>
  253. <?php
  254. }
  255. function save()
  256. {
  257. $_var_16 = intval(SafeRequest("id"));
  258. $_var_17 = SafeRequest("iss");
  259. $_var_18 = SafeRequest("type");
  260. $_var_19 = SafeRequest("kid");
  261. $_var_20 = SafeRequest("mark");
  262. $_var_21 = SafeRequest("username");
  263. $_var_22 = SafeRequest("password");
  264. $_var_23 = SafeRequest("mobile");
  265. $_var_24 = SafeRequest("sp_password");
  266. if (!$_var_17) {
  267. reJSON("请输入iss");
  268. }
  269. if (!$_var_16 && ($_var_25 = db("super_cert")->where("iss", $_var_17)->count())) {
  270. reJSON("该证书已存在");
  271. }
  272. if ($_var_18) {
  273. if (!$_var_21) {
  274. reJSON("fastlane模式,开发者账号必须填");
  275. }
  276. if (!$_var_22) {
  277. reJSON("fastlane模式,开发者密码必须填");
  278. }
  279. if (!$_var_23) {
  280. reJSON("fastlane模式,双重验证手机必须填");
  281. }
  282. if (!$_var_24) {
  283. reJSON("fastlane模式,专用密码必须填");
  284. }
  285. } else {
  286. if (!$_var_19) {
  287. reJSON("p8模式,kid必须填");
  288. }
  289. $_var_26 = IN_CERT_PATH . getCert($_var_17, $_var_19);
  290. if (!empty($_FILES["p8"]) && $_FILES["p8"]["size"]) {
  291. $_var_27 = $_FILES["p8"];
  292. $_var_28 = $_var_27["name"];
  293. $_var_29 = pathinfo($_var_28);
  294. $_var_30 = strtolower($_var_29["extension"]);
  295. if ($_var_30 != "p8") {
  296. reJSON("p8文件错误,请上传正确的格式的p8文件");
  297. }
  298. $_var_31 = IN_CERT_PATH . bees_encrypt($_var_17) . "/";
  299. if (!is_dir($_var_31)) {
  300. @mkdir($_var_31, 0777, true);
  301. }
  302. @move_uploaded_file($_FILES["p8"]["tmp_name"], $_var_26);
  303. }
  304. if (!is_file($_var_26)) {
  305. reJSON("p8文件错误,请上传正确的格式的p8文件");
  306. }
  307. }
  308. $_var_32 = ["iss" => $_var_17, "kid" => $_var_19, "p8_file" => getCert($_var_17, $_var_19), "p12_file" => getCert($_var_17, $_var_19, "p12"), "mark" => $_var_20, "type" => $_var_18, "username" => $_var_21, "password" => $_var_22, "mobile" => $_var_23, "sp_password" => $_var_24];
  309. if ($_var_16) {
  310. $_var_33 = db("super_cert")->where("id", $_var_16)->update($_var_32);
  311. } else {
  312. $_var_32 = array_merge($_var_32, ["user_id" => 0, "team_id" => "", "tid" => "", "p12_pwd" => "123456", "limit_count" => 100, "total_count" => 0, "create_time" => time(), "status" => 1]);
  313. $_var_34 = db("super_cert")->insertGetId($_var_32);
  314. if ($_var_34) {
  315. $_var_32["id"] = $_var_34;
  316. $this->apicert($_var_32);
  317. }
  318. }
  319. reJSON("提交成功", 200);
  320. }
  321. function update()
  322. {
  323. $_var_35 = SafeRequest("id") ?: $_var_35;
  324. $_var_36 = db("super_cert")->where("id", $_var_35)->find();
  325. if (!$_var_36) {
  326. reJSON("证书不存在!");
  327. }
  328. $this->apicert($_var_36);
  329. reJSON("更新成功", 200);
  330. }
  331. function apicert($_var_37)
  332. {
  333. $_var_38 = $_var_37["id"];
  334. $_var_39 = $_var_37["status"];
  335. if ($_var_37["type"]) {
  336. if (empty($_var_37["username"]) || empty($_var_37["password"]) || empty($_var_37["mobile"])) {
  337. reJSON($_var_37["id"] . "号证书信息遗漏,请联系管理员完善");
  338. }
  339. $_var_40 = "export LANG=\"en_US.UTF-8\";export LC_ALL=\"en_US.UTF-8\";export PATH=\"/root/.pyenv/shims:/root/.pyenv/bin:/usr/local/php/bin:/usr/local/nginx/sbin:/usr/local/mysql/bin:/usr/local/rvm/gems/ruby-2.6.5/bin:/usr/local/rvm/gems/ruby-2.6.5@global/bin:/usr/local/rvm/rubies/ruby-2.6.5/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/rvm/bin:/root/bin\";export GEM_HOME=\"/usr/local/rvm/gems/ruby-2.6.5\";export GEM_PATH=\"/usr/local/rvm/gems/ruby-2.6.5:/usr/local/rvm/gems/ruby-2.6.5@global\";export FASTLANE_USER=\"" . $_var_37["username"] . "\";export FASTLANE_PASSWORD=\"" . $_var_37["password"] . "\";export FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD=\"" . $_var_37["sp_password"] . "\";export SPACESHIP_2FA_SMS_DEFAULT_PHONE_NUMBER=\"+86 " . $_var_37["mobile"] . "\";export FASTLANE_SESSION='" . $_var_37["fastlane_session"] . "';cd " . IN_ROOT . "static/sign_tools/fastlane/;ruby saveCert.rb " . $_var_37["iss"] . " 1";
  340. exec($_var_40, $_var_41, $_var_42);
  341. creatdir(IN_TMP_PATH . "saveCert/");
  342. file_put_contents(IN_TMP_PATH . "saveCert/" . $_var_37["username"] . time() . ".txt", $_var_40);
  343. if (!empty($_var_41[0])) {
  344. $_var_43 = json_decode($_var_41[0], true);
  345. if (empty($_var_43) || !isset($_var_43["status"])) {
  346. reJSON("处理失败,未能正常获取响应内容");
  347. }
  348. if ($_var_43["status"] == 0) {
  349. reJSON("任务失败,消息提示:" . $_var_43["msg"]);
  350. }
  351. reJSON("处理成功");
  352. }
  353. reJSON("处理失败,提示:" . print_R($_var_41, true));
  354. }
  355. @certMoveToNew($_var_37);
  356. $_var_44 = $_var_37["iss"];
  357. $_var_45 = $_var_37["kid"];
  358. $_var_46 = ["iss" => $_var_44, "kid" => $_var_45, "secret" => IN_CERT_PATH . getCert($_var_44, $_var_45)];
  359. $_var_47 = new Client($_var_46);
  360. $_var_47->setHeaders(["Authorization" => "Bearer " . $_var_47->getToken()]);
  361. $_var_48 = $_var_47->api("certificates")->all(["filter[certificateType]" => "IOS_DISTRIBUTION"]);
  362. if (isset($_var_48["errors"][0]["status"])) {
  363. if (($_var_39 == 401 || $_var_39 == -1) && $_var_48["errors"][0]["status"] == 401) {
  364. $_var_42 = -1;
  365. } else {
  366. $_var_42 = $_var_48["errors"][0]["status"];
  367. }
  368. $_var_49 = db("super_cert")->where("id", $_var_38)->update(["status" => $_var_42]);
  369. reJSON($_var_48["errors"][0]["title"], 200);
  370. }
  371. if (count($_var_48["data"]) < 2) {
  372. $_var_50 = $_var_47->api("certificates")->reg();
  373. if ($_var_50["data"]) {
  374. $_var_48["data"][] = $_var_50["data"];
  375. }
  376. }
  377. $_var_51 = 0;
  378. $_var_52 = "";
  379. foreach (array_reverse($_var_48["data"]) as $_var_53 => $_var_37) {
  380. $_var_54 = IN_CERT_PATH . getCert($_var_44, $_var_45, "cer");
  381. file_put_contents($_var_54, base64_decode($_var_37["attributes"]["certificateContent"]));
  382. $_var_55 = 123456;
  383. $_var_56 = IN_CERT_PATH . "public/ios.key";
  384. exec("openssl x509 -in " . $_var_54 . " -inform DER -outform PEM -out " . IN_CERT_PATH . getCert($_var_44, $_var_45, "pem") . " 2>&1", $_var_41, $_var_57);
  385. file_put_contents(IN_TMP_PATH . "supercert_add_openssl.log", $_var_41);
  386. exec("openssl pkcs12 -export -inkey " . $_var_56 . " -in " . IN_CERT_PATH . getCert($_var_44, $_var_45, "pem") . " -out " . IN_CERT_PATH . getCert($_var_44, $_var_45, "p12") . " -passout pass:" . $_var_55, $_var_41, $_var_57);
  387. file_put_contents(IN_TMP_PATH . "supercert_add_openssl2.log", $_var_41);
  388. if (file_get_contents(IN_CERT_PATH . getCert($_var_44, $_var_45, "p12"))) {
  389. $_var_51 = $_var_37["id"];
  390. $_var_52 = $_var_37["attributes"]["expirationDate"];
  391. break 1;
  392. } else {
  393. $_var_47->api("certificates")->del($_var_37["id"]);
  394. }
  395. }
  396. if (!$_var_51) {
  397. reJSON("没有可使用的证书文件");
  398. }
  399. $_var_58 = $_var_47->api("device")->all(["limit" => 200]);
  400. if (isset($_var_58["data"])) {
  401. foreach ($_var_58["data"] as $_var_53 => $_var_59) {
  402. if (!db("ios_device")->where("udid", $_var_59["attributes"]["udid"])->where("cert_iss", $_var_44)->count()) {
  403. db("ios_device")->insert(["app_id" => 0, "udid" => $_var_59["attributes"]["udid"], "cert_iss" => $_var_44]);
  404. }
  405. }
  406. if ($_var_39 != 0) {
  407. $_var_60["status"] = 1;
  408. }
  409. $_var_60["tid"] = $_var_51;
  410. $_var_60["total_count"] = $_var_58["meta"]["paging"]["total"];
  411. $_var_60["limit_count"] = 100 - $_var_60["total_count"];
  412. $_var_60["expirationDate"] = $_var_52 ? strtotime($_var_52) : time();
  413. $_var_49 = db("super_cert")->where("id", $_var_38)->update($_var_60);
  414. }
  415. }
  416. function del()
  417. {
  418. $_var_61 = intval(SafeRequest("id"));
  419. $_var_62 = db("super_cert")->where("id", $_var_61)->find();
  420. $_var_63 = db("super_cert")->where("id", $_var_61)->delete();
  421. if ($_var_63) {
  422. @certMoveToNew($_var_62);
  423. @destroyDir(IN_CERT_PATH . bees_encrypt($_var_62["iss"]));
  424. db("ios_device")->where("cert_iss", $_var_62["iss"])->delete();
  425. }
  426. reJSON("删除成功", 200);
  427. }
  428. function change_status()
  429. {
  430. $_var_64 = intval(SafeRequest("id"));
  431. $_var_65 = intval(SafeRequest("status"));
  432. db("super_cert")->where("id", $_var_64)->update(["status" => $_var_65]);
  433. if ($_var_65) {
  434. $this->update($_var_64);
  435. }
  436. reJSON("修改成功", 200);
  437. }
  438. function checkLogin()
  439. {
  440. $_var_66 = intval(SafeRequest("id"));
  441. $_var_67 = db("super_cert")->where("id", $_var_66)->find();
  442. if (!$_var_67) {
  443. reJSON("证书不存在!");
  444. }
  445. if (empty($_var_67["username"]) || empty($_var_67["password"]) || empty($_var_67["mobile"])) {
  446. reJSON($_var_67["id"] . "号证书信息遗漏,请联系管理员完善");
  447. }
  448. $_var_68 = "export LANG=\"en_US.UTF-8\";export LC_ALL=\"en_US.UTF-8\";export PATH=\"/root/.pyenv/shims:/root/.pyenv/bin:/usr/local/php/bin:/usr/local/nginx/sbin:/usr/local/mysql/bin:/usr/local/rvm/gems/ruby-2.6.5/bin:/usr/local/rvm/gems/ruby-2.6.5@global/bin:/usr/local/rvm/rubies/ruby-2.6.5/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/rvm/bin:/root/bin\";export GEM_HOME=\"/usr/local/rvm/gems/ruby-2.6.5\";export GEM_PATH=\"/usr/local/rvm/gems/ruby-2.6.5:/usr/local/rvm/gems/ruby-2.6.5@global\";export FASTLANE_USER=\"" . $_var_67["username"] . "\";export FASTLANE_PASSWORD=\"" . $_var_67["password"] . "\";export FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD=\"" . $_var_67["sp_password"] . "\";export SPACESHIP_2FA_SMS_DEFAULT_PHONE_NUMBER=\"+86 " . $_var_67["mobile"] . "\";export FASTLANE_SESSION='" . $_var_67["fastlane_session"] . "';cd " . IN_ROOT . "static/sign_tools/fastlane/;";
  449. exec($_var_68 . "ruby checkLogin.rb", $_var_69, $_var_70);
  450. creatdir(IN_TMP_PATH . "checkLogin/");
  451. file_put_contents(IN_TMP_PATH . "checkLogin/" . $_var_67["username"] . time() . ".log", $_var_68 . "fastlane spaceauth;ruby checkLogin.rb");
  452. if (!empty($_var_69[0])) {
  453. $_var_71 = json_decode($_var_69[0], true);
  454. if (empty($_var_71) || !isset($_var_71["status"])) {
  455. reJSON("登录失败,未能正常获取响应内容");
  456. }
  457. if ($_var_71["status"] == 0) {
  458. reJSON("登录失败,消息提示:" . $_var_71["msg"]);
  459. }
  460. $_var_71["session"] = base64_decode($_var_71["session"]);
  461. if (empty($_var_71["session"])) {
  462. reJSON("未能获取session");
  463. }
  464. if (strpos($_var_71["session"], "---\\n- !ruby/object:") === false) {
  465. reJSON("session格式校验失败");
  466. }
  467. db("super_cert")->where("id", $_var_66)->update(["fastlane_session" => $_var_71["session"]]);
  468. reJSON("登录正常,session更新成功");
  469. }
  470. reJSON("登录失败,提示:" . print_r($_var_69, true));
  471. }
  472. }