agent_conf.sh 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. #!/bin/bash
  2. #
  3. # OGP - Open Game Panel
  4. # Copyright (C) Copyright (C) 2008 - 2013 The OGP Development Team
  5. #
  6. # http://www.opengamepanel.org/
  7. #
  8. # This program is free software; you can redistribute it and/or
  9. # modify it under the terms of the GNU General Public License
  10. # as published by the Free Software Foundation; either version 2
  11. # of the License, or any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, write to the Free Software
  20. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. #
  22. ####################
  23. # FUNCTIONs #
  24. ####################
  25. function indexOf(){
  26. # $1 = search string
  27. # $2 = string or char to find
  28. # Returns -1 if not found
  29. x="${1%%$2*}"
  30. [[ $x = $1 ]] && echo -1 || echo ${#x}
  31. }
  32. #####################
  33. # CODE ##########
  34. #####################
  35. if [ $EUID -ne 0 -a "$(uname -o)" != "Cygwin" ]; then
  36. echo "This script must be run as root" 1>&2
  37. exit 1
  38. fi
  39. usage()
  40. {
  41. cat << EOF
  42. Usage: $0 option
  43. OPTIONS:
  44. -s password Set the password for the agent's user (Linux)
  45. -p password Set the password for cyg_server user (Windows)
  46. -u ogpuser Set the username of the ogp user
  47. EOF
  48. }
  49. while getopts "hs:p:u" OPTION
  50. do
  51. case $OPTION in
  52. s)
  53. sudo_password=$OPTARG
  54. ;;
  55. p)
  56. cs_psw=$OPTARG
  57. ;;
  58. u)
  59. agent_user=$OPTARG
  60. ;;
  61. ?)
  62. exit
  63. ;;
  64. esac
  65. done
  66. if [ -z $1 ]
  67. then
  68. usage
  69. exit
  70. fi
  71. if [ "$(uname -o)" == "Cygwin" ]; then
  72. if [ -z $cs_psw ]
  73. then
  74. echo "Must use -p argument instead of -s."
  75. exit
  76. fi
  77. else
  78. if [ -z $sudo_password ]
  79. then
  80. echo "Must use -s argument instead of -p."
  81. exit
  82. fi
  83. fi
  84. readonly DEFAULT_PORT=12679
  85. readonly DEFAULT_IP=0.0.0.0
  86. readonly DEFAULT_FTP_PORT=21
  87. readonly DEFAULT_FTP_PASV_RANGE=40000:50000
  88. readonly AGENT_VERSION='v1.4'
  89. failed()
  90. {
  91. echo "ERROR: ${1}"
  92. exit 1
  93. }
  94. agent_home="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  95. cfgfile=${agent_home}/Cfg/Config.pm
  96. prefsfile=${agent_home}/Cfg/Preferences.pm
  97. bashprefsfile=${agent_home}/Cfg/bash_prefs.cfg
  98. overwrite_config=1
  99. if [ -e ${cfgfile} ]; then
  100. while [ 1 ]
  101. do
  102. echo "Overwrite old configuration?"
  103. echo -n "(yes/no) [Default yes]: "
  104. read octmp
  105. if [ "$octmp" == "yes" -o -z "$octmp" ]
  106. then
  107. break
  108. elif [ "$octmp" == "no" ]
  109. then
  110. overwrite_config=0
  111. break
  112. else
  113. echo "You need to type 'yes', 'no' or leave empty for default value [yes]."
  114. fi
  115. done
  116. fi
  117. if [ "X${overwrite_config}" == "X1" ]
  118. then
  119. if [ -z "$sudo_password" ]; then
  120. if [ -f "$cfgfile" ]; then
  121. sudo_password=`awk '/sudo_password/{print $3}' $cfgfile|sed -e "s#\('\)\(.*\)\(',\)#\2#"`
  122. fi
  123. fi
  124. echo "#######################################################################"
  125. echo ""
  126. echo "OGP agent uses basic encryption to prevent unauthorized users from connecting"
  127. echo "Enter a string of alpha-numeric characters for example 'abcd12345'"
  128. echo "**** NOTE - Use the same key in your Open Game Panel webpage config file - they must match *****"
  129. echo ""
  130. while [ -z "${key}" ]
  131. do
  132. echo -n "Set encryption key: "
  133. read key
  134. done
  135. echo
  136. echo "Set the listen port for the agent. The default should be fine for everyone."
  137. echo "However, if you want to change it that can be done here, otherwise just press Enter."
  138. echo -n "Set listen port [Default ${DEFAULT_PORT}]: "
  139. read port
  140. if [ -z "${port}" ]
  141. then
  142. port=$DEFAULT_PORT
  143. fi
  144. echo
  145. echo "Set the listen IP for the agent."
  146. echo "Use ${DEFAULT_IP} to bind on all interfaces."
  147. echo -n "Set listen IP [Default ${DEFAULT_IP}]: "
  148. read ip
  149. if [ -z "${ip}" ]
  150. then
  151. ip=$DEFAULT_IP
  152. fi
  153. while [ 1 ]
  154. do
  155. echo
  156. echo "For some games the OGP panel is using Steam client."
  157. echo "This client has its own license that you need to agree before continuing."
  158. echo "This agreement is available at http://store.steampowered.com/subscriber_agreement/"
  159. echo;
  160. echo "Do you accept the terms of Steam(tm) Subscriber Agreement?"
  161. echo -n "(Accept|Reject): "
  162. read steam_license
  163. if [ "$steam_license" == "Accept" -o "$steam_license" == "Reject" ]
  164. then
  165. break;
  166. fi
  167. echo "You need to type either 'Accept' or 'Reject'."
  168. done
  169. echo "Writing Config file - $cfgfile"
  170. echo "%Cfg::Config = (
  171. logfile => '${agent_home}/ogp_agent.log',
  172. listen_port => '${port}',
  173. listen_ip => '${ip}',
  174. version => '${AGENT_VERSION}',
  175. key => '${key}',
  176. steam_license => '${steam_license}',
  177. sudo_password => '${sudo_password}',
  178. web_admin_api_key => '{your_admin_ogp_web_api_key_here}',
  179. web_api_url => '{your_url_to_ogp_api.php}',
  180. steam_dl_limit => '0',
  181. );" > $cfgfile
  182. if [ $? != 0 ]
  183. then
  184. failed "Failed to write config file."
  185. else
  186. chmod 600 ${cfgfile} || failed "Failed to chmod ${cfgfile} to 600."
  187. fi
  188. echo;
  189. while [ 1 ]
  190. do
  191. echo "The agent should be updated when the service is restarted or started?"
  192. echo -n "(yes|no) [Default yes]: "
  193. read auto_update
  194. if [ "${auto_update}" == "yes" -o "${auto_update}" == "no" -o -z "${auto_update}" ]
  195. then
  196. if [ "${auto_update}" == "yes" ]
  197. then
  198. autoUpdate=1
  199. elif [ -z "${auto_update}" ]
  200. then
  201. autoUpdate=1
  202. else
  203. autoUpdate=0
  204. fi
  205. break;
  206. fi
  207. echo "You need to type 'yes', 'no' or leave empty for default value [yes]."
  208. done
  209. echo;
  210. while [ 1 ]
  211. do
  212. echo "The agent should backup the server log files in the game server directory?"
  213. echo -n "(yes|no) [Default yes]: "
  214. read log_local_copy
  215. if [ "${log_local_copy}" == "yes" -o "${log_local_copy}" == "no" -o -z "${log_local_copy}" ]
  216. then
  217. if [ "${log_local_copy}" == "yes" ]
  218. then
  219. logLocalCopy=1
  220. elif [ -z "${log_local_copy}" ]
  221. then
  222. logLocalCopy=1
  223. else
  224. logLocalCopy=0
  225. fi
  226. break;
  227. fi
  228. echo "You need to type 'yes', 'no' or leave empty for default value [yes]."
  229. done
  230. echo;
  231. echo "After how many days should be deleted the old backups of server's logs?"
  232. echo -n "[Default 30]: "
  233. read delete_logs_after
  234. case ${delete_logs_after} in
  235. ''|*[!0-9]*) deleteLogsAfter=30 ;;
  236. *) deleteLogsAfter=${delete_logs_after} ;;
  237. esac
  238. echo;
  239. while [ 1 ]
  240. do
  241. echo "The agent should automatically restart game servers if they crash?"
  242. echo -n "(yes|no) [Default yes]: "
  243. read auto_restart
  244. if [ "${auto_restart}" == "yes" -o "${auto_restart}" == "no" -o -z "${auto_restart}" ]
  245. then
  246. if [ "${auto_restart}" == "yes" ]
  247. then
  248. autoRestart=1
  249. elif [ -z "${auto_restart}" ]
  250. then
  251. autoRestart=1
  252. else
  253. autoRestart=0
  254. fi
  255. break;
  256. fi
  257. echo "You need to type 'yes', 'no' or leave empty for default value [yes]."
  258. done
  259. echo;
  260. while [ 1 ]
  261. do
  262. echo "Should Open Game Panel create and manage FTP accounts?"
  263. echo -n "(yes|no) [Default yes]: "
  264. read manage_ftp
  265. if [ "${manage_ftp}" == "yes" -o "${manage_ftp}" == "no" -o -z "${manage_ftp}" ]
  266. then
  267. if [ "${manage_ftp}" == "yes" ]
  268. then
  269. ogpManagesFTP=1
  270. elif [ -z "${manage_ftp}" ]
  271. then
  272. ogpManagesFTP=1
  273. else
  274. ogpManagesFTP=0
  275. fi
  276. break;
  277. fi
  278. echo "You need to type 'yes', 'no' or leave empty for default value [yes]."
  279. done
  280. echo;
  281. # Only ask these install questions if users want OGP to manage FTP accounts
  282. if [ "$ogpManagesFTP" == "1" ]
  283. then
  284. if [ "$(uname -o)" != "Cygwin" ]; then
  285. while [ 1 ]
  286. do
  287. echo "If you are running ISPConfig 3 in this machine the agent"
  288. echo "can use it to create FTP accounts instead of using Pure-FTPd."
  289. echo "Would you like to configure this agent to use the API of ISPConfig 3?"
  290. echo -n "(yes|no) [Default no]: "
  291. read IspConfig
  292. if [ "${IspConfig}" == "yes" -o "${IspConfig}" == "no" -o -z "${IspConfig}" ]
  293. then
  294. if [ "${IspConfig}" == "yes" ]
  295. then
  296. ftpMethod="IspConfig"
  297. else
  298. IspConfig="no"
  299. fi
  300. break;
  301. fi
  302. echo "You need to type 'yes', 'no' or leave empty for default value [no]."
  303. done
  304. if [ "${IspConfig}" == "yes" ]
  305. then
  306. while [ 1 ]
  307. do
  308. echo "Do you use HTTPS to access to your ISPConfig 3 Panel?"
  309. echo -n "(yes|no) [Default no]: "
  310. read https
  311. if [ "${https}" == "yes" -o "${https}" == "no" -o -z "${https}" ]
  312. then
  313. if [ "${https}" == "yes" ]
  314. then
  315. secure="s"
  316. else
  317. secure=""
  318. fi
  319. break;
  320. fi
  321. echo "You need to type 'yes', 'no' or leave empty for default value [no]."
  322. done
  323. echo -n "What port do you use to connect to your ISPConfig 3 Panel? [Default 8080]: "
  324. read setport
  325. case ${setport} in
  326. ''|*[!0-9]*) port=8080 ;;
  327. *) port=${setport} ;;
  328. esac
  329. echo -n "Enter an user name to sing in remotelly (Remote user): "
  330. read remote_login_username
  331. echo -n "Enter password (Remote user): "
  332. read remote_login_password
  333. echo -e "<?php\n\$username = '${remote_login_username}';" > ${agent_home}/IspConfig/soap_config.php
  334. echo "\$password = '${remote_login_password}';" >> ${agent_home}/IspConfig/soap_config.php
  335. echo "\$soap_location = 'http${secure}://127.0.0.1:${port}/remote/index.php';" >> ${agent_home}/IspConfig/soap_config.php
  336. echo -e "\$soap_uri = 'http${secure}://127.0.0.1:${port}/remote/';\n?>" >> ${agent_home}/IspConfig/soap_config.php
  337. else
  338. while [ 1 ]
  339. do
  340. echo;
  341. echo "If you have installed the Easy Hosting Control Panel (EHCP - www.ehcpforce.tk),"
  342. echo "the agent can use it to create FTP accounts instead of using Pure-FTPd."
  343. echo "Would you like to configure this agent to use the API of EHCP?"
  344. echo -n "(yes|no) [Default no]: "
  345. read ehcp
  346. if [ "${ehcp}" == "yes" -o "${ehcp}" == "no" -o -z "${ehcp}" ]
  347. then
  348. if [ "${ehcp}" == "yes" ]
  349. then
  350. ftpMethod="EHCP"
  351. fi
  352. break;
  353. fi
  354. echo "You need to type 'yes', 'no' or leave empty for default value [no]."
  355. done
  356. if [ "${ehcp}" == "yes" ]
  357. then
  358. echo "Please enter the MySQL database password for the ehcp user"
  359. echo -n "(created during the install of EHCP): "
  360. read ehcpDB
  361. ehcpConf=${agent_home}/EHCP/config.php
  362. sed -i "s/changeme/${ehcpDB}/" $ehcpConf
  363. else
  364. while [ 1 ]
  365. do
  366. echo;
  367. echo "The agent can use ProFTPd to create FTP accounts."
  368. echo "Would you like to configure this agent to use the ProFTPd?"
  369. echo -n "(yes|no) [Default no]: "
  370. read proftpd
  371. if [ "${proftpd}" == "yes" -o "${proftpd}" == "no" -o -z "${proftpd}" ]
  372. then
  373. if [ "${proftpd}" == "yes" ]
  374. then
  375. ftpMethod="proftpd"
  376. fi
  377. break;
  378. fi
  379. echo "You need to type 'yes', 'no' or leave empty for default value [no]."
  380. done
  381. if [ "${proftpd}" == "yes" ]
  382. then
  383. echo "Please enter the path for proFTPd configuration file"
  384. echo -n "[Default /etc/proftpd/proftpd.conf]: "
  385. read proFTPdConfFile
  386. if [ -z $proFTPdConfFile ]
  387. then
  388. proFTPdConfFile="/etc/proftpd/proftpd.conf"
  389. if [ ! -e "$proFTPdConfFile" ]; then
  390. proFTPdConfFile="/etc/proftpd.conf"
  391. fi
  392. fi
  393. proFTPdConfPath=$(dirname ${proFTPdConfFile})
  394. while [ 1 ]
  395. do
  396. if [ ! -e $proFTPdConfFile ]
  397. then
  398. echo "The file ${proFTPdConfFile} does not exists,"
  399. echo "what you want to do, reenter it or ignore and continue?"
  400. echo "If your answer is 'ignore' is meant that you will install proFTPd later."
  401. echo -n "(reenter|ignore): "
  402. read answer
  403. if [ "${answer}" == "reenter" -o "${answer}" == "ignore" ]
  404. then
  405. if [ "${answer}" == "reenter" ]
  406. then
  407. echo "Reenter proFTPd's configuration file path:"
  408. read proFTPdConfFile
  409. continue
  410. elif [ "${answer}" == "ignore" ]
  411. then
  412. echo "You will need to append this to ${proFTPdConfFile} once you've installed proftpd:"
  413. bold=`tput bold`
  414. normal=`tput sgr0`
  415. echo -e "\n\n${bold}RequireValidShell off\nAuthUserFile ${proFTPdConfPath}/ftpd.passwd\nAuthGroupFile ${proFTPdConfPath}/ftpd.group${normal}\n\n"
  416. break
  417. fi
  418. fi
  419. echo "You need to type 'reenter' or 'ignore'."
  420. else
  421. if egrep -iq "LoadModule\s*mod_auth_file.c" ${proFTPdConfFile}
  422. then
  423. sed -i "s/\s*#\s*LoadModule\s*mod_auth_file.c/LoadModule mod_auth_file.c/g" ${proFTPdConfFile}
  424. else
  425. echo -e "LoadModule mod_auth_file.c" >> ${proFTPdConfFile}
  426. fi
  427. if egrep -iq "^\s*AuthOrder.*" ${proFTPdConfFile}
  428. then
  429. if egrep -iq "^\s*AuthOrder.*mod_auth_file.c" ${proFTPdConfFile}
  430. then
  431. false
  432. else
  433. sed -ri "s/(^\s*AuthOrder.*)/\1 mod_auth_file.c/g" ${proFTPdConfFile}
  434. fi
  435. else
  436. echo -e "AuthOrder mod_auth_file.c" >> ${proFTPdConfFile}
  437. fi
  438. if egrep -iq "RequireValidShell.*" ${proFTPdConfFile}
  439. then
  440. sed -i "s#RequireValidShell.*#RequireValidShell off#g" ${proFTPdConfFile}
  441. else
  442. echo -e "RequireValidShell off" >> ${proFTPdConfFile}
  443. fi
  444. if egrep -iq "AuthUserFile.*" ${proFTPdConfFile}
  445. then
  446. sed -i "s#AuthUserFile.*#AuthUserFile ${proFTPdConfPath}/ftpd.passwd#g" ${proFTPdConfFile}
  447. else
  448. echo -e "AuthUserFile "${proFTPdConfPath}"/ftpd.passwd" >> ${proFTPdConfFile}
  449. fi
  450. if egrep -iq "AuthGroupFile.*" ${proFTPdConfFile}
  451. then
  452. sed -i "s#AuthGroupFile.*#AuthGroupFile ${proFTPdConfPath}/ftpd.group#g" ${proFTPdConfFile}
  453. else
  454. echo -e "AuthGroupFile "${proFTPdConfPath}"/ftpd.group" >> ${proFTPdConfFile}
  455. fi
  456. # Allow global overwrite (http://opengamepanel.org/forum/viewthread.php?thread_id=5202)
  457. if egrep -iq "AllowOverwrite.*" ${proFTPdConfFile}
  458. then
  459. sed -i "s#AllowOverwrite.*#AllowOverwrite yes#g" ${proFTPdConfFile}
  460. else
  461. echo -e "<Global>\nAllowOverwrite yes\n</Global>" >> ${proFTPdConfFile}
  462. fi
  463. if [ ! -e "${proFTPdConfPath}/ftpd.group" ]
  464. then
  465. touch ${proFTPdConfPath}/ftpd.group
  466. fi
  467. if [ ! -e "${proFTPdConfPath}/ftpd.passwd" ]
  468. then
  469. touch ${proFTPdConfPath}/ftpd.passwd
  470. fi
  471. ftpd_user=$(grep -oP '^User\s+\K.+' ${proFTPdConfFile})
  472. ftpd_group=$(grep -oP '^Group\s+\K.+' ${proFTPdConfFile})
  473. if [ -z "$agent_user" ]; then
  474. agent_user=$(grep -oP 'agent_user=\K.+' /etc/init.d/ogp_agent)
  475. fi
  476. if [ ! -z "$ftpd_user" ] && [ ! -z "$ftpd_group" ] && [ ! -z "$agent_user" ]
  477. then
  478. if [ "$(groups $agent_user|grep $ftpd_group)" == "" ]
  479. then
  480. usermod -aG $ftpd_group $agent_user
  481. fi
  482. if [ -e "${proFTPdConfPath}/ftpd.passwd" -a -e "${proFTPdConfPath}/ftpd.group" ]
  483. then
  484. chmod 640 ${proFTPdConfPath}/ftpd.*
  485. chown -f $ftpd_user:$ftpd_group ${proFTPdConfPath}/ftpd.*
  486. fi
  487. fi
  488. break
  489. fi
  490. done
  491. if [ -e "/etc/init.d/proftpd" ]
  492. then
  493. /etc/init.d/proftpd restart
  494. else
  495. echo "If proftpd is running, to apply the changes, you must restart the service."
  496. fi
  497. else
  498. ftpMethod="PureFTPd"
  499. fi
  500. fi
  501. fi
  502. else
  503. if uname -a|grep -q "x86_64"
  504. then
  505. FZ="yes"
  506. else
  507. while [ 1 ]
  508. do
  509. echo;
  510. echo "If you have installed the FileZilla Server,"
  511. echo "the agent can use it to create FTP accounts instead of using Pure-FTPd."
  512. echo "Would you like to configure this agent to use it?"
  513. echo -n "(yes|no) [Default no]: "
  514. read FZ
  515. if [ "${FZ}" == "yes" -o "${FZ}" == "no" -o -z "${FZ}" ]
  516. then
  517. break;
  518. fi
  519. echo "You need to type 'yes', 'no' or leave empty for default value [no].";
  520. done
  521. fi
  522. if [ "${FZ}" == "yes" ]; then
  523. ftpMethod="FZ"
  524. PF=$(cmd /Q /C echo %PROGRAMFILES\(X86\)% | sed 's/\r$//')
  525. if [ "X${PF}" == "X" ];then PF=$(cmd /Q /C echo %PROGRAMFILES% | sed 's/\r$//'); fi
  526. echo;
  527. echo "Please enter the path for FileZilla server executable file"
  528. echo -n "[Default ${PF}\\FileZilla Server\\FileZilla server.exe]: "
  529. read -r FZ_EXE
  530. if [ -z "${FZ_EXE}" ]
  531. then
  532. FZ_EXE="${PF}\\FileZilla Server\\FileZilla server.exe"
  533. fi
  534. echo;
  535. echo "Please enter the path for FileZilla server xml file"
  536. echo -n "[Default ${PF}\\FileZilla Server\\FileZilla Server.xml]: "
  537. read -r FZ_XML
  538. if [ -z "${FZ_XML}" ]
  539. then
  540. FZ_XML="${PF}\\FileZilla Server\\FileZilla server.xml"
  541. fi
  542. FZ_EXE=$(cygpath -u "$FZ_EXE")
  543. FZ_XML=$(cygpath -u "$FZ_XML")
  544. FZconf=${agent_home}/Cfg/FileZilla.pm
  545. echo -e "%Cfg::FileZilla = (\n\tfz_exe => '${FZ_EXE}',\n\tfz_xml => '${FZ_XML}'\n);" > ${FZconf}
  546. if [ $? != 0 ]
  547. then
  548. failed "Failed to write FileZilla configuration file."
  549. fi
  550. if [ ! -z "$cs_psw" ]; then
  551. UD=$(cmd /Q /C echo %USERDOMAIN% | sed 's/\r$//')
  552. net stop "FileZilla Server"
  553. sc config "FileZilla Server" obj= "${UD}\cyg_server" password= "$cs_psw" type= own
  554. net start "FileZilla Server"
  555. fi
  556. else
  557. if uname -a|grep -qv "x86_64"
  558. then
  559. ftpMethod="PureFTPd"
  560. echo;
  561. echo "Set the listen IP for the PureFTPd."
  562. echo "Default is (${DEFAULT_IP}) to bind on all interfaces."
  563. echo -n "Set listen IP [Default ${DEFAULT_IP}]: "
  564. read ftp_ip
  565. if [ -z "${ftp_ip}" ]
  566. then
  567. ftp_ip=$DEFAULT_IP
  568. fi
  569. echo
  570. echo "Set the listen port for PureFTPd. The default should be fine for everyone."
  571. echo "However, if you want to change it that can be done here, otherwise just press Enter."
  572. echo -n "Set listen port [Default ${DEFAULT_FTP_PORT}]: "
  573. read port
  574. if [ -z "${ftp_port}" ]
  575. then
  576. ftp_port=$DEFAULT_FTP_PORT
  577. fi
  578. echo
  579. echo "Passive-mode downloads."
  580. echo "This is especially useful if the server is behind a firewall."
  581. echo -n "Use only ports in the range?(yes|no)[Default no]: "
  582. read passive_ftp
  583. if [ -z "${passive_ftp}" -o "${passive_ftp}" != "yes" ]
  584. then
  585. ftp_pasv_range=""
  586. else
  587. echo "Enter passive ports range separated by colon (<first port>:<last port>)."
  588. echo -n "[Default ${DEFAULT_FTP_PASV_RANGE}]: "
  589. read ftp_pasv_range
  590. if [ -z "${ftp_pasv_range}" ]
  591. then
  592. ftp_pasv_range=$DEFAULT_FTP_PASV_RANGE
  593. fi
  594. fi
  595. fi
  596. fi
  597. fi
  598. fi
  599. if [ "${ftpMethod}" == "PureFTPd" ]
  600. then
  601. run_pureftpd=1
  602. else
  603. run_pureftpd=0
  604. fi
  605. echo "Writing Preferences file - $prefsfile"
  606. prefs="%Cfg::Preferences = (\n"
  607. prefs="${prefs}\tscreen_log_local => '${logLocalCopy}',\n"
  608. prefs="${prefs}\tdelete_logs_after => '${deleteLogsAfter}',\n"
  609. prefs="${prefs}\togp_manages_ftp => '${ogpManagesFTP}',\n"
  610. prefs="${prefs}\tftp_method => '${ftpMethod}',\n"
  611. prefs="${prefs}\togp_autorestart_server => '${autoRestart}',\n"
  612. prefs="${prefs}\tprotocol_shutdown_waittime => '10',\n"
  613. if [ "X${proftpd}" == "Xyes" ]
  614. then
  615. prefs="${prefs}\tproftpd_conf_path => '${proFTPdConfPath}'\n"
  616. fi
  617. prefs="${prefs});"
  618. echo -e $prefs > $prefsfile
  619. if [ $? != 0 ]
  620. then
  621. failed "Failed to write preferences file."
  622. fi
  623. echo "Writing bash script preferences file - $bashprefsfile"
  624. echo -e "agent_auto_update=${autoUpdate}\nrun_pureftpd=${run_pureftpd}\nftp_port=${ftp_port}\nftp_ip=${ftp_ip}\nftp_pasv_range=${ftp_pasv_range}" > $bashprefsfile
  625. if [ $? != 0 ]
  626. then
  627. failed "Failed to write MISC configuration file used by bash scripts."
  628. fi
  629. fi