Difference between revisions of "AMuleWeb PHP"
Woutermense (Talk | contribs) m (→amule_do_download_cmd) |
Woutermense (Talk | contribs) |
||
Line 1: | Line 1: | ||
− | |||
= Introduction = | = Introduction = | ||
− | |||
[[aMuleWeb]] is an add-on program, used together with [[aMule]] and serves as webserver, allowing user to control aMule through browser interface. aMuleWeb works very similar to regular and wide-known webservers such as Apache[http://www.apache.org] - set of HTML pages stored on server side (called "template"). Those pages contains embedded server-side script, which is running when user requests the page. Resulting page is returned to user. | [[aMuleWeb]] is an add-on program, used together with [[aMule]] and serves as webserver, allowing user to control aMule through browser interface. aMuleWeb works very similar to regular and wide-known webservers such as Apache[http://www.apache.org] - set of HTML pages stored on server side (called "template"). Those pages contains embedded server-side script, which is running when user requests the page. Resulting page is returned to user. | ||
Line 92: | Line 90: | ||
=== amule_do_server_cmd === | === amule_do_server_cmd === | ||
− | '''''amule_do_server_cmd($server_ip, $server_port, | + | '''''amule_do_server_cmd($server_ip, $server_port, $command)''''': Used to connect to or disconnect from a server or to remove a server. '''''$command''''' can be '''connect''', '''disconnect''' or '''remove'''. |
=== amule_get_stats === | === amule_get_stats === | ||
− | '''''amule_get_stats()''''' | + | '''''amule_get_stats()''''': Used to query the status of aMule. Returns a hash with the keys: '''id, serv_addr, serv_name, serv_users, kad_connected, kad_firewalled, speed_up, speed_down, speed_limit_up, speed_limit_down'''. |
=== amule_get_categories === | === amule_get_categories === | ||
Line 106: | Line 104: | ||
=== amule_get_options === | === amule_get_options === | ||
'''''amule_get_options()''''': return options and their values. Options are returned in form of hash, where keys are categories and values are hashes of name-value for each option. | '''''amule_get_options()''''': return options and their values. Options are returned in form of hash, where keys are categories and values are hashes of name-value for each option. | ||
+ | |||
+ | Returned keys are: '''nick, connection, files, webserver, coretweaks'''. | ||
+ | |||
+ | Value of '''connection''' is a hash with keys: '''max_line_up_cap, max_line_down_cap, max_up_limit, max_down_limit, slot_alloc, tcp_port, udp_port, udp_dis, max_file_src, max_conn_total, autoconn_en, reconn_en'''. | ||
+ | |||
+ | Value of '''files''' is a hash with keys: '''ich_en, aich_trust, new_files_paused, new_files_auto_dl_prio, preview_prio, new_files_auto_ul_prio, upload_full_chunks, first_last_chunks_prio, start_next_paused, resume_same_cat, save_sources, extract_metadata, alloc_full, check_free_space, min_free_space'''. | ||
+ | |||
+ | Value of '''webserver''' is a hash with keys: '''use_gzip, autorefresh_time'''. | ||
+ | |||
+ | Value of '''coretweaks''' is a hash with key: '''max_conn_5sec'''. | ||
=== amule_set_options === | === amule_set_options === | ||
Line 111: | Line 119: | ||
=== amule_do_search_download_cmd === | === amule_do_search_download_cmd === | ||
− | '''''amule_do_search_download_cmd($file_hash, $cat)''''': | + | '''''amule_do_search_download_cmd($file_hash, $cat)''''': Used to download 1 of the search results. |
=== amule_do_search_start_cmd === | === amule_do_search_start_cmd === | ||
Line 117: | Line 125: | ||
=== amule_get_log === | === amule_get_log === | ||
− | '''''amule_get_log($rst)''''': | + | '''''amule_get_log($rst)''''': Returns log if $rst = "0", resets log otherwise. |
$log = amule_get_log(); | $log = amule_get_log(); | ||
echo "My log:", $log; | echo "My log:", $log; | ||
=== amule_get_serverinfo === | === amule_get_serverinfo === | ||
− | '''''amule_get_serverinfo($rst)''''': | + | '''''amule_get_serverinfo($rst)''''': Request contents of server info if $rst = "0", resets contents otherwise |
=== amule_do_ed2k_download_cmd === | === amule_do_ed2k_download_cmd === | ||
− | '''''amule_do_ed2k_download_cmd($link, $cat)''''': | + | '''''amule_do_ed2k_download_cmd($link, $cat)''''': Download ed2k link. Params: link, category (default=0) |
=== amule_load_vars === | === amule_load_vars === | ||
Line 144: | Line 152: | ||
'''downloads''': return an array of ''Object(AmuleDownloadFile)''. The fields of this are: | '''downloads''': return an array of ''Object(AmuleDownloadFile)''. The fields of this are: | ||
− | # 'name' (full name with extension) | + | # '''name''' (full name with extension) |
− | # 'short_name' (the full name trucated after some chars and ended with three periods) | + | # '''short_name''' (the full name trucated after some chars and ended with three periods) |
− | # 'size' (in byte) | + | # '''hash''' (univoque id of the file, is used for other commands) |
− | # 'size_done' (completed bytes) | + | # '''progress''' |
− | # 'size_xfer' (transfered bytes) | + | # '''link''' (full ed2k link, be aware: it included you ip as sources) |
− | # 'speed' (actually download speed, in bytes/sec) | + | # '''category''' (id of the category of the file, where 0 = all, 1 = first category, etc.. see '''''amule_get_categories''''') |
− | # 'src_count' (total number of source found) | + | # '''status''' (where 7=stopped / paused, for other status valute the transfer rate or src_count_xfer, if it's 0 status=waiting, else downloading'. Actually I don't know how distinguish from 'stopped' and 'paused') |
− | # 'src_count_not_curr' (number of sources not fully identified and connected to, so for total of valid source you use src_count - src_count_not_curr) | + | # '''size''' (in byte) |
− | # 'prio' (priority of downloading where 0 => "Low", 1 => "Normal", 2 => "High", 3 => "Very high", 4 => "Very low", 5=> "Auto", 6 => "Powershare") | + | # '''size_done''' (completed bytes) |
− | # 'prio_auto' (boolean, 0 = false, 1 = true) | + | # '''size_xfer''' (transfered bytes) |
− | # ' | + | # '''speed''' (actually download speed, in bytes/sec) |
− | + | # '''src_count''' (total number of source found) | |
− | + | # '''src_count_not_curr''' (number of sources not fully identified and connected to, so for total of valid source you use '''src_count''' - '''src_count_not_curr''') | |
− | + | # '''src_count_a4af''' (sources not used because used for another file) | |
− | + | # '''src_count_xfer''' (source transfering in this moment) | |
+ | # '''prio''' (priority of downloading where 0 => "Low", 1 => "Normal", 2 => "High", 3 => "Very high", 4 => "Very low", 5=> "Auto", 6 => "Powershare") | ||
+ | # '''prio_auto''' (boolean, 0 = false, 1 = true) | ||
+ | # '''last_seen_complete''' show last seen date / time, timestamp format | ||
'''uploads''': return an array of ''Object(AmuleUploadFile)''. The fields of this are: | '''uploads''': return an array of ''Object(AmuleUploadFile)''. The fields of this are: | ||
− | # 'name' (full file name with extension) | + | # '''name''' (full file name with extension) |
− | # 'short_name' (the full name trucated after some chars and ended with three periods) | + | # '''short_name''' (the full name trucated after some chars and ended with three periods) |
− | # 'xfer_up' (total of uploaded bytes of this file to this client) | + | # '''xfer_up''' (total of uploaded bytes of this file to this client) |
− | # 'xfer_down' (total of downloaded bytes of this file from this client) | + | # '''xfer_down''' (total of downloaded bytes of this file from this client) |
− | # 'xfer_speed' (actual upload speed of this file to this client, in bytes/sec) | + | # '''xfer_speed''' (actual upload speed of this file to this client, in bytes/sec) |
+ | |||
+ | '''shared''': returns an array of ''Object(AmuleSharedFile)''. The fields of this are: | ||
+ | # '''name''' | ||
+ | # '''short_name''': | ||
+ | # '''hash''': | ||
+ | # '''size''' | ||
+ | # '''link''' | ||
+ | # '''xfer''' | ||
+ | # '''xfer_all''' | ||
+ | # '''req''' | ||
+ | # '''req_all''' | ||
+ | # '''accept''': | ||
+ | # '''accept_all''': | ||
+ | # '''prio''' | ||
+ | # '''prio_auto''': | ||
+ | |||
+ | '''searchresult''': returns an array of ''Object(AmuleSearchResult)''. The fields of this are: | ||
+ | # '''name''' | ||
+ | # '''short_name''' | ||
+ | # '''hash''' | ||
+ | # '''size''' | ||
+ | # '''sources''' | ||
+ | # '''present''' | ||
+ | '''servers''': | ||
+ | |||
+ | '''stats_graph''': returns stats graphs images (?) | ||
+ | |||
+ | '''stats_tree''': returns stats tree (?) | ||
=== amule_get_version === | === amule_get_version === | ||
− | '''''amule_get_version()''''': | + | '''''amule_get_version()''''': Returns version number string. |
= Authentication = | = Authentication = |
Revision as of 16:22, 23 May 2009
Contents
- 1 Introduction
- 2 Conventions
- 3 Interaction with PHP and webserver
- 4 Core language constructs
- 5 Library
- 5.1 Predefined global variables
- 5.2 Functions
- 5.2.1 amule_do_shared_cmd
- 5.2.2 amule_do_reload_shared_cmd
- 5.2.3 amule_do_download_cmd
- 5.2.4 amule_kad_connect
- 5.2.5 amule_do_add_server_cmd
- 5.2.6 amule_do_server_cmd
- 5.2.7 amule_get_stats
- 5.2.8 amule_get_categories
- 5.2.9 amule_get_options
- 5.2.10 amule_set_options
- 5.2.11 amule_do_search_download_cmd
- 5.2.12 amule_do_search_start_cmd
- 5.2.13 amule_get_log
- 5.2.14 amule_get_serverinfo
- 5.2.15 amule_do_ed2k_download_cmd
- 5.2.16 amule_load_vars
- 5.2.17 amule_get_version
- 6 Authentication
- 7 Errors and debugging
Introduction
aMuleWeb is an add-on program, used together with aMule and serves as webserver, allowing user to control aMule through browser interface. aMuleWeb works very similar to regular and wide-known webservers such as Apache[1] - set of HTML pages stored on server side (called "template"). Those pages contains embedded server-side script, which is running when user requests the page. Resulting page is returned to user.
The scripting language, aMuleWeb using is very similar to widely known "PHP", developed and distributed by Zend company [2]. Since aMuleWeb implementation is differ from original PHP, I will call it "aMuleWeb PHP" for reader convenience. "The PHP" language, will be referred as "real PHP" or just "PHP" to make difference between the two.
Conventions
Language elements and reserved words are marked bold: keyword. Things that are not part of syntax, but are reserved or predefined are marked bold italic: special_var. Language limitations are marked like:
- Making cofee not supported
Interaction with PHP and webserver
Similarly to real PHP, script is embedded into regular HTML pages using <?php ?> marks. Page must have .php extension in order to be searched for script. Note, that markups can not be nested, i.e. placing <html> marks inside of <?php ?> will result in syntax error.
Core language constructs
aMuleWeb PHP have same basic language elements as real PHP version 5. Several things supported or implemented differently: OO constructs (classes) may pass syntax check, but they are not supported in any way. include construct is parse-time directive (in contrary to PHP, where you can do it in run-time and check result of "include" operation) There's no list at all.
Variables
There's scalar (referred as $var) and array (referred as @var) variables. Similarly to real PHP all variables are local, unless defined otherwise. Variables, marked as global must be declated before this definition. Example:
$a = 1;
function foo() { global $a; }
References to variable and to array members are fully supported:
$a = &$b; $c = &$c[5];
- Reference of variable by name like $$var is not supported.
- Integer variables are 64-bit unsigned integers
- Variable substitution inside of "" is not supported.
Operators
All PHP operators supported. Implicit type conversion is supported too, as common in scripting languages. This way 1 + "2" = 3.
- Prefix and postfix ++ and -- are not distinguished (prefix form used)
- Using operator + for array mean "join" in real PHP. Here array is interpreted as integer equal to number of elements.
Subroutines
function construct is fully supported. In contrary to regular PHP function must be defined prior calling. It is error to do otherwise. Functions can be recursive, thou. Real PHP allows to omit parameters for function calls (default parameters). aMuleWeb PHP does not support this conventions, which mean that all parameters must be present when function is called. This is not an error, and parameters will receive predefined values when omit: 0 for numbers, "" (empty string) for strings. Parameters can be references or arrays with usual meaning.
- Function can not return reference.
Library
PHP language is known to have huge library of useful subroutines. Those subroutines are used to perform various tasks, varying from simple string manipulation to complex databases and OS binding. aMuleWeb PHP on the other hand, have very limited library. There's several reasons behind this fact. First of all, it is out of question to completely re-create PHP library, given it's size and complexity. Second, and most important, it's not really needed. aMuleWeb PHP is built to serve very specific application, and used to create very specific kind of pages. It will not be used to create e-commerce site or webmail. List below summarize supported functions:
- var_dump($var): var_dump()
- strlen($string):strlen()
- usort($var): usort()
- isset($var): isset()
Predefined global variables
Similarly to real PHP, there's set of special, or predefined variables, which have special meaning. Those variables may indicate input received from user, or they may control script execution. Those variables have same name as in real PHP, but functionality may be limited.
$_SESSION: Hash of values that survive between engine invocation per session. Some of it's values are predefined by webserver itself.
- $_SESSION["guest_login"]: set to 1 when password supplied belongs to low-right user, 0 otherwise
- $_SESSION["login_error"]: set when bad password supplied, normally is an empty string.
- $_SESSION["auto_refresh"]: always set; indicate time to autorefresh (in seconds). User can supply a zero. Can be used in http-equiv:
<?php if ( $_SESSION["auto_refresh"] > 0 ) { echo "<meta http-equiv=\"refresh\" content=\"", $_SESSION["auto_refresh"], '">'; } ?>
$HTTP_GET_VARS: Hash of values passed from browser on GET or POST method
Functions
The whole purpose of aMuleWeb control aMule. aMuleWeb PHP provide library functions for convinient access to underlying aMule datastructure for both queries and actions.
amule_do_shared_cmd($file_hash, $command, $optional_arg): Used to change the priority of a shared file. $command can be prioup, priodown or prio. In case prio is used, $optional_arg needs to contain the new priority.
amule_do_reload_shared_cmd(): Used to reload the list of shared files fom disk.
amule_do_download_cmd
amule_do_download_cmd($file_hash, $command, $optional_arg): Used to change a parameter of a file in the downloads list. $command can be pause, resume, cancel, prio, prioup or priodown. In case of prio, $optional_arg needs to contain the new priority.
amule_kad_connect
amule_kad_connect($bootstrap_ip, $bootstrap_port): Used to connect to the Kad network.
amule_do_add_server_cmd
amule_do_add_server_cmd($server_addr, $server_port, $server_name): Used to add a server to the server list.
amule_do_server_cmd
amule_do_server_cmd($server_ip, $server_port, $command): Used to connect to or disconnect from a server or to remove a server. $command can be connect, disconnect or remove.
amule_get_stats
amule_get_stats(): Used to query the status of aMule. Returns a hash with the keys: id, serv_addr, serv_name, serv_users, kad_connected, kad_firewalled, speed_up, speed_down, speed_limit_up, speed_limit_down.
amule_get_categories
amule_get_categories(): return list of valid categories in form of a associative array, the key is and index starting from 0 (= all), the value is the full name of the category ('all' is the 0-indexed, others may be "film", "Docs", etc...)
$cat_list = amule_get_categories(); foreach($cat_list as $key => $cat_string) { echo "cat = ". $cat_string ."- key = ". $key; }
amule_get_options
amule_get_options(): return options and their values. Options are returned in form of hash, where keys are categories and values are hashes of name-value for each option.
Returned keys are: nick, connection, files, webserver, coretweaks.
Value of connection is a hash with keys: max_line_up_cap, max_line_down_cap, max_up_limit, max_down_limit, slot_alloc, tcp_port, udp_port, udp_dis, max_file_src, max_conn_total, autoconn_en, reconn_en.
Value of files is a hash with keys: ich_en, aich_trust, new_files_paused, new_files_auto_dl_prio, preview_prio, new_files_auto_ul_prio, upload_full_chunks, first_last_chunks_prio, start_next_paused, resume_same_cat, save_sources, extract_metadata, alloc_full, check_free_space, min_free_space.
Value of webserver is a hash with keys: use_gzip, autorefresh_time.
Value of coretweaks is a hash with key: max_conn_5sec.
amule_set_options
amule_set_options($options_hash): set aMule options. Receives hash in form returned by amule_get_options()
amule_do_search_download_cmd
amule_do_search_download_cmd($file_hash, $cat): Used to download 1 of the search results.
amule_do_search_start_cmd
amule_do_search_start_cmd($search, $ext, $filetype, $type, $avail, $min_size, $max_size):
amule_get_log
amule_get_log($rst): Returns log if $rst = "0", resets log otherwise.
$log = amule_get_log(); echo "My log:", $log;
amule_get_serverinfo
amule_get_serverinfo($rst): Request contents of server info if $rst = "0", resets contents otherwise
amule_do_ed2k_download_cmd
amule_do_ed2k_download_cmd($link, $cat): Download ed2k link. Params: link, category (default=0)
amule_load_vars
amule_load_vars($name_of_variable): Query aMule datastructure. Result is returned as array of hashes, where each hash represent item in aMule datastructure (upload, download, client, item in search result). Following are possible category names:
- 'downloads'
- 'uploads'
- 'searchresult'
- 'shared'
- 'servers'
- 'stats_graph'
- 'stats_tree'
$var = amule_load_vars($name_of_variable) foreach ($var as $i) { }
Some info about data structures retrieved via amule_load_vars
downloads: return an array of Object(AmuleDownloadFile). The fields of this are:
- name (full name with extension)
- short_name (the full name trucated after some chars and ended with three periods)
- hash (univoque id of the file, is used for other commands)
- progress
- link (full ed2k link, be aware: it included you ip as sources)
- category (id of the category of the file, where 0 = all, 1 = first category, etc.. see amule_get_categories)
- status (where 7=stopped / paused, for other status valute the transfer rate or src_count_xfer, if it's 0 status=waiting, else downloading'. Actually I don't know how distinguish from 'stopped' and 'paused')
- size (in byte)
- size_done (completed bytes)
- size_xfer (transfered bytes)
- speed (actually download speed, in bytes/sec)
- src_count (total number of source found)
- src_count_not_curr (number of sources not fully identified and connected to, so for total of valid source you use src_count - src_count_not_curr)
- src_count_a4af (sources not used because used for another file)
- src_count_xfer (source transfering in this moment)
- prio (priority of downloading where 0 => "Low", 1 => "Normal", 2 => "High", 3 => "Very high", 4 => "Very low", 5=> "Auto", 6 => "Powershare")
- prio_auto (boolean, 0 = false, 1 = true)
- last_seen_complete show last seen date / time, timestamp format
uploads: return an array of Object(AmuleUploadFile). The fields of this are:
- name (full file name with extension)
- short_name (the full name trucated after some chars and ended with three periods)
- xfer_up (total of uploaded bytes of this file to this client)
- xfer_down (total of downloaded bytes of this file from this client)
- xfer_speed (actual upload speed of this file to this client, in bytes/sec)
shared: returns an array of Object(AmuleSharedFile). The fields of this are:
- name
- short_name:
- hash:
- size
- link
- xfer
- xfer_all
- req
- req_all
- accept:
- accept_all:
- prio
- prio_auto:
searchresult: returns an array of Object(AmuleSearchResult). The fields of this are:
- name
- short_name
- hash
- size
- sources
- present
servers:
stats_graph: returns stats graphs images (?)
stats_tree: returns stats tree (?)
amule_get_version
amule_get_version(): Returns version number string.
Authentication
Real PHP have wide range of authentication and session management possibilities. In aMuleWeb PHP, status is different. Both authentication and session management are not part of scripting language. Instead, they are implemented as part of in webserver itself, and running invisibly for script engine.
Errors and debugging
As in any other language, aMuleWeb PHP have 3 types of errors: compile-time, run-time and logic errors. All error messages produced by engine are printed to terminal. This effectively means, that aMuleWeb should be started manually from terminal (and not automatically by aMule) in order to see those messages. Alghouth engine perform some effort to recover from syntax errors, it's known to crash in some corner-cases. Beware.
- Compile-time errors means error in script syntax as misspelled names, missing ";" or mismatched (). In this case, error message from parser is printed and execution is not performed.
- Run-time errors like division by zero, incorrect or missing parameters etc. When encountered, appropriate message is printed, and execution aborted in point of problem.
- Logic errors: everything is OK, but result is different from expected. Since aMuleWeb PHP offers no debugger, the only way to trace program is to add var_dump() in suspicious places;
It is possible to compile aMuleWeb PHP engine standalone. This compilation mode is used to debug engine itself. Since aMule binding is not possible in this case, it have little use for template debugging.