一步两步是魔鬼的步伐

Duan1v's Blog

执着于真相,享受追踪思维漏洞的过程|

部署django

1
2
3
4
5
6
7
8
9
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

bash Miniconda3-latest-Linux-x86_64.sh

source ~/miniconda3/bin/activate

conda create -n myenv python=3.9

conda activate myenv
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
cd /path/to/your/project

pip install -r requirements.txt

which python

sudo /home/ubuntu/miniconda3/envs/myenv/bin/python manage.py migrate

sudo /home/ubuntu/miniconda3/envs/myenv/bin/python load_data.py data.csv

sudo /home/ubuntu/miniconda3/envs/myenv/bin/python manage.py collectstatic # 收集静态文件

pip install gunicorn

sudo touch gunicorn.log 

sudo chmod 666 gunicorn.log 

开启服务器10000端口

# 创建admin账户
sudo /home/ubuntu/miniconda3/envs/myenv/bin/python manage.py createsuperuser

启动项目:nginx启动或者manage.py启动(本次使用manage.py启动)
1.nginx启动
nohup sudo /home/ubuntu/miniconda3/envs/myenv/bin/gunicorn CM3035_Midterm.wsgi:application --bind 0.0.0.0:10000 > gunicorn.log 2>&1 &

# 配置nginx示例
server {
    listen 80;
    server_name your_domain_or_IP;

    location /static/ {
        alias /path/to/your/project/staticfiles/;  # 确保这个路径是正确的
    }

    location / {
        proxy_pass http://127.0.0.1:10000;  # Django 应用的地址
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

2.manage.py启动
sudo touch run.log
sudo chmod 666 run.log
nohup sudo /home/ubuntu/miniconda3/envs/myenv/bin/python manage.py runserver 0.0.0.0:10000 > run.log 2>&1 &
1
2
ps aux|grep manage.py
sudo kill 15070
https://static.duan1v.top/images/20251017115055.png
1
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
1
sudo /home/ubuntu/miniconda3/envs/myenv/bin/python manage.py collectstatic
1
nohup sudo /home/ubuntu/miniconda3/envs/myenv/bin/uvicorn eLearning.asgi:application --host 0.0.0.0 --port 8001 --workers 4 > uvicorn.log 2>&1 &
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# /etc/caddy/conf.d/eLearning.conf
http://3.73.131.131:10000 {
    # 服务静态文件
    root * /www/wwwroot/eLearning/staticfiles
    file_server

    # 反向代理到 Django 应用
    reverse_proxy /ws/chat/* 0.0.0.0:8001
    reverse_proxy /* 0.0.0.0:8001

    # 可选:设置 Cross-Origin-Opener-Policy 头
    header {
        Cross-Origin-Opener-Policy unsafe-none
    }
}
1
sudo service caddy restart 

安装mmrotate

  • 下载页面 https://learn.microsoft.com/en-us/visualstudio/releases/2019/history#release-dates-and-build-numbers

  • 选择 BuildTools 链接并下载,安装之后,选择可安装页面中的 社区版安装,并在更改中选择桌面c++开发安装

  • 配置cl path的环境变量,例如 C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\Hostx86\x64

1
2
3
4
5
conda create -n mmrotate_env_11.8 python=3.10 -y
conda activate mmrotate_env_11.8 
conda install pytorch==2.0.0 torchvision==0.15.0 torchaudio==2.0.0 pytorch-cuda=11.8 -c pytorch -c nvidia
pip install H:\Workspace\python\mmcv_full-1.7.2-cp310-cp310-win_amd64.whl
pip install -U openmim
1
2
3
cd mmrotate
conda activate mmrotate_env_11.8 
pip install -v -e .
  • 可以到这个页面下载 https://github.com/open-mmlab/mmrotate/blob/main/configs/r3det/README.md
  • 也可以运行这个命令下载 mim download mmrotate --config r3det_r50_fpn_1x_dota_oc --dest .
  • 配置文件移到 mmrotate\configs\r3det\r3det_r50_fpn_1x_dota_oc.py
  • 模型文件移到 mmrotate\checkpoint\r3det_r50_fpn_1x_dota_oc-b1fb045c.pth
1
python demo/image_demo.py demo/demo.jpg configs/r3det/r3det_r50_fpn_1x_dota_oc.py checkpoint/r3det_r50_fpn_1x_dota_oc-b1fb045c.pth --out-file result.jpg --device=cpu

PHP 基础函数bug

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
$a = [
    "WX4027507200005",
    "EU20250728001",
    "LL1925670384FR",
    "LL1925670384FR",
    "LL1925670384FR",
    "LL1925670384FR",
    "LL1925670384FR",
    "WX2297507220003",
    "WX2297507220003",
    "WX2297507220003",
    "WX2297507220003",
    "WX2297507220003",
    "7506115142",
    "7506115142",
    "LL4137208569FR",
    "LL4137208569FR",
    "LL4137208569FR",
    "LL4137208569FR",
    "LL4137208569FR",
    "XDB5072549673XM",
    "XDB5072549673XM",
    "XDB5072549673XM",
    "XDB5072549673XM",
    "XDB5072549673XM",
    "XDB5072149071XM",
    "XDB5072149071XM",
    "XDB5072149071XM",
    "XDB5072149071XM",
    "XDB5072149071XM",
    "LGG20250725011",
    "XH-3057627154887125M",
    "YQGJ0726113701362",
    "EU20250728001",
    "EU20250728001",
    "LL0914278653FR",
    "LL0914278653FR",
    "SSZS0725133700888",
    "QX0964507210005",
    "QX0964507210005",
    "QX0964507210005",
    "QX0964507210005",
    "QX0964507210005",
    "SF6047002327729",
    "SF6047002327729",
    "SF6047002327729",
    "SF6047002327729",
    "SF6047002327729",
    "EU20250728003",
    "EU20250728001",
    "L15331546",
    "95333946",
    "LL6082139574FR",
    "SF6045816343138",
    "SF6045817977501",
    "5FDFVEAWC2",
    "SZMW0724163699247",
    "SHCW0725123700382N",
    "SF6045816343138",
    "SF6045816343138",
    "SF6045816343138",
    "SF6045816343138",
    "SF6045817977501",
    "SF6045817977501",
    "SF6045817977501",
    "SF6045817977501",
    "5FDFVEAWC2",
    "5FDFVEAWC2",
    "5FDFVEAWC2",
    "5FDFVEAWC2",
    "SZMW0724163699247",
    "SZMW0724163699247",
    "SHCW0725123700382N",
    "SHCW0725123700382N",
    "EU20250728003",
    "LGG20250725011",
    "HF072466A",
    "D11753121899677",
    "MS202500724BB",
    "HF072466A",
    "HF072466A",
    "HF072466A",
    "HF072466A",
    "D11753121899677",
    "D11753121899677",
    "MS202500724BB",
    "MS202500724BB",
    "MS202500724BB",
    "HS20250721",
    "HS20250721",
    "HS20250721",
    "HS20250721",
    "HS20250721",
    "SF6045816381174",
    "SF6045816381174",
    "SF6045816381174",
    "SF6045816381174",
    "SF6045816381174",
    "QX8772507220002",
    "20250725H",
    "QX8772507220002",
    "QX8772507220002",
    "QX8772507220002",
    "QX8772507220002",
    "20250725H",
    "20250725H",
    "20250725H",
    "20250725H",
    "EU20250728003",
    "EU20250728001",
    "EU20250728001",
    "SHXC0724173699581",
    "JH54SCVVS",
    "510129479",
    "80854608-0725041809",
    "LL5384071962FR",
    "EU20250728003",
    "EU20250728003",
    "EU20250728003",
    "EU20250728003",
    "SHXC0724173699581",
    "SHXC0724173699581",
    "SHXC0724173699581",
    "SHXC0724173699581",
    "JH54SCVVS",
    "JH54SCVVS",
    "JH54SCVVS",
    "JH54SCVVS",
    "510129479",
    "510129479",
    "510129479",
    "510129479",
    "80854608-0725041809",
    "80854608-0725041809",
    "80854608-0725041809",
    "80854608-0725041809",
    "LL5384071962FR",
    "LL5384071962FR",
    "LL5384071962FR",
    "LL5384071962FR",
    "L15331546",
    "5515085623",
    "1308795",
    "1308795",
    "1308795",
    "1308795",
    "1308795",
    "IB006250725RS",
    "SF6045819317946",
    "LL4802519763FR",
    "SHCW0725123700382N",
    "FHZJ072511852544",
    "L15331546",
    "D11753121899677",
    "XH-3057627154887125M",
    "FHZJ072511852544",
    "FHZJ072511852544",
    "FHZJ072511852544",
    "FHZJ072511852544",
    "L15331546",
    "L15331546",
    "D11753121899677",
    "D11753121899677",
    "XH-3057627154887125M",
    "XH-3057627154887125M",
    "7822025083",
    "7822025083",
    "7822025083",
    "7822025083",
    "7822025083",
    "LGG20250725011",
    "EU20250728001",
    "ZLXF0717123690322",
    "QDGJ0722143696161",
    "SHZR0724213699881",
    "SHCW0725123700382N",
    "NYZ7658615017JS",
    "7822025072",
    "XHD0619203658230",
    "SXX0725113700282",
    "GZST0725013699844",
    "LL9317856204FR",
    "LL0852693714FR",
    "LL5462309871FR",
    "LL7106293548FR",
    "EU20250728001",
    "EU20250728001",
    "ZLXF0717123690322",
    "ZLXF0717123690322",
    "ZLXF0717123690322",
    "ZLXF0717123690322",
    "QDGJ0722143696161",
    "QDGJ0722143696161",
    "QDGJ0722143696161",
    "QDGJ0722143696161",
    "SHZR0724213699881",
    "SHZR0724213699881",
    "SHZR0724213699881",
    "SHZR0724213699881",
    "SHCW0725123700382N",
    "SHCW0725123700382N",
    "SHCW0725123700382N",
    "SHCW0725123700382N",
    "NYZ7658615017JS",
    "NYZ7658615017JS",
    "NYZ7658615017JS",
    "NYZ7658615017JS",
    "7822025072",
    "7822025072",
    "7822025072",
    "7822025072",
    "XHD0619203658230",
    "XHD0619203658230",
    "XHD0619203658230",
    "XHD0619203658230",
    "SXX0725113700282",
    "SXX0725113700282",
    "SXX0725113700282",
    "SXX0725113700282",
    "GZST0725013699844",
    "GZST0725013699844",
    "GZST0725013699844",
    "GZST0725013699844",
    "LL9317856204FR",
    "LL9317856204FR",
    "LL9317856204FR",
    "LL9317856204FR",
    "LL0852693714FR",
    "LL0852693714FR",
    "LL0852693714FR",
    "LL0852693714FR",
    "LL5462309871FR",
    "LL5462309871FR",
    "LL5462309871FR",
    "LL5462309871FR",
    "LL7106293548FR",
    "LL7106293548FR",
    "LL7106293548FR",
    "LL7106293548FR",
    "GZGY0725153700566",
    "GZGY0725153700566",
    "GZGY0725153700566",
    "GZGY0725153700566",
    "GZGY0725153700566",
    "EU20250728001",
    "WW4443507070002",
    "MS202500724BB",
    "WW4443507070002",
    "WW4443507070002",
    "WW4443507070002",
    "WW4443507070002",
    "MS202500724BB",
    "MS202500724BB",
    "MS202500724BB",
    "MS202500724BB",
    "XH2572507",
    "XH2572507",
    "XH2572507",
    "XH2572507",
    "XH2572507",
    "SZMW0724163699247",
    "FC47456",
    "SZMW0724163699247",
    "SZMW0724163699247",
    "SZMW0724163699247",
    "SZMW0724163699247",
    "FC47456",
    "FC47456",
    "FC47456",
    "FC47456",
    "ZHGJ2025072614128",
    "WX5333507211421",
    "560018735",
    "WX5333507211421",
    "WX5333507211421",
    "WX5333507211421",
    "WX5333507211421",
    "560018735",
    "FLWF0725223701203",
    "LL1806925734FR",
    "5515085623",
    "XH-3057627154887125M",
    "SSZS0725133700888",
    "FLWF0725223701203",
    "FLWF0725223701203",
    "FLWF0725223701203",
    "FLWF0725223701203",
    "LL1806925734FR",
    "LL1806925734FR",
    "LL1806925734FR",
    "5515085623",
    "XH-3057627154887125M",
    "XH-3057627154887125M",
    "SSZS0725133700888",
    "EU20250728001",
    "KSXC0718173692041KY",
    "KSXC0718173692041KY",
    "KSXC0718173692041KY",
    "KSXC0718173692041KY",
    "KSXC0718173692041KY",
    "SHLD07241636992860",
    "SHLD07241636992860",
    "SHLD07241636992860",
    "SHLD07241636992860",
    "SHLD07241636992860",
    "WX2936507180006",
    "WX2936507180006",
    "WX2936507180006",
    "WX2936507180006",
    "WX2936507180006",
    "EU20250728001",
    "HF072466A",
    "EU20250728001",
    "HF072466A",
    "HF072466A",
    "312557156209-7",
    "560018734",
    "312557156209-7",
    "312557156209-7",
    "312557156209-7",
    "312557156209-7",
    "560018734",
    "560018734",
    "560018734",
    "560018734",
    "LGG20250725011",
    "LGG20250725011",
    "XL663292S",
    "XL663292S",
    "XL663292S",
    "XL663292S",
    "XL663292S",
    "XL663292S",
    "LGG20250725011",
    "LGG20250725011",
    "EU20250728001",
    "EU20250728001",
    "LGG20250725011",
    "LGG20250725011",
    "WL0725",
    "8384050283",
    "MS202500724BB",
    "WL0725",
    "WL0725",
    "WL0725",
    "WL0725",
    "8384050283",
    "8384050283",
    "MS202500724BB",
    "LL2917603485FR",
    "LL4623589017FR",
    "LL2917603485FR",
    "LL2917603485FR",
    "LL2917603485FR",
    "LL2917603485FR",
    "LL4623589017FR",
    "LL4623589017FR",
    "LL4623589017FR",
    "LL4623589017FR",
    "WX4018507230018",
    "WX4018507230018",
    "WX4018507230018",
    "WX4018507230018",
    "WX4018507230018",
    "LGG20250725011",
    "LGG20250725011",
    "510129524",
    "LGG20250725011",
    "LGG20250725011",
    "510129524",
    "510129524",
    "510129524",
    "510129524",
    "LL8209476351FR",
    "LL4261370895FR",
    "LL0427183659FR",
    "LL9704821635FR",
    "LL8209476351FR",
    "LL8209476351FR",
    "LL8209476351FR",
    "LL8209476351FR",
    "LL4261370895FR",
    "LL4261370895FR",
    "LL4261370895FR",
    "LL4261370895FR",
    "LL0427183659FR",
    "LL0427183659FR",
    "LL0427183659FR",
    "LL0427183659FR",
    "LL9704821635FR",
    "LL9704821635FR",
    "LL9704821635FR",
    "LL9704821635FR",
    "EU20250728003",
    "EU20250728003",
    "EU20250728001",
    "EU20250728001",
    "1024648183",
    "WV9874507230002",
    "WV9874507220021",
    "WV9874507220006",
    "H2507247536677",
    "8564FFSSV",
    "EU20250728003",
    "1024648183",
    "1024648183",
    "1024648183",
    "1024648183",
    "WV9874507230002",
    "WV9874507230002",
    "WV9874507230002",
    "WV9874507230002",
    "WV9874507220021",
    "WV9874507220021",
    "WV9874507220021",
    "WV9874507220021",
    "WV9874507220006",
    "WV9874507220006",
    "WV9874507220006",
    "WV9874507220006",
    "H2507247536677",
    "H2507247536677",
    "H2507247536677",
    "H2507247536677",
    "8564FFSSV",
    "8564FFSSV",
    "8564FFSSV",
    "8564FFSSV",
    "SZMW0724163699247",
    "SSZS0725133700888",
    "WX0843507140005",
    "WX0843507140005",
    "WX0843507140005",
    "WX0843507140005",
    "WX0843507140005",
    "250723002",
    "250723002",
    "Q1234ZG11",
    "QX8772507220001",
    "9813636965",
    "LL1475382906FR",
    "Q1234ZG11",
    "QX8772507220001",
    "9813636965",
    "LL1475382906FR",
    "73564749922517-1",
    "73564749922517-1",
    "73564749922517-1",
    "73564749922517-1",
    "73564749922517-1",
    "LL1376094852FR",
    "5515085623",
    "5515085623",
    "5515085623",
    "5515085623",
    "5515085623",
    "EU20250728003",
    "EU20250728001",
    "FHZJ072414852356-2",
    "250723002",
    "HF072466A",
    "XL663292S",
    "FHZJ072414852356-2",
    "FHZJ072414852356-2",
    "FHZJ072414852356-2",
    "FHZJ072414852356-2",
    "250723002",
    "250723002",
    "HF072466A",
    "HF072466A",
    "XL663292S",
    "XL663292S",
    "D11753121899677",
    "LGG20250725011",
    "LGG20250725011",
    "LGG20250725011",
    "WX5811507140035",
    "WX5811507180009",
    "WX5811507140035",
    "WX5811507140035",
    "WX5811507140035",
    "WX5811507140035",
    "WX5811507180009",
    "WX5811507180009",
    "WX5811507180009",
    "WX5811507180009",
    "EU20250728001",
    "EU20250728001",
    "EU20250728001",
    "20250726B1",
    "LL1405792683FR",
    "20250726B1",
    "20250726B1",
    "LL1405792683FR",
    "LL1405792683FR",
    "LL1405792683FR",
    "LL1405792683FR",
    "250723002",
    "GWX0725DE",
    "250723002",
    "GWX0725DE",
    "XDB5071949043XM",
    "XDB5071949043XM",
    "XDB5071949043XM",
    "XDB5071949043XM",
    "XDB5071949043XM",
  ]

collect($a)->unique()

Ubuntu 配置Nginx

1
sudo certbot certonly --nginx --nginx-server-root /www/server/nginx/conf -w /www/wwwroot/example.com -d example.com -d www.example.com
  • 其中 --nginx-server-root 需要指向实际的nginx的配置文件

  • 如果报证书文件夹已存在,可以再次执行一遍

1
sudo certbot renew --dry-run --nginx-server-root /www/server/nginx/conf
1
2
3
4
sudo crontab -e

# 添加下面任务
15 2 * */2 * certbot renew --dry-run --nginx-server-root /www/server/nginx/conf --pre-hook "service nginx stop" --post-hook "service nginx start"
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
sudo vim /lib/systemd/system/nginx.service

# 添加下面配置
[Unit]
Description=A high performance web server and a reverse proxy server
After=network.target

[Service]
Type=forking
PIDFile=/www/server/nginx/logs/nginx.pid
ExecStart=/www/server/nginx/sbin/nginx -c /www/server/nginx/conf/nginx.conf
ExecReload=/www/server/nginx/sbin/nginx -s reload
ExecStop=/www/server/nginx/sbin/nginx -s quit
TimeoutStopSec=5
KillMode=mixed

[Install]
WantedBy=multi-user.target
1
sudo systemctl enable nginx.service
1
sudo systemctl status nginx.service
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
server
{
    listen 80;
    listen 443 ssl;
    server_name example.com www.example.com;
    index index.php index.html index.htm default.php default.htm default.html;
    root /www/wwwroot/example.com/public;

    #error_page 404/404.html;
    if ($server_port !~ 443){
        rewrite ^(/.*)$ https://$host$1 permanent;
    }

    # 改成上面生成的证书路径
    ssl_certificate    /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key    /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;
    error_page 497  https://$host$request_uri;

    error_page 404 /404.html;
    error_page 502 /502.html;

    location ~ [^/]\.php(/|$)
    {
        try_files $uri =404;
        fastcgi_pass  127.0.0.1:9003;
        # fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        # fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
        fastcgi_index index.php;
        # include fastcgi.conf;
        include fastcgi_params;
        set $real_script_name $fastcgi_script_name;
        if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
            set $real_script_name $1;
            set $path_info $2;
         }
        fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
        fastcgi_param SCRIPT_NAME $real_script_name;
        fastcgi_param PATH_INFO $path_info;
        fastcgi_buffering off;
    }

    location / {
        try_files $uri $uri/ /index.php$is_args$query_string;
    }

    location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
    {
        return 404;
    }

    location ~ \.well-known{
        allow all;
    }

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires      30d;
        error_log off;
        access_log off;
    }

    location ~ .*\.(js|css)?$
    {
        expires      12h;
        error_log off;
        access_log off;
    }
    access_log  /www/wwwlogs/example.com.log;
    error_log  /www/wwwlogs/example.com.error.log;
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
server {
    listen 80;
    server_name my_vue3_backend.com www.my_vue3_backend.com;
    index index.php index.html index.htm default.php default.htm default.html;
    root /mnt/h/workspace/php/vue3-backend/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/run/php/php8.1-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_buffering off;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
    access_log  /mnt/h/wsl/nginx/logs/my_vue3_backend.com.log;
    error_log  /mnt/h/wsl/nginx/logs/my_vue3_backend.com.error.log;
}
  • 通过 php-fpm.conf查找pid文件,比如 /var/php/74/var/run/php-fpm.pid
1
kill -SIGUSR2 `cat /var/php/74/var/run/php-fpm.pid`

XML相关

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
<link href="/path/codemirror/css/codemirror.css" rel="stylesheet">
<link href="/path/codemirror/css/foldgutter.css" rel="stylesheet">
<link href="/path/codemirror/css/isotope.css" rel="stylesheet">
<style>
    h4 {
        color: #abb2bf;
    }

    .CodeMirror {
        height: auto;
        font-family: "SFMono-Regular", Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    }

    .CodeMirror-vscrollbar {
        overflow-y: auto !important;
    }

    .cm-tag {
        cursor: pointer;
    }

    .CodeMirror-cursors {
        display: none;
    }

    .CodeMirror-scroll {
        background-color: #282c34 !important;
    }

    .CodeMirror-scroll::before {
        content: "";
        display: block;
        width: 100%;
        height: 30px;
        background-color: #384548;
        border-top-left-radius: 5px;
        border-top-right-radius: 5px;
    }

    .CodeMirror-scroll::after {
        content: "";
        position: absolute;
        top: 0;
        left: 35px;
        width: 60px;
        height: 30px;
        background: url({{asset('falcon/assets/img/sd.png')}});
        background-size: 40px;
        background-repeat: no-repeat;
        background-position: 15px 10px;
        transform: rotate(-3deg);
    }

    .cm-s-isotope span.cm-tag {
        color: #e06c75 !important;
    }

    .cm-s-isotope span.cm-bracket {
        color: #ffffff !important;
    }

    .cm-s-isotope span.cm-attribute {
        color: #d19a66 !important;
    }

    .cm-s-isotope span.cm-string {
        color: #98c379 !important;
    }

    .cm-s-isotope span.cm-meta {
        color: #61aeee !important;
    }
</style>
<div>
    <textarea id="code-xml" name="code" class="d-none">xml文本</textarea>
</div>

<script src="/path/codemirror/js/codemirror.js"></script>
<script src="/path/codemirror/js/foldcode.js"></script>
<script src="/path/codemirror/js/foldgutter.js"></script>
<script src="/path/codemirror/js/xml-fold.js"></script>
<script src="/path/codemirror/js/xml.js"></script>
<script type="module">
function initCode() {
    return CodeMirror.fromTextArea(document.getElementById("code-xml"), {
        mode: "text/xml",
        lineNumbers: true,
        readOnly: true,
        cursorBlinkRate: 0,
        theme: "isotope",
        // extraKeys: {
        //     "Ctrl-Q": function (cm) {
        //         cm.foldCode(cm.getCursor());
        //     }
        // },
        foldGutter: true,
        gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"]
    });
}
var editor = initCode();
</script>
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
function formatXML($xmlString): bool|string
{
    $dom = new DOMDocument();
    $dom->preserveWhiteSpace = false;
    $dom->formatOutput = true;

    $dom->loadXML($xmlString);

    return $dom->saveXML();
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
function getAllXpath($xmlString, $noSplit = false, $line = 0)
{
    $doc = new DOMDocument();
    $doc->loadXML($xmlString);

    function traverseElement($node, $path, &$result, $noSplit)
    {
        if ($node->nodeType === XML_ELEMENT_NODE) {
            $path[] = $node->nodeName;
            if ($noSplit) {
                $result[] = $path;
            } else {
                $result[] = implode("/", $path);
            }
        }

        foreach ($node->childNodes as $childNode) {
            if ($childNode->nodeType === XML_ELEMENT_NODE) {
                traverseElement($childNode, $path, $result, $noSplit);
            }
        }
        if ($node->childNodes->length > 1) {
            if ($noSplit) {
                $result[] = $path;
            } else {
                $result[] = implode("/", $path);
            }
        }
    }

    $result = [];
    traverseElement($doc->documentElement, [], $result, $noSplit);

    $jsonResult = [];
    foreach ($result as $index => $xpath) {
        $lineNumber = $index + 1;
        $jsonResult[$lineNumber] = $xpath;
    }

    return $line ? data_get($jsonResult, $line) : $jsonResult;
}

PDF相关

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<div id="pdf-content"></div>

<script src="/path/pdf.min.js"></script>
<script src="/path/pdf.worker.min.js"></script>
<script type="module">
function loadPdf(url, workerSrc, cid, scale = 0) {
    var pdfJsLib = window['pdfjs-dist/build/pdf'];

    pdfJsLib.GlobalWorkerOptions.workerSrc = workerSrc;

    // Asynchronous download of PDF
    var loadingTask = pdfJsLib.getDocument(url);
    loadingTask.promise.then(function (pdf) {
        var pagesCount = pdf.numPages;
        var container = document.getElementById(cid);
        container.innerHTML = '';
        for (var i = 1; i <= pagesCount; i++) {
            pdf.getPage(i).then(function (page) {
                var desiredWidth = container.offsetWidth;
                // console.log(desiredWidth)
                var viewport = page.getViewport({scale: 1,});
                if (scale === 0) {
                    scale = desiredWidth / viewport.width;
                }
                viewport = page.getViewport({scale: scale,});

                var canvas = document.createElement('canvas');
                var context = canvas.getContext('2d');
                canvas.height = viewport.height;
                canvas.width = viewport.width;

                var renderContext = {
                    canvasContext: context,
                    viewport: viewport
                };

                page.render(renderContext);
                var pageContainer = document.createElement('div');
                pageContainer.className = 'pdfPage';
                pageContainer.appendChild(canvas);
                container.appendChild(pageContainer);
            });
        }
    }, function (reason) {
        console.error(reason);
    });
}
loadPdf("/pdf/download/url", "/path/pdf.worker.min.js", "pdf-content");
</script>
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
from PyPDF2 import PdfMerger
import sys

def merge_pdfs(pdf_files,out_path):
    merger = PdfMerger()

    for file in pdf_files:
        merger.append(file)

    merger.write(out_path)
    merger.close()


# "python3 main.py test.pdf,test1.pdf output.pdf"
pdf_files = sys.argv[1] if len(sys.argv) > 1 else ''
out_path = sys.argv[2] if len(sys.argv) > 2 else ''
merge_pdfs(pdf_files.split(","),out_path)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import fitz
import sys

def read_clip(page,x0,y0,x1,y1):
    return page.get_text(clip=fitz.Rect(x0,y0,x1,y1))

def highlight(pdf_path,output_path,texts):
    # READ IN PDF
    doc = fitz.open(pdf_path)
    mupdf_page = doc.load_page(0)
    page_width = mupdf_page.rect.width
    hightOffset=15
    for page in doc:
        sites=[]
        for text in texts:
            sites.extend(page.search_for(text))
        for inst in sites:
            x0,y0,x1,y1=inst
            ys=y0
            next_text=str(read_clip(page,x0,y0+hightOffset,x1,y1+hightOffset)).strip()
            while next_text=="":
                next_row=str(read_clip(page,0,y0+hightOffset,page_width,y1+hightOffset)).strip()
                if next_row=="":
                    break
                y0=y0+hightOffset
                y1=y1+hightOffset
                next_text=str(read_clip(page,x0,y0+hightOffset,x1,y1+hightOffset)).strip()
            highlight=page.add_highlight_annot((-5,ys-2,page_width+5, y1))
            highlight.set_colors(stroke=[1, 0.94 ,0.4])
            highlight.update()

    # OUTPUT
    doc.save(output_path, garbage=4, deflate=True, clean=True)

# "python3 main.py in.pdf output.pdf needles_text"
in_pdf = sys.argv[1] if len(sys.argv) > 1 else ''
out_path = sys.argv[2] if len(sys.argv) > 2 else ''
needles_text = sys.argv[3] if len(sys.argv) > 3 else ''
highlight(in_pdf,out_path,needles_text.split(","))