{"id":19558,"date":"2017-05-13T06:23:59","date_gmt":"2017-05-12T22:23:59","guid":{"rendered":"https:\/\/2blog.ilc.edu.tw\/25793\/2017\/05\/13\/%e5%b0%87-ldapsearch-%e8%bc%b8%e5%87%ba%e5%85%a7%e5%ae%b9-ldif-%e8%bd%89-utf-8-%e7%b7%a8%e7%a2%bc-1\/"},"modified":"2021-03-18T17:25:02","modified_gmt":"2021-03-18T09:25:02","slug":"%e5%b0%87-ldapsearch-%e8%bc%b8%e5%87%ba%e5%85%a7%e5%ae%b9-ldif-%e8%bd%89-utf-8-%e7%b7%a8%e7%a2%bc-1","status":"publish","type":"post","link":"https:\/\/2blog.ilc.edu.tw\/25793\/2017\/05\/13\/%e5%b0%87-ldapsearch-%e8%bc%b8%e5%87%ba%e5%85%a7%e5%ae%b9-ldif-%e8%bd%89-utf-8-%e7%b7%a8%e7%a2%bc-1\/","title":{"rendered":"\u5c07 ldapsearch \u8f38\u51fa\u5167\u5bb9 (LDIF) \u8f49 UTF-8 \u7de8\u78bc &#8211; 1"},"content":{"rendered":"<p>\u5e95\u4e0b\u7684\u5167\u5bb9\u53c3\u8003 <a href=\"https:\/\/jamyy.dyndns.org\/blog\/2008\/11\/414.html\/comment-page-1\" target=\"_blank\" rel=\"noopener noreferrer\">PHP \u7a0b\u5f0f: ldapsearch \u8f38\u51fa\u5167\u5bb9 (LDIF) \u8f49 UTF-8 \u7de8\u78bc \u00ab Jamyy&#8217;s Weblog<\/a> <br \/>#\u00a0\u5efa\u7acb php\u00a0\u7684\u8f49\u63db\u6a94 <br \/># <span style=\"color: #ff0000\"> vim \/usr\/local\/bin\/utf8ldif.php <\/span><\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\"><span style=\"color: #0000ff\">&lt;?php\n\nfunction fn_output($str) {\n\tif (strpos($str,\":: \") &gt; 0) {\n\t\t\/\/\u89e3 Base64 \u7de8\u78bc\n\t\t\/\/\u7576 ldap \u6b04\u4f4d\u540d\u7a31\u5f8c\u9762\u63a5\u7684\u662f\u5169\u500b\u5192\u865f\u5373\u8868\u793a\u8a72\u6b04\u4f4d\u5167\u5bb9\u70ba Base64 \u7de8\u78bc\n\t\t$head = substr($str,0,strpos($str,\" \")-1);\n\t\t$body = substr($str,strpos($str,\" \")+1);\n\t\t$str = $head . \" \" . base64_decode($body) . \"n\";\n\t} else if (preg_match('\/x5c[A-F0-9][A-F0-9]x5c[A-F0-9][A-F0-9]\/',$str)) {\n\t\t\/\/\u89e3 URL \u7de8\u78bc\n\t\t\/\/URL \u7de8\u78bc\u51fa\u73fe\u5728\u8a3b\u89e3 (#), ldapsearch -LLL \u53ef\u53d6\u6d88\u8f38\u51fa\u8a3b\u89e3\u5167\u5bb9\n\t\t$str = urldecode(str_replace(\"\",\"%\",$str));\n\t}\n\tif (!preg_match('\/n$\/',$str)) {\n\t\t\/\/\u5982\u679c\u8655\u7406\u904e\u5f8c\u7684\u5b57\u4e32\u6c92\u6709\u63db\u884c\u7b26\u865f (n) \u5c31\u585e\u4e00\u500b\u7d66\u4ed6\n\t\t$str .= \"n\";\n\t}\n\treturn($str);\n}\n\n$line_old = \"\";\n$line_merge = \"\";\n$params = count($argv);\nif ($params == 1) {\n\t\/\/\u672a\u7d66\u53c3\u6578\u6642, \u958b\u555f STDIN \u4e32\u6d41\n\t$f = fopen(\"php:\/\/stdin\",\"r\");\n} else {\n\t\/\/\u958b\u555f\u6307\u5b9a\u6a94\u6848\n\t$f = fopen(\"$argv[1]\",\"r\");\n}\nwhile (!feof($f)) {\n\t$line = fgets($f);\n\tif (substr($line,0,1) == \" \") {\n\t\t\/\/\u82e5\u8a72\u884c\u884c\u9996\u70ba\u7a7a\u767d\u5b57\u5143, \u8868\u793a\u56e0\u5167\u5bb9\u904e\u9577\u800c\u65b7\u884c\n\t\t\/\/\u4ee5 line_merge \u8b8a\u6578\u5408\u4f75\u5404\u6bb5\u843d\n\t\tif ($line_merge == \"\") {\n\t\t\t$line_merge = trim($line_old) . trim($line);\n\t\t} else {\n\t\t\t$line_merge .= trim($line);\n\t\t}\n\t} else if ($line_merge &gt; \"\") {\n\t\t\/\/\u8f38\u51fa\u5408\u4f75\u597d\u7684\u5167\u5bb9\n\t\techo fn_output($line_merge);\n\t\t$line_merge = \"\";\n\t} else {\n\t\t\/\/\u8f38\u51fa\u4e00\u822c\u5167\u5bb9\n\t\techo fn_output($line_old);\n\t}\n\t$line_old = $line;\n}\nfclose($f);\n?&gt;\n<\/span><\/pre>\n<p>[@more@]<\/p>\n<p>1. \u5b89\u88dd php \u5957\u4ef6<br \/># <span style=\"color: #ff0000\">yum install php-cli<\/span><\/p>\n<p>2. \u9032\u884c\u6e2c\u8a66<br \/># <span style=\"color: #ff0000\">\/usr\/bin\/ldapsearch -x -b &#8220;ou=s0101,ou=student,ou=tces,dc=ilc,dc=edu,dc=tw&#8221; uid=s0101129\u00a0 | php \/usr\/l<\/span><span style=\"color: #ff0000\">ocal\/bin\/utf8ldif.php<\/span><\/p>\n<p><span style=\"color: #0000ff\"># extended LDIF<\/span><br \/><span style=\"color: #0000ff\">#<\/span><br \/><span style=\"color: #0000ff\"># LDAPv3<\/span><br \/><span style=\"color: #0000ff\"># base &lt;ou=s0101,ou=student,ou=tces,dc=ilc,dc=edu,dc=tw&gt; with scope subtree<\/span><br \/><span style=\"color: #0000ff\"># filter: uid=s0101129<\/span><br \/><span style=\"color: #0000ff\"># requesting: ALL<\/span><br \/><span style=\"color: #0000ff\">#<\/span><\/p>\n<p><span style=\"color: #0000ff\"># s0101129, s0101, student, tces, ilc.edu.tw<\/span><br \/><span style=\"color: #0000ff\">dn: uid=s0101129,ou=s0101,ou=student,ou=tces,dc=ilc,dc=edu,dc=tw<\/span><br \/><span style=\"color: #0000ff\">uid: s0101129<\/span><br \/><span style=\"color: #0000ff\">cn: \u4e94\u4ec125\u7537\u9673\u203b\u99ff<\/span><br \/><span style=\"color: #0000ff\">sn: \u4e94\u4ec125\u7537\u9673\u203b\u99ff<\/span><br \/><span style=\"color: #0000ff\">mail: s0101129@smail.ilc.edu.tw<\/span><br \/><span style=\"color: #0000ff\">objectClass: person<\/span><br \/><span style=\"color: #0000ff\">objectClass: organizationalPerson<\/span><br \/><span style=\"color: #0000ff\">objectClass: inetOrgPerson<\/span><br \/><span style=\"color: #0000ff\">objectClass: posixAccount<\/span><br \/><span style=\"color: #0000ff\">objectClass: top<\/span><br \/><span style=\"color: #0000ff\">objectClass: shadowAccount<\/span><br \/><span style=\"color: #0000ff\">shadowMin: 0<\/span><br \/><span style=\"color: #0000ff\">shadowMax: 99999<\/span><br \/><span style=\"color: #0000ff\">shadowWarning: 7<\/span><br \/><span style=\"color: #0000ff\">shadowExpire: 17774<\/span><br \/><span style=\"color: #0000ff\">loginShell: \/sbin\/nologin<\/span><br \/><span style=\"color: #0000ff\">uidNumber: 1784<\/span><br \/><span style=\"color: #0000ff\">gidNumber: 1075<\/span><br \/><span style=\"color: #0000ff\">homeDirectory: \/home\/s0101\/s0101129<\/span><\/p>\n<p><span style=\"color: #0000ff\"># search result<\/span><br \/><span style=\"color: #0000ff\">search: 2<\/span><br \/><span style=\"color: #0000ff\">result: 0 Success<\/span><\/p>\n<p><span style=\"color: #0000ff\"># numResponses: 2<\/span><br \/><span style=\"color: #0000ff\"># numEntries: 1<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5e95\u4e0b\u7684\u5167\u5bb9\u53c3\u8003 PHP \u7a0b\u5f0f: ldapsearch \u8f38\u51fa\u5167\u5bb9 (LDIF) \u8f49 UTF-8 \u7de8\u78bc \u00ab Jam &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/2blog.ilc.edu.tw\/25793\/2017\/05\/13\/%e5%b0%87-ldapsearch-%e8%bc%b8%e5%87%ba%e5%85%a7%e5%ae%b9-ldif-%e8%bd%89-utf-8-%e7%b7%a8%e7%a2%bc-1\/\" class=\"more-link\">\u95b1\u8b80\u5168\u6587<span class=\"screen-reader-text\">\u3008\u5c07 ldapsearch \u8f38\u51fa\u5167\u5bb9 (LDIF) \u8f49 UTF-8 \u7de8\u78bc &#8211; 1\u3009<\/span><\/a><\/p>\n","protected":false},"author":55,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[117,115],"tags":[],"class_list":["post-19558","post","type-post","status-publish","format-standard","hentry","category-c-78462","category-c-78460"],"meta_key":{"_pingme":["1"],"_encloseme":["1"],"lt_post_id":["688056"]},"_links":{"self":[{"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/posts\/19558"}],"collection":[{"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/users\/55"}],"replies":[{"embeddable":true,"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/comments?post=19558"}],"version-history":[{"count":1,"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/posts\/19558\/revisions"}],"predecessor-version":[{"id":21070,"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/posts\/19558\/revisions\/21070"}],"wp:attachment":[{"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/media?parent=19558"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/categories?post=19558"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/tags?post=19558"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}