通过curl从oracle网站下载weblogic安装包

时间:2017-06-24 07:11:54

标签: curl download

我想从oracle网站下载安装包(作为我的CI版本的一部分)。所以要求是使用linux命令行工具集在没有任何用户交互的情况下完成它。

我已尝试过以下脚本:

#!/bin/sh

ORCL_USER='top'
ORCL_PWD='secret'
rm -rf cookies.txt

curl -H "Cookie: oraclelicense=accept-weblogicserver-cookie" -b cookies.txt -c cookies.txt -L -v http://download.oracle.com/otn/nt/middleware/12c/12212/fmw_12.2.1.2.0_wls_Disk1_1of1.zip
curl -H "Cookie: oraclelicense=accept-weblogicserver-cookie" --data "sso_username=${ORCL_USER}&ssopassword=${ORCL_PWD}&v=v1.4&locale=&" -b cookies.txt -c cookies.txt -L -v https://login.oracle.com/mysso/signon.jsp

(其中ORCL_USER和ORCL_PWD替换为有效值)

然而,在2.nd curl命令后,我最终得到了这样的回复:

...
<div class="cb41 cb41v0">
<input type="hidden" name="request_id" value="">
<div class="cb41w1">
<span id="errormsg" class="error-show">
Error! Do not use bookmarked URL. Please type the URL you are trying to reach directly into your browser.
</span>

...

关于如何继续/我在这里缺少什么的想法?

2 个答案:

答案 0 :(得分:1)

用于登录的URI为https://login.oracle.com/oam/server/sso/auth_cred_submit,除了OAM_REQssousername

之外,当您执行身份验证时,它似乎还需要一个额外的参数password

当您请求此页面时:     http://download.oracle.com/otn/nt/middleware/12c/12212/fmw_12.2.1.2.0_wls_Disk1_1of1.zip

您通过2 302移动的页面+最后一个将您重定向到登录页面的页面。但重定向是通过Javascript完成的,例如:

<html>

<head>
    <base target="_self">
</head>

<body onLoad="document.myForm.submit()">
    <noscript>
        <p>JavaScript is required. Enable JavaScript to use OAM Server.</p>
    </noscript>
    <form action="https://login.oracle.com/mysso/signon.jsp" method="post" name="myForm">
        <!------------ DO NOT REMOVE ------------->
        <!----- loginform renderBrowserView ------>
        <!-- Required for SmartView Integration -->
        <input type="hidden" name="contextType" value="external">
        <input type="hidden" name="username" value="string">
        <input type="hidden" name="contextValue" value="%2Foam">
        <input type="hidden" name="challenge_url" value="https%3A%2F%2Flogin.oracle.com%2Fmysso%2Fsignon.jsp">
        <input type="hidden" name="password" value="sercure_string">
        <input type="hidden" name="request_id" value="7632874198179980871">
        <input type="hidden" name="authn_try_count" value="0">
        <input type="hidden" name="site2pstoretoken" value="v1.2~CA55CD32~98699EBEC5E806BC86433113210667840689CE66A7AAAA88D959A0A0C8EB0824B9BEA969EABEFA236F656064444710B1471D34CDAA73EE704CF7219701567C4C0BDE7F5D03B1344B57A64F1D2E00A3B6A313F86FC7154A8BE9B1D0F5130FFF1C086984BBF9C9F67C41DEC899740D0FB6B76882F8661966DE810F9F8936C08090E37DCEB6AFE2AA35124AFB2BD70221775F078CA4D7841F50C2A7D4567505EDACD451740B4DDEF96FB25E3807C6241E305584C8D94681191E225913A213A0C14E90BE2C840C762E31C9895AE7DD7FFCB5C7854A08DBA311D6FE0872CF2969584C9FB0764BE06A1FD8E5147EEA5CF4E349F44A586FAF4F455F2FF29E651064862E6D4A3E320EF19FC4BDEF53F1398CCC4B">
        <input type="hidden" name="v" value="v1.4">
        <input type="hidden" name="p_submit_url" value="https://login.oracle.com:443/sso/auth">
        <input type="hidden" name="p_cancel_url" value="https://edelivery.oracle.com">
        <input type="hidden" name="p_error_code" value="">
        <input type="hidden" name="ssousername" value="">
        <input type="hidden" name="subscribername" value="">
        <input type="hidden" name="OAM_REQ" value="VERSION_4~7fNDjTUHJ%2bWv7qhZS3Txgx0QbxQGs3AJ4pzB6vtcD0tVSis7wBsyHhsbVWQ0C6Bpms498sJoLqqL9wsGpepsxy2wEt%2f2bLsbWZNzKtq2HbPKjkw0cImi2nmhhS%2bUq4mRZKlX2qNcCPaXjqBFN4NCs388sUIaues2CWPuDv8P%2fpnQHvLoMsu10H%2fO8WDb4o3AI4afso7D3UQdtgj5P%2fd8AKt0Gsfn9opFX88tW8B%2bQhk%2fGvYjKcVPDiVoTpkviOf1m4VCpEVTmvXHMbiDWt9NTpTSWQBIplLB%2fqgvgowdGp%2f51GKATL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4Tn7WJoJGxpcRCv%2fQPneJR%2fdMx38JrFFRmwBbhdQmYGUj7Og2zafOW7MDFGsaHk%2buBsrV1A8FTTOmTFxhpygM0krHSnKp0Bb6G%2b0UOHzQ8Jyz0HzVuEsgZoM%2fPMWAg9owaLfyLXFoXvmgy6abmB9%2bWB3PG7If%2bYXnLdEO36F3SGsevEOn5jHERsm5YVBy1UZdJRUNSIQssmq0eogh7uJjGOWyrBTLHeRjW49UCHTa2rIXrbL8S5XkLDnLNtIVc6fNPis41MvpY0zAbxWmy0ngZkBem61jBTrtOIE%2bG0qzdGItSJ0uq9NAZkX6XSKK%2fRjr1xle9duYYc10XL52pABawwXSgSFp3vU43p7xyNPpFwB28D7rKPvOBd2QJJ3a2Ct3bjYpzw7vA%2bUjoKhjPmWcJaGR2KLEVtjKhK0EMWJSwVaG4furgKgOEEKDs9eXutEMqYVthI3qmnbfba3rIcc7%2bLfvMhxSGrkhTGMCeUN3vhplFPa1BcGLwQC2J8SHgJiopKVmPdjXe6lpSodvxBL8PWH3rm0n%2fzsQi6mWidK10AVghPGdjEsOY%2bddZpHrhQZuYLyNaa%2ba8oGlWBJHNUVj14hwwB4x7DEOXCpDiepV%2bs4fswcSYr6gWPo%2b9%2bteCq6PkyHA%2f3dTUnuNRfKw31Zy7mik5Pr3Ta6mYmIS1NiAlk3A4ua%2bFe%2bdwbgB7ZmdDrdzs%2fWp38%2b3x5iIME5j0ks0dJFuFg1BquyhvHIDhdfGDINmJYW3%2fVjkpL10otYcFU66e21mWbPtEcsEPfSvAUlFI

所以基本上你只需要请求文件页面,存储cookie并解析这个OAM_REQ参数。然后,POST凭据的正确URI为https://login.oracle.com/oam/server/sso/auth_cred_submit

注意:

  • 除了s_cc=true;之外,您还需要Cookie oraclelicense=accept-weblogicserver-cookie;来验证许可
  • Oracle似乎已阻止curl用户代理,使用另一个

以下脚本使用curl执行http请求,pup使用html解析OAM_REQ变量:

username="your_username"
password="your_password"

rm -f cookies.txt

# store the OAM_REQ parameter
oam_req=$(curl -s -L -c cookies.txt "http://download.oracle.com/otn/nt/middleware/12c/12212/fmw_12.2.1.2.0_wls_Disk1_1of1.zip" \
     -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36' | \
     pup 'form [name="OAM_REQ"] attr{value}')

# download the file with the additionnal OAM_REQ parameter
curl -o "weblogic.zip" -L -b cookies.txt 'https://login.oracle.com/oam/server/sso/auth_cred_submit' \
    -H 'Cookie: s_cc=true; oraclelicense=accept-weblogicserver-cookie;' \
    -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36' \
    --data-urlencode "ssousername=$username" --data-urlencode "password=$password" -d "OAM_REQ=$oam_req" --compressed

答案 1 :(得分:0)

基于@Bertrand回答我介绍了github项目:https://github.com/typekpb/oradown

Usage: oradown.sh [OPTION]... URL
oradown enables download of the SSO protected files (specified by URL) from the Oracle website.

Functional arguments:
  -C, --cookie=LICENSE_COOKIE  name of the license cookie (mandatory)
  -O, --output=FILE            output FILE (optional)
  -P, --password=PASSWORD      set the Oracle PASSWORD (mandatory)
  -U, --username=USERNAME      set the Oracle USERNAME (mandatory)

Logging and info arguments:
  -H, --help                   print this help and exit
  -V, --version                display the version of oradown and exit.

Examples:

  Downloads weblogic 12c (oradown downloaded via wget):
    wget -O - -q https://raw.githubusercontent.com/typekpb/oradown/master/oradown.sh  | \
    bash -s -- --cookie=accept-weblogicserver-server \
        --username=foo --password=bar \
        http://download.oracle.com/otn/nt/middleware/12c/12212/fmw_12.2.1.2.0_wls_Disk1_1of1.zip

    Downloads weblogic 12c (oradown downloaded via curl):
    curl -s https://raw.githubusercontent.com/typekpb/oradown/master/oradown.sh  | \
    bash -s -- --cookie=accept-weblogicserver-server \
        --username=foo --password=bar \
        http://download.oracle.com/otn/nt/middleware/12c/12212/fmw_12.2.1.2.0_wls_Disk1_1of1.zip